mirror of
https://github.com/snipe/snipe-it.git
synced 2025-01-12 22:37:28 -08:00
Add some assertions
This commit is contained in:
parent
0506f3bef9
commit
31a75bd252
|
@ -295,6 +295,7 @@ class AssetFactory extends Factory
|
||||||
return [
|
return [
|
||||||
'assigned_to' => $user->id ?? User::factory(),
|
'assigned_to' => $user->id ?? User::factory(),
|
||||||
'assigned_type' => User::class,
|
'assigned_type' => User::class,
|
||||||
|
'last_checkout' => now()->subDay(),
|
||||||
];
|
];
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ namespace Tests\Feature\Checkins;
|
||||||
|
|
||||||
use App\Events\CheckoutableCheckedIn;
|
use App\Events\CheckoutableCheckedIn;
|
||||||
use App\Models\Asset;
|
use App\Models\Asset;
|
||||||
|
use App\Models\Statuslabel;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use App\Notifications\CheckinAssetNotification;
|
use App\Notifications\CheckinAssetNotification;
|
||||||
use Illuminate\Support\Facades\Event;
|
use Illuminate\Support\Facades\Event;
|
||||||
|
@ -34,6 +35,43 @@ class AssetCheckinTest extends TestCase
|
||||||
$this->markTestIncomplete();
|
$this->markTestIncomplete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testAssetCheckedOutToUserCanBeCheckedIn()
|
||||||
|
{
|
||||||
|
Event::fake([CheckoutableCheckedIn::class]);
|
||||||
|
|
||||||
|
$admin = User::factory()->checkinAssets()->create();
|
||||||
|
$user = User::factory()->create();
|
||||||
|
$status = Statuslabel::first() ?? Statuslabel::factory()->create();
|
||||||
|
$asset = Asset::factory()->assignedToUser($user)->create([
|
||||||
|
'expected_checkin' => now()->addDay(),
|
||||||
|
'last_checkin' => null,
|
||||||
|
'accepted' => 'accepted',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertTrue($asset->assignedTo->is($user));
|
||||||
|
|
||||||
|
$this->actingAs($admin)
|
||||||
|
->post(
|
||||||
|
route('hardware.checkin.store', ['assetId' => $asset->id, 'backto' => 'user']),
|
||||||
|
[
|
||||||
|
'name' => 'Changed Name',
|
||||||
|
'status_id' => $status->id,
|
||||||
|
],
|
||||||
|
)
|
||||||
|
->assertRedirect(route('users.show', $user));
|
||||||
|
|
||||||
|
Event::assertDispatched(CheckoutableCheckedIn::class, 1);
|
||||||
|
$this->assertNull($asset->refresh()->assignedTo);
|
||||||
|
$this->assertNull($asset->expected_checkin);
|
||||||
|
$this->assertNull($asset->last_checkout);
|
||||||
|
$this->assertNotNull($asset->last_checkin);
|
||||||
|
$this->assertNull($asset->assignedTo);
|
||||||
|
$this->assertNull($asset->assigned_type);
|
||||||
|
$this->assertNull($asset->accepted);
|
||||||
|
$this->assertEquals('Changed Name', $asset->name);
|
||||||
|
$this->assertEquals($status->id, $asset->status_id);
|
||||||
|
}
|
||||||
|
|
||||||
public function testAssetCheckedOutToAssetCanBeCheckedIn()
|
public function testAssetCheckedOutToAssetCanBeCheckedIn()
|
||||||
{
|
{
|
||||||
$this->markTestIncomplete();
|
$this->markTestIncomplete();
|
||||||
|
@ -44,24 +82,6 @@ class AssetCheckinTest extends TestCase
|
||||||
$this->markTestIncomplete();
|
$this->markTestIncomplete();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testAssetCheckedOutToUserCanBeCheckedIn()
|
|
||||||
{
|
|
||||||
Event::fake([CheckoutableCheckedIn::class]);
|
|
||||||
|
|
||||||
$admin = User::factory()->checkinAssets()->create();
|
|
||||||
$user = User::factory()->create();
|
|
||||||
$asset = Asset::factory()->assignedToUser($user)->create();
|
|
||||||
|
|
||||||
$this->assertTrue($asset->assignedTo->is($user));
|
|
||||||
|
|
||||||
$this->actingAs($admin)
|
|
||||||
->post(route('hardware.checkin.store', ['assetId' => $asset->id, 'backto' => 'user']))
|
|
||||||
->assertRedirect(route('users.show', $user));
|
|
||||||
|
|
||||||
$this->assertNull($asset->fresh()->assignedTo);
|
|
||||||
Event::assertDispatched(CheckoutableCheckedIn::class, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testLastCheckInFieldIsSetOnCheckin()
|
public function testLastCheckInFieldIsSetOnCheckin()
|
||||||
{
|
{
|
||||||
$admin = User::factory()->superuser()->create();
|
$admin = User::factory()->superuser()->create();
|
||||||
|
|
Loading…
Reference in a new issue