A free open source IT asset/license management system
adds an option to disable Auto assigned an actionlogs in factories
Godfrey M6f990dd1de5d
diff --git a/database/factories/CheckoutAcceptanceFactory.php b/database/factories/CheckoutAcceptanceFactory.phpindex bb56ab2b4a..5e0016763d 100644--- a/database/factories/CheckoutAcceptanceFactory.php+++ b/database/factories/CheckoutAcceptanceFactory.php@@ -23,23 +23,39 @@ class CheckoutAcceptanceFactory extends Factory'assigned_to_id' => User::factory(),];}+ protected static bool $skipAutoAssign = false;++ public function withoutAutoAssign(): static+ {+ // turn off for this create() call+ static::$skipAutoAssign = true;++ // ensure it turns back on AFTER creating+ return $this->afterCreating(function () {+ static::$skipAutoAssign = false;+ });+ }public function configure(): static{return $this->afterCreating(function (CheckoutAcceptance $acceptance) {+ if (static::$skipAutoAssign) {+ return; // short-circuit+ }if ($acceptance->checkoutable instanceof Asset) {$this->createdAssociatedActionLogEntry($acceptance);}if ($acceptance->checkoutable instanceof Asset && $acceptance->assignedTo instanceof User) {$acceptance->checkoutable->update([- 'assigned_to' => $acceptance->assigned_to_id,- 'assigned_type' => get_class($acceptance->assignedTo),+ 'assigned_to' => $acceptance->assigned_to_id,+ 'assigned_type'=> get_class($acceptance->assignedTo),]);}});}+public function forAccessory(){return $this->state([diff --git a/tests/Feature/Notifications/Email/AssetAcceptanceReminderTest.php b/tests/Feature/Notifications/Email/AssetAcceptanceReminderTest.phpindex deb3e07d2c..11afdaba4b 100644--- a/tests/Feature/Notifications/Email/AssetAcceptanceReminderTest.php+++ b/tests/Feature/Notifications/Email/AssetAcceptanceReminderTest.php@@ -86,7 +86,38 @@ class AssetAcceptanceReminderTest extends TestCasepublic function testReminderIsSentToUser(){+<<<<<<< Updated upstream$checkoutAcceptance = CheckoutAcceptance::factory()->pending()->create();+=======+ $checkedOutBy = User::factory()->canViewReports()->create();++ $checkoutTypes = [+ Asset::class => CheckoutAssetMail::class,+ Accessory::class => CheckoutAccessoryMail::class,+ LicenseSeat::class => CheckoutLicenseMail::class,+ Consumable::class => CheckoutConsumableMail::class,+ //for the future its setup for components, but we dont send reminders for components at the moment.+// Component::class => CheckoutComponentMail::class,+ ];++ $assignee = User::factory()->create(['email' => '[email protected]']);+ foreach ($checkoutTypes as $modelClass => $mailable) {++ $item = $modelClass::factory()->create();+ $acceptance = CheckoutAcceptance::factory()->withoutAutoAssign()->pending()->create([+ 'checkoutable_id' => $item->id,+ 'checkoutable_type' => $modelClass,+ 'assigned_to_id' => $assignee->id,+ ]);++ if ($modelClass === LicenseSeat::class) {+ $logType = License::class;+ $logId = $item->license->id;+ } else {+ $logType = $modelClass;+ $logId = $item->id;+ }+>>>>>>> Stashed changes$this->actingAs(User::factory()->canViewReports()->create())->post($this->routeFor($checkoutAcceptance))