Store alert_on_response_id on CheckoutAcceptance
This commit is contained in:
@@ -227,6 +227,7 @@ class CheckoutableListener
|
||||
if ($checkedOutToType != "App\Models\User") {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!$event->checkoutable->requireAcceptance()) {
|
||||
return null;
|
||||
}
|
||||
@@ -234,6 +235,11 @@ class CheckoutableListener
|
||||
$acceptance = new CheckoutAcceptance;
|
||||
$acceptance->checkoutable()->associate($event->checkoutable);
|
||||
$acceptance->assignedTo()->associate($event->checkedOutTo);
|
||||
|
||||
if (data_get($event, 'checkoutable.model.category.alert_on_response')) {
|
||||
$acceptance->alert_on_response_id = auth()->id();
|
||||
}
|
||||
|
||||
$acceptance->save();
|
||||
|
||||
return $acceptance;
|
||||
|
||||
@@ -70,6 +70,7 @@ class Category extends SnipeModel
|
||||
'eula_text',
|
||||
'name',
|
||||
'require_acceptance',
|
||||
'alert_on_response',
|
||||
'use_default_eula',
|
||||
'created_by',
|
||||
'notes',
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Checkouts\General;
|
||||
|
||||
use App\Models\Asset;
|
||||
use App\Models\Statuslabel;
|
||||
use App\Models\User;
|
||||
use Tests\TestCase;
|
||||
|
||||
class SettingAlertOnResponseTest extends TestCase
|
||||
{
|
||||
public function testSetsAlertOnResponseCorrectly()
|
||||
{
|
||||
$asset = Asset::factory()->create();
|
||||
$asset->model->category->update([
|
||||
'require_acceptance' => true,
|
||||
'alert_on_response' => true,
|
||||
]);
|
||||
|
||||
$actor = User::factory()->checkoutAssets()->create();
|
||||
$assignedUser = User::factory()->create();
|
||||
|
||||
$this->actingAs($actor)
|
||||
->post(route('hardware.checkout.store', $asset), [
|
||||
'checkout_to_type' => 'user',
|
||||
'status_id' => (string) Statuslabel::factory()->readyToDeploy()->create()->id,
|
||||
'assigned_user' => $assignedUser->id,
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('checkout_acceptances', [
|
||||
'checkoutable_type' => Asset::class,
|
||||
'checkoutable_id' => $asset->id,
|
||||
'assigned_to_id' => $assignedUser->id,
|
||||
'alert_on_response_id' => $actor->id,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user