-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' of https://github.com/hngprojects/hng_boilerplate_…
…php_laravel_web into fix/google-auth-reamend
- Loading branch information
Showing
11 changed files
with
528 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
namespace App\Http\Requests; | ||
|
||
use Illuminate\Foundation\Http\FormRequest; | ||
|
||
class DeleteSqueezeRequest extends FormRequest | ||
{ | ||
/** | ||
* Determine if the user is authorized to make this request. | ||
*/ | ||
public function authorize(): bool | ||
{ | ||
return true; | ||
} | ||
|
||
/** | ||
* Get the validation rules that apply to the request. | ||
* | ||
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string> | ||
*/ | ||
public function rules(): array | ||
{ | ||
return [ | ||
'squeeze_page' => 'required|string|exists:squeeze_pages,id' | ||
]; | ||
} | ||
|
||
protected function prepareForValidation() | ||
{ | ||
$this->merge([ | ||
'squeeze_page' => $this->route('squeeze_page'), | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<?php | ||
|
||
namespace Tests\Feature; | ||
|
||
use Illuminate\Foundation\Testing\RefreshDatabase; | ||
use Tests\TestCase; | ||
use App\Models\User; | ||
use App\Models\SqueezePage; | ||
use Tymon\JWTAuth\Facades\JWTAuth; | ||
|
||
class DeleteSqueezeTest extends TestCase | ||
{ | ||
use RefreshDatabase; | ||
|
||
private function getAuthenticatedUser(string $role) | ||
{ | ||
$user = User::factory()->create([ | ||
'role' => $role, | ||
'is_active' => true, | ||
]); | ||
|
||
$token = JWTAuth::fromUser($user); | ||
|
||
return [$user, $token]; | ||
} | ||
|
||
/** @test */ | ||
public function admin_can_delete_a_squeeze_page() | ||
{ | ||
[$admin, $token] = $this->getAuthenticatedUser('admin'); | ||
|
||
$squeezePage = SqueezePage::create([ | ||
'title' => 'Digital Marketing', | ||
'slug' => 'digital-marketing', | ||
'status' => 'online', | ||
'activate' => true, | ||
'headline' => 'Master Digital Marketing', | ||
'sub_headline' => 'Unlock the Secrets of Online Success', | ||
'hero_image' => 'digital_marketing.jpg', | ||
'content' => 'Learn the best strategies to excel in digital marketing...', | ||
]); | ||
|
||
$response = $this->withHeaders([ | ||
'Authorization' => 'Bearer ' . $token, | ||
'Accept' => 'application/json', | ||
])->deleteJson(route('squeeze-pages.destroy', ['squeeze_page' => $squeezePage->id])); | ||
|
||
$response->assertStatus(200) | ||
->assertJson([ | ||
'message' => 'Squeeze Page deleted successfully', | ||
'status' => 200, | ||
]); | ||
|
||
$this->assertDatabaseMissing('squeeze_pages', [ | ||
'id' => $squeezePage->id, | ||
]); | ||
} | ||
|
||
/** @test */ | ||
public function non_admin_cannot_delete_a_squeeze_page() | ||
{ | ||
[$user, $token] = $this->getAuthenticatedUser('user'); | ||
|
||
$squeezePage = SqueezePage::create([ | ||
'title' => 'Digital Marketing', | ||
'slug' => 'digital-marketing', | ||
'status' => 'online', | ||
'activate' => true, | ||
'headline' => 'Master Digital Marketing', | ||
'sub_headline' => 'Unlock the Secrets of Online Success', | ||
'hero_image' => 'digital_marketing.jpg', | ||
'content' => 'Learn the best strategies to excel in digital marketing...', | ||
]); | ||
|
||
$response = $this->withHeaders([ | ||
'Authorization' => 'Bearer ' . $token, | ||
'Accept' => 'application/json', | ||
])->deleteJson(route('squeeze-pages.destroy', ['squeeze_page' => $squeezePage->id])); | ||
|
||
$response->assertStatus(401) | ||
->assertJson([ | ||
'status_code' => 401, | ||
'message' => 'Unauthorized, admin access only', | ||
]); | ||
|
||
$this->assertDatabaseHas('squeeze_pages', [ | ||
'id' => $squeezePage->id, | ||
]); | ||
} | ||
} |
Oops, something went wrong.