Updated tests

Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
snipe 2025-04-09 06:40:14 +01:00
parent f29146b319
commit 8892a11e7e

View file

@ -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();
}
}