Added tests

Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
snipe 2024-09-11 16:43:41 +01:00
parent 98323185de
commit 04e96b8f20

View file

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