Skip to content

A free open source IT asset/license management system

Added tests

snipe04e96b8f2009
diff --git a/tests/Feature/Assets/Ui/EditAssetTest.php b/tests/Feature/Assets/Ui/EditAssetTest.php
index befe64a864..c17366bed5 100644
--- a/tests/Feature/Assets/Ui/EditAssetTest.php
+++ b/tests/Feature/Assets/Ui/EditAssetTest.php
@@ -2,16 +2,20 @@
namespace Tests\Feature\Assets\Ui;
+use App\Events\CheckoutableCheckedIn;
use App\Models\Asset;
use App\Models\AssetModel;
+use App\Models\Location;
use App\Models\StatusLabel;
use App\Models\User;
+use Illuminate\Support\Carbon;
+use Illuminate\Support\Facades\Event;
use Tests\TestCase;
class EditAssetTest extends TestCase
{
- public function testPermissionRequiredToViewLicense()
+ public function testPermissionRequiredToViewAsset()
{
$asset = Asset::factory()->create();
$this->actingAs(User::factory()->create())
@@ -64,4 +68,41 @@ class EditAssetTest extends TestCase
$this->assertDatabaseHas('assets', ['asset_tag' => 'New Asset Tag']);
}
+ public function testNewCheckinIsLoggedIfStatusChangedToUndeployable()
+ {
+ Event::fake([CheckoutableCheckedIn::class]);
+
+ $user = User::factory()->create();
+ $location = Location::factory()->create();
+ $deployable_status = Statuslabel::factory()->rtd()->create();
+ $achived_status = Statuslabel::factory()->archived()->create();
+
+ $asset = Asset::factory()->assignedToUser($user)->create(['status_id' => $deployable_status->id]);
+
+ $this->assertTrue($asset->assignedTo->is($user));
+
+ $currentTimestamp = now();
+
+ $this->actingAs(User::factory()->viewAssets()->editAssets()->create())
+ ->post(
+ route('hardware.update', ['hardware' => $asset->id]),
+ [
+ 'status_id' => $achived_status->id,
+ ],
+ );
+
+ $asset->refresh();
+ \Log::error('AssignedTo: '.$asset->refresh()->assignedTo);
+ \Log::error('Assigned_to: '.$asset->refresh()->assigned_to);
+ \Log::error('Assigned_type: '.$asset->refresh()->assigned_type);
+ $this->assertNull($asset->refresh()->assignedTo);
+ $this->assertNull($asset->refresh()->assigned_type);
+ $this->assertEquals($achived_status->id, $asset->refresh()->status_id);
+
+ Event::assertDispatched(function (CheckoutableCheckedIn $event) use ($currentTimestamp) {
+ // this could be better mocked but is ok for now.
+ return Carbon::parse($event->action_date)->diffInSeconds($currentTimestamp) < 2;
+ }, 1);
+ }
+
}