A free open source IT asset/license management system
Updated/added tests
snipe9a2c5ff19577
diff --git a/tests/Feature/AssetMaintenances/Api/CreateAssetMaintenanceTest.php b/tests/Feature/AssetMaintenances/Api/CreateAssetMaintenanceTest.phpnew file mode 100644index 0000000000..039ba8656c--- /dev/null+++ b/tests/Feature/AssetMaintenances/Api/CreateAssetMaintenanceTest.php@@ -0,0 +1,73 @@+<?php++namespace Tests\Feature\AssetMaintenances\Api;++use App\Models\Asset;+use App\Models\AssetMaintenance;+use App\Models\Category;+use App\Models\Supplier;+use App\Models\User;+use Illuminate\Http\UploadedFile;+use Illuminate\Support\Facades\Storage;+use Illuminate\Testing\Fluent\AssertableJson;+use Tests\TestCase;++class CreateAssetMaintenanceTest extends TestCase+{+++ public function testRequiresPermissionToCreateAssetMaintenance()+ {+ $this->actingAsForApi(User::factory()->create())+ ->postJson(route('api.maintenances.store'))+ ->assertForbidden();+ }+ public function testCanCreateAssetMaintenance()+ {++ Storage::fake('public');+ $actor = User::factory()->superuser()->create();++ $asset = Asset::factory()->create();+ $supplier = Supplier::factory()->create();++ $response = $this->actingAsForApi($actor)+ ->postJson(route('api.maintenances.store'), [+ 'title' => 'Test Maintenance',+ 'asset_id' => $asset->id,+ 'supplier_id' => $supplier->id,+ 'asset_maintenance_type' => 'Maintenance',+ 'start_date' => '2021-01-01',+ 'completion_date' => '2021-01-10',+ 'is_warranty' => '1',+ 'cost' => '100.00',+ 'image' => UploadedFile::fake()->image('test_image.png'),+ 'notes' => 'A note',+ ])+ ->assertOk()+ ->assertStatus(200);++ \Log::error($response->json());+ // Since we rename the file in the ImageUploadRequest, we have to fetch the record from the database+ $assetMaintenance = AssetMaintenance::where('title', 'Test Maintenance')->first();++ // Assert file was stored...+ Storage::disk('public')->assertExists(app('asset_maintenances_path').$assetMaintenance->image);++ $this->assertDatabaseHas('asset_maintenances', [+ 'asset_id' => $asset->id,+ 'supplier_id' => $supplier->id,+ 'asset_maintenance_type' => 'Maintenance',+ 'title' => 'Test Maintenance',+ 'is_warranty' => 1,+ 'start_date' => '2021-01-01',+ 'completion_date' => '2021-01-10',+ 'notes' => 'A note',+ 'image' => $assetMaintenance->image,+ 'created_by' => $actor->id,+ ]);+ }++++}diff --git a/tests/Feature/AssetMaintenances/Api/EditAssetMaintenanceTest.php b/tests/Feature/AssetMaintenances/Api/EditAssetMaintenanceTest.phpnew file mode 100644index 0000000000..a6c1d25419--- /dev/null+++ b/tests/Feature/AssetMaintenances/Api/EditAssetMaintenanceTest.php@@ -0,0 +1,71 @@+<?php++namespace Tests\Feature\AssetMaintenances\Api;++use App\Models\Asset;+use App\Models\AssetMaintenance;+use App\Models\Supplier;+use App\Models\User;+use Illuminate\Http\UploadedFile;+use Illuminate\Support\Facades\Storage;+use Tests\TestCase;++class EditAssetMaintenanceTest extends TestCase+{+ public function testPageRenders()+ {+ $this->actingAs(User::factory()->superuser()->create())+ ->get(route('maintenances.update', AssetMaintenance::factory()->create()->id))+ ->assertOk();+ }+++ public function testCanCreateAssetMaintenance()+ {+ Storage::fake('public');+ $actor = User::factory()->superuser()->create();++ $asset = Asset::factory()->create();+ $supplier = Supplier::factory()->create();++ $maintenance = AssetMaintenance::factory()->create();++ $this->actingAs($actor)+ ->followingRedirects()+ ->post(route('maintenances.update', $maintenance), [+ 'title' => 'Test Maintenance',+ 'selected_assets' => [$asset->id],+ 'supplier_id' => $supplier->id,+ 'asset_maintenance_type' => 'Maintenance',+ 'start_date' => '2021-01-01',+ 'completion_date' => '2021-01-10',+ 'is_warranty' => '1',+ 'cost' => '100.00',+ 'image' => UploadedFile::fake()->image('test_image.png'),+ 'notes' => 'A note',+ ])+ ->assertOk();++ // Since we rename the file in the ImageUploadRequest, we have to fetch the record from the database+ $assetMaintenance = AssetMaintenance::where('title', 'Test Maintenance')->first();++ // Assert file was stored...+ Storage::disk('public')->assertExists(app('asset_maintenances_path').$assetMaintenance->image);+++ $this->assertDatabaseHas('asset_maintenances', [+ 'asset_id' => $asset->id,+ 'supplier_id' => $supplier->id,+ 'asset_maintenance_type' => 'Maintenance',+ 'title' => 'Test Maintenance',+ 'is_warranty' => 1,+ 'start_date' => '2021-01-01',+ 'completion_date' => '2021-01-10',+ 'asset_maintenance_time' => '9',+ 'notes' => 'A note',+ 'cost' => '100.00',+ 'image' => $assetMaintenance->image,+ 'created_by' => $actor->id,+ ]);+ }+}diff --git a/tests/Feature/AssetMaintenances/Ui/CreateAssetMaintenanceTest.php b/tests/Feature/AssetMaintenances/Ui/CreateAssetMaintenanceTest.phpindex 23227c7e6a..5ccf70eddb 100644--- a/tests/Feature/AssetMaintenances/Ui/CreateAssetMaintenanceTest.php+++ b/tests/Feature/AssetMaintenances/Ui/CreateAssetMaintenanceTest.php@@ -3,8 +3,11 @@namespace Tests\Feature\AssetMaintenances\Ui;use App\Models\Asset;+use App\Models\AssetMaintenance;use App\Models\Supplier;use App\Models\User;+use Illuminate\Http\UploadedFile;+use Illuminate\Support\Facades\Storage;use Tests\TestCase;class CreateAssetMaintenanceTest extends TestCase@@ -19,6 +22,7 @@ class CreateAssetMaintenanceTest extends TestCasepublic function testCanCreateAssetMaintenance(){+ Storage::fake('public');$actor = User::factory()->superuser()->create();$asset = Asset::factory()->create();@@ -35,10 +39,18 @@ class CreateAssetMaintenanceTest extends TestCase'completion_date' => '2021-01-10','is_warranty' => '1','cost' => '100.00',+ 'image' => UploadedFile::fake()->image('test_image.png'),'notes' => 'A note',])->assertOk();+ // Since we rename the file in the ImageUploadRequest, we have to fetch the record from the database+ $assetMaintenance = AssetMaintenance::where('title', 'Test Maintenance')->first();++ // Assert file was stored...+ Storage::disk('public')->assertExists(app('asset_maintenances_path').$assetMaintenance->image);++$this->assertDatabaseHas('asset_maintenances', ['asset_id' => $asset->id,'supplier_id' => $supplier->id,@@ -50,6 +62,7 @@ class CreateAssetMaintenanceTest extends TestCase'asset_maintenance_time' => '9','notes' => 'A note','cost' => '100.00',+ 'image' => $assetMaintenance->image,'created_by' => $actor->id,]);}diff --git a/tests/Feature/AssetMaintenances/Ui/EditAssetMaintenanceTest.php b/tests/Feature/AssetMaintenances/Ui/EditAssetMaintenanceTest.phpindex a622a5dec7..e898cc4990 100644--- a/tests/Feature/AssetMaintenances/Ui/EditAssetMaintenanceTest.php+++ b/tests/Feature/AssetMaintenances/Ui/EditAssetMaintenanceTest.php@@ -6,6 +6,8 @@ use App\Models\Asset;use App\Models\AssetMaintenance;use App\Models\Supplier;use App\Models\User;+use Illuminate\Http\UploadedFile;+use Illuminate\Support\Facades\Storage;use Tests\TestCase;class EditAssetMaintenanceTest extends TestCase@@ -34,11 +36,17 @@ class EditAssetMaintenanceTest extends TestCase'start_date' => '2021-01-01','completion_date' => '2021-01-10','is_warranty' => 1,+ 'image' => UploadedFile::fake()->image('test_image.png'),'cost' => '100.99','notes' => 'A note',])->assertOk();+ // Since we rename the file in the ImageUploadRequest, we have to fetch the record from the database+ $assetMaintenance = AssetMaintenance::where('title', 'Test Maintenance')->first();++ // Assert file was stored...+ Storage::disk('public')->assertExists(app('asset_maintenances_path').$assetMaintenance->image);$this->assertDatabaseHas('asset_maintenances', ['asset_id' => $asset->id,diff --git a/tests/Feature/Settings/BrandingSettingsTest.php b/tests/Feature/Settings/BrandingSettingsTest.phpindex d751a1ab47..494c401d9e 100644--- a/tests/Feature/Settings/BrandingSettingsTest.php+++ b/tests/Feature/Settings/BrandingSettingsTest.php@@ -51,6 +51,9 @@ class BrandingSettingsTest extends TestCase->assertRedirect(route('settings.index'))->assertSessionHasNoErrors();+ // Assert files was stored...+ Storage::disk('public')->assertExists('test_logo.jpg');+$this->followRedirects($response)->assertSee('alert-success');$setting->refresh();