adds an option to disable Auto assigned an actionlogs in factories
This commit is contained in:
@@ -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([
|
||||
|
||||
@@ -86,7 +86,38 @@ class AssetAcceptanceReminderTest extends TestCase
|
||||
|
||||
public 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' => 'test@example.com']);
|
||||
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))
|
||||
|
||||
Reference in New Issue
Block a user