Get the file upload test working
Added the upload functionality to the get and delete tests, but I currently don't seem to be able to reference the correct file ID
This commit is contained in:
parent
2d4af61e6c
commit
633bcbb6c4
1 changed files with 57 additions and 9 deletions
|
@ -5,6 +5,7 @@ namespace Tests\Feature\Api\Assets;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use App\Models\Asset;
|
use App\Models\Asset;
|
||||||
|
use Illuminate\Http\UploadedFile;
|
||||||
|
|
||||||
class AssetFilesTest extends TestCase
|
class AssetFilesTest extends TestCase
|
||||||
{
|
{
|
||||||
|
@ -14,13 +15,17 @@ class AssetFilesTest extends TestCase
|
||||||
|
|
||||||
// Create an asset to work with
|
// Create an asset to work with
|
||||||
$asset = Asset::factory()->count(1)->create();
|
$asset = Asset::factory()->count(1)->create();
|
||||||
//
|
|
||||||
//// Upload a file
|
// Create a superuser to run this as
|
||||||
//// Create a superuser to run this as
|
$user = User::factory()->superuser()->create();
|
||||||
//$this->actingAsForApi(User::factory()->superuser()->create())
|
|
||||||
// ->postJson(
|
//Upload a file
|
||||||
// route('api.asset.files', $asset), [
|
$this->actingAsForApi($user)
|
||||||
// 'file[]' =>
|
->post(
|
||||||
|
route('api.assets.files', ['asset_id' => $asset[0]["id"]]), [
|
||||||
|
'file' => [UploadedFile::fake()->create("test.jpg", 100)]
|
||||||
|
])
|
||||||
|
->assertOk();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testAssetApiListsFiles()
|
public function testAssetApiListsFiles()
|
||||||
|
@ -30,8 +35,6 @@ class AssetFilesTest extends TestCase
|
||||||
// Create an asset to work with
|
// Create an asset to work with
|
||||||
$asset = Asset::factory()->count(1)->create();
|
$asset = Asset::factory()->count(1)->create();
|
||||||
|
|
||||||
print($asset);
|
|
||||||
|
|
||||||
// Create a superuser to run this as
|
// Create a superuser to run this as
|
||||||
$user = User::factory()->superuser()->create();
|
$user = User::factory()->superuser()->create();
|
||||||
$this->actingAsForApi($user)
|
$this->actingAsForApi($user)
|
||||||
|
@ -48,10 +51,55 @@ class AssetFilesTest extends TestCase
|
||||||
public function testAssetApiDownloadsFile()
|
public function testAssetApiDownloadsFile()
|
||||||
{
|
{
|
||||||
// Download a file from an asset
|
// Download a file from an asset
|
||||||
|
|
||||||
|
// Create an asset to work with
|
||||||
|
$asset = Asset::factory()->count(1)->create();
|
||||||
|
|
||||||
|
// Create a superuser to run this as
|
||||||
|
$user = User::factory()->superuser()->create();
|
||||||
|
|
||||||
|
//Upload a file
|
||||||
|
$this->actingAsForApi($user)
|
||||||
|
->post(
|
||||||
|
route('api.assets.files', ['asset_id' => $asset[0]["id"]]), [
|
||||||
|
'file' => [UploadedFile::fake()->create("test.jpg", 100)]
|
||||||
|
])->assertOk();
|
||||||
|
|
||||||
|
// Get the file
|
||||||
|
$this->actingAsForApi($user)
|
||||||
|
->get(
|
||||||
|
route('api.assets.file', [
|
||||||
|
'asset_id' => $asset[0]["id"],
|
||||||
|
'file_id' => 1,
|
||||||
|
]))
|
||||||
|
->assertOk();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testAssetApiDeletesFile()
|
public function testAssetApiDeletesFile()
|
||||||
{
|
{
|
||||||
// Delete a file from an asset
|
// Delete a file from an asset
|
||||||
|
|
||||||
|
// Create an asset to work with
|
||||||
|
$asset = Asset::factory()->count(1)->create();
|
||||||
|
|
||||||
|
// Create a superuser to run this as
|
||||||
|
$user = User::factory()->superuser()->create();
|
||||||
|
|
||||||
|
//Upload a file
|
||||||
|
$this->actingAsForApi($user)
|
||||||
|
->post(
|
||||||
|
route('api.assets.files', ['asset_id' => $asset[0]["id"]]), [
|
||||||
|
'file' => [UploadedFile::fake()->create("test.jpg", 100)]
|
||||||
|
])
|
||||||
|
->assertOk();
|
||||||
|
|
||||||
|
// Delete the file
|
||||||
|
$this->actingAsForApi($user)
|
||||||
|
->delete(
|
||||||
|
route('api.assets.file', [
|
||||||
|
'asset_id' => $asset[0]["id"],
|
||||||
|
'file_id' => 1,
|
||||||
|
]))
|
||||||
|
->assertOk();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue