mirror of
https://github.com/snipe/snipe-it.git
synced 2024-09-19 23:37:38 -07:00
Implement test
This commit is contained in:
parent
7bfd02054b
commit
af513946a2
|
@ -2,8 +2,11 @@
|
|||
|
||||
namespace Tests\Feature\Api\Assets;
|
||||
|
||||
use App\Events\CheckoutableCheckedIn;
|
||||
use App\Models\Asset;
|
||||
use App\Models\Statuslabel;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Tests\Support\InteractsWithSettings;
|
||||
use Tests\TestCase;
|
||||
|
||||
|
@ -34,7 +37,35 @@ class AssetCheckinTest extends TestCase
|
|||
|
||||
public function testAssetCanBeCheckedIn()
|
||||
{
|
||||
$this->markTestIncomplete();
|
||||
Event::fake([CheckoutableCheckedIn::class]);
|
||||
|
||||
$user = User::factory()->create();
|
||||
$status = 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->actingAsForApi(User::factory()->checkinAssets()->create())
|
||||
->postJson(route('api.asset.checkin', $asset->id), [
|
||||
'name' => 'Changed Name',
|
||||
'status_id' => $status->id,
|
||||
])
|
||||
->assertOk();
|
||||
|
||||
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 testLastCheckInFieldIsSetOnCheckin()
|
||||
|
|
|
@ -40,7 +40,6 @@ class AssetCheckinTest extends TestCase
|
|||
{
|
||||
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([
|
||||
|
@ -51,7 +50,7 @@ class AssetCheckinTest extends TestCase
|
|||
|
||||
$this->assertTrue($asset->assignedTo->is($user));
|
||||
|
||||
$this->actingAs($admin)
|
||||
$this->actingAs(User::factory()->checkinAssets()->create())
|
||||
->post(
|
||||
route('hardware.checkin.store', ['assetId' => $asset->id, 'backto' => 'user']),
|
||||
[
|
||||
|
|
Loading…
Reference in a new issue