-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: media_format attribute and song resource pivot (#605)
- Loading branch information
Showing
14 changed files
with
1,289 additions
and
6 deletions.
There are no files selected for viewing
108 changes: 108 additions & 0 deletions
108
tests/Feature/Http/Api/Pivot/Wiki/SongResource/SongResourceDestroyTest.php
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,108 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Http\Api\Pivot\Wiki\SongResource; | ||
|
||
use App\Enums\Auth\CrudPermission; | ||
use App\Models\Auth\User; | ||
use App\Models\Wiki\Song; | ||
use App\Models\Wiki\ExternalResource; | ||
use App\Pivots\Wiki\SongResource; | ||
use Laravel\Sanctum\Sanctum; | ||
use Tests\TestCase; | ||
|
||
/** | ||
* Class SongResourceDestroyTest. | ||
*/ | ||
class SongResourceDestroyTest extends TestCase | ||
{ | ||
/** | ||
* The Song Resource Destroy Endpoint shall be protected by sanctum. | ||
* | ||
* @return void | ||
*/ | ||
public function testProtected(): void | ||
{ | ||
$songResource = SongResource::factory() | ||
->for(Song::factory()) | ||
->for(ExternalResource::factory(), SongResource::RELATION_RESOURCE) | ||
->createOne(); | ||
|
||
$response = $this->delete(route('api.songresource.destroy', ['song' => $songResource->song, 'resource' => $songResource->resource])); | ||
|
||
$response->assertUnauthorized(); | ||
} | ||
|
||
/** | ||
* The Song Resource Destroy Endpoint shall forbid users without the delete song & delete resource permissions. | ||
* | ||
* @return void | ||
*/ | ||
public function testForbidden(): void | ||
{ | ||
$songResource = SongResource::factory() | ||
->for(Song::factory()) | ||
->for(ExternalResource::factory(), SongResource::RELATION_RESOURCE) | ||
->createOne(); | ||
|
||
$user = User::factory()->createOne(); | ||
|
||
Sanctum::actingAs($user); | ||
|
||
$response = $this->delete(route('api.songresource.destroy', ['song' => $songResource->song, 'resource' => $songResource->resource])); | ||
|
||
$response->assertForbidden(); | ||
} | ||
|
||
/** | ||
* The Song Resource Destroy Endpoint shall return an error if the song resource does not exist. | ||
* | ||
* @return void | ||
*/ | ||
public function testNotFound(): void | ||
{ | ||
$song = Song::factory()->createOne(); | ||
$resource = ExternalResource::factory()->createOne(); | ||
|
||
$user = User::factory() | ||
->withPermissions( | ||
CrudPermission::DELETE->format(Song::class), | ||
CrudPermission::DELETE->format(ExternalResource::class) | ||
) | ||
->createOne(); | ||
|
||
Sanctum::actingAs($user); | ||
|
||
$response = $this->delete(route('api.songresource.destroy', ['song' => $song, 'resource' => $resource])); | ||
|
||
$response->assertNotFound(); | ||
} | ||
|
||
/** | ||
* The Song Resource Destroy Endpoint shall delete the song resource. | ||
* | ||
* @return void | ||
*/ | ||
public function testDeleted(): void | ||
{ | ||
$songResource = SongResource::factory() | ||
->for(Song::factory()) | ||
->for(ExternalResource::factory(), SongResource::RELATION_RESOURCE) | ||
->createOne(); | ||
|
||
$user = User::factory() | ||
->withPermissions( | ||
CrudPermission::DELETE->format(Song::class), | ||
CrudPermission::DELETE->format(ExternalResource::class) | ||
) | ||
->createOne(); | ||
|
||
Sanctum::actingAs($user); | ||
|
||
$response = $this->delete(route('api.songresource.destroy', ['song' => $songResource->song, 'resource' => $songResource->resource])); | ||
|
||
$response->assertOk(); | ||
static::assertModelMissing($songResource); | ||
} | ||
} |
Oops, something went wrong.