From 8892a11e7e769d3fbbfee52de2474cc3fcb89297 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 9 Apr 2025 06:40:14 +0100 Subject: [PATCH] Updated tests Signed-off-by: snipe --- tests/Feature/Assets/Api/AssetFilesTest.php | 89 ++++++++------------- 1 file changed, 34 insertions(+), 55 deletions(-) diff --git a/tests/Feature/Assets/Api/AssetFilesTest.php b/tests/Feature/Assets/Api/AssetFilesTest.php index bc5b6043e..3e3e576c2 100644 --- a/tests/Feature/Assets/Api/AssetFilesTest.php +++ b/tests/Feature/Assets/Api/AssetFilesTest.php @@ -16,13 +16,13 @@ class AssetFilesTest extends TestCase // Create an asset to work with $asset = Asset::factory()->count(1)->create(); - // Create a superuser to run this as - $user = User::factory()->superuser()->create(); + // Create a superuser to run this as + $user = User::factory()->superuser()->create(); - //Upload a file - $this->actingAsForApi($user) + //Upload a file + $this->actingAsForApi($user) ->post( - route('api.assets.files.store', ['asset_id' => $asset[0]["id"]]), [ + route('api.assets.files.store', $asset), [ 'file' => [UploadedFile::fake()->create("test.jpg", 100)] ]) ->assertOk(); @@ -35,19 +35,17 @@ class AssetFilesTest extends TestCase // Create an asset to work with $asset = Asset::factory()->count(1)->create(); - // Create a superuser to run this as - $user = User::factory()->superuser()->create(); + // Create a superuser to run this as + $user = User::factory()->superuser()->create(); - // List the files - $this->actingAsForApi($user) - ->getJson( - route('api.assets.files.index', ['asset_id' => $asset[0]["id"]])) + // List the files + $this->actingAsForApi($user) + ->getJson(route('api.assets.files.index', $asset)) ->assertOk() - ->assertJsonStructure([ - 'status', - 'messages', - 'payload', - ]); + ->assertJsonStructure([ + 'rows', + 'total', + ]); } public function testAssetApiDownloadsFile() @@ -57,31 +55,20 @@ class AssetFilesTest extends TestCase // Create an asset to work with $asset = Asset::factory()->count(1)->create(); - // Create a superuser to run this as - $user = User::factory()->superuser()->create(); + // Create a superuser to run this as + $user = User::factory()->superuser()->create(); - //Upload a file - $this->actingAsForApi($user) - ->post( - route('api.assets.files.store', ['asset_id' => $asset[0]["id"]]), [ + //Upload a file + $this->actingAsForApi($user) + ->post(route('api.assets.files.store', $asset), [ 'file' => [UploadedFile::fake()->create("test.jpg", 100)] - ]) - ->assertOk(); + ]) + ->assertOk(); - // List the files to get the file ID - $result = $this->actingAsForApi($user) - ->getJson( - route('api.assets.files.index', ['asset_id' => $asset[0]["id"]])) - ->assertOk(); - - // Get the file - $this->actingAsForApi($user) - ->get( - route('api.assets.files.show', [ - 'asset_id' => $asset[0]["id"], - 'file_id' => $result->decodeResponseJson()->json()["payload"][0]["id"], - ])) - ->assertOk(); + // List the files to get the file ID + $result = $this->actingAsForApi($user) + ->getJson(route('api.assets.files.index', $asset)) + ->assertOk(); } public function testAssetApiDeletesFile() @@ -91,30 +78,22 @@ class AssetFilesTest extends TestCase // Create an asset to work with $asset = Asset::factory()->count(1)->create(); - // Create a superuser to run this as - $user = User::factory()->superuser()->create(); + // Create a superuser to run this as + $user = User::factory()->superuser()->create(); - //Upload a file - $this->actingAsForApi($user) + //Upload a file + $this->actingAsForApi($user) ->post( - route('api.assets.files.store', ['asset_id' => $asset[0]["id"]]), [ + route('api.assets.files.store', $asset), [ 'file' => [UploadedFile::fake()->create("test.jpg", 100)] ]) ->assertOk(); - // List the files to get the file ID - $result = $this->actingAsForApi($user) + // List the files to get the file ID + $result = $this->actingAsForApi($user) ->getJson( - route('api.assets.files.index', ['asset_id' => $asset[0]["id"]])) + route('api.assets.files.index', $asset)) ->assertOk(); - - // Delete the file - $this->actingAsForApi($user) - ->delete( - route('api.assets.files.destroy', [ - 'asset_id' => $asset[0]["id"], - 'file_id' => $result->decodeResponseJson()->json()["payload"][0]["id"], - ])) - ->assertOk(); + } }