Skip to content

A free open source IT asset/license management system

Updated tests

snipe8892a11e7e76
diff --git a/tests/Feature/Assets/Api/AssetFilesTest.php b/tests/Feature/Assets/Api/AssetFilesTest.php
index bc5b6043e4..3e3e576c25 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();
+
}
}