mirror of
https://github.com/snipe/snipe-it.git
synced 2024-11-09 23:24:06 -08:00
Improve event assertions
This commit is contained in:
parent
1fe22e4b7b
commit
f16c79bb9a
|
@ -852,12 +852,9 @@ class AssetsController extends Controller
|
|||
}
|
||||
|
||||
$checkout_at = request('checkout_at', date('Y-m-d H:i:s'));
|
||||
// @todo: test this
|
||||
$expected_checkin = request('expected_checkin', null);
|
||||
// @todo: test this
|
||||
$note = request('note', null);
|
||||
// Using `->has` preserves the asset name if the name parameter was not included in request.
|
||||
// @todo: test this
|
||||
$asset_name = request()->has('name') ? request('name') : $asset->name;
|
||||
|
||||
// Set the location ID to the RTD location id if there is one
|
||||
|
|
|
@ -160,20 +160,21 @@ class AssetCheckoutTest extends TestCase
|
|||
$this->actingAsForApi($admin)
|
||||
->postJson(route('api.asset.checkout', $asset), [
|
||||
'checkout_to_type' => $type,
|
||||
'assigned_' . $type => $target->id,
|
||||
'assigned_'.$type => $target->id,
|
||||
'status_id' => $newStatus->id,
|
||||
'checkout_at' => '2024-04-01',
|
||||
'expected_checkin' => '2024-04-08',
|
||||
'name' => 'Changed Name',
|
||||
'note' => 'Here is a cool note!',
|
||||
]);
|
||||
])
|
||||
->assertOk();
|
||||
|
||||
$asset->refresh();
|
||||
$this->assertTrue($asset->assignedTo()->is($target));
|
||||
$this->assertEquals('Changed Name', $asset->name);
|
||||
$this->assertTrue($asset->assetstatus->is($newStatus));
|
||||
$this->assertEquals('2024-04-01 00:00:00', $asset->last_checkout);
|
||||
$this->assertEquals('2024-04-08 00:00:00', (string)$asset->expected_checkin);
|
||||
$this->assertEquals('2024-04-08 00:00:00', (string) $asset->expected_checkin);
|
||||
|
||||
$expectedLocation
|
||||
? $this->assertTrue($asset->location->is($expectedLocation))
|
||||
|
@ -181,10 +182,12 @@ class AssetCheckoutTest extends TestCase
|
|||
|
||||
Event::assertDispatched(CheckoutableCheckedOut::class, 1);
|
||||
Event::assertDispatched(function (CheckoutableCheckedOut $event) use ($admin, $asset, $target) {
|
||||
return $event->checkoutable->is($asset)
|
||||
&& $event->checkedOutTo->is($target)
|
||||
&& $event->checkedOutBy->is($admin)
|
||||
&& $event->note === 'Here is a cool note!';
|
||||
$this->assertTrue($event->checkoutable->is($asset));
|
||||
$this->assertTrue($event->checkedOutTo->is($target));
|
||||
$this->assertTrue($event->checkedOutBy->is($admin));
|
||||
$this->assertEquals('Here is a cool note!', $event->note);
|
||||
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue