A free open source IT asset/license management system
fix test to check all mailable types for reminders
Godfrey M9ac2ea2a5242
diff --git a/app/Http/Controllers/ReportsController.php b/app/Http/Controllers/ReportsController.phpindex 6d79f80893..d06e779a40 100644--- a/app/Http/Controllers/ReportsController.php+++ b/app/Http/Controllers/ReportsController.php@@ -1189,10 +1189,10 @@ class ReportsController extends Controllerreturn redirect()->route('reports/unaccepted_assets')->with('error', trans('general.bad_data'));} else {if($item instanceof LicenseSeat){- $logItem_res = $item->license->checkouts()->where('created_at', '=', $acceptance->created_at)->get();+ $logItem_res = $item->license->checkouts()->with('adminuser')->where('created_at', '=', $acceptance->created_at)->get();}else{- $logItem_res = $item->checkouts()->where('created_at', '=', $acceptance->created_at)->get();+ $logItem_res = $item->checkouts()->with('adminuser')->where('created_at', '=', $acceptance->created_at)->get();}if ($logItem_res->isEmpty()){Log::debug('Acceptance date mismatch');diff --git a/tests/Feature/Notifications/Email/AssetAcceptanceReminderTest.php b/tests/Feature/Notifications/Email/AssetAcceptanceReminderTest.phpindex deb3e07d2c..246d52366c 100644--- a/tests/Feature/Notifications/Email/AssetAcceptanceReminderTest.php+++ b/tests/Feature/Notifications/Email/AssetAcceptanceReminderTest.php@@ -2,8 +2,19 @@namespace Tests\Feature\Notifications\Email;+use App\Mail\CheckoutAccessoryMail;use App\Mail\CheckoutAssetMail;+use App\Mail\CheckoutComponentMail;+use App\Mail\CheckoutConsumableMail;+use App\Mail\CheckoutLicenseMail;+use App\Models\Accessory;+use App\Models\Actionlog;+use App\Models\Asset;use App\Models\CheckoutAcceptance;+use App\Models\Component;+use App\Models\Consumable;+use App\Models\License;+use App\Models\LicenseSeat;use App\Models\User;use Illuminate\Support\Facades\Mail;use PHPUnit\Framework\Attributes\DataProvider;@@ -86,16 +97,52 @@ class AssetAcceptanceReminderTest extends TestCasepublic function testReminderIsSentToUser(){- $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,+ ];- $this->actingAs(User::factory()->canViewReports()->create())- ->post($this->routeFor($checkoutAcceptance))+ $assignee = User::factory()->create(['email' => '[email protected]']);+ foreach ($checkoutTypes as $modelClass => $mailable) {++ $item = $modelClass::factory()->create();+ $acceptance = CheckoutAcceptance::factory()->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;+ }++ Actionlog::factory()->create([+ 'action_type' => 'checkout',+ 'created_by' => $checkedOutBy->id,+ 'target_id' => $assignee->id,+ 'item_type' => $logType,+ 'item_id' => $logId,+ 'created_at' => $acceptance->created_at,+ ]);++ $this->actingAs($checkedOutBy)+ ->post($this->routeFor($acceptance))->assertRedirect(route('reports/unaccepted_assets'));+ }- Mail::assertSent(CheckoutAssetMail::class, 1);- Mail::assertSent(CheckoutAssetMail::class, function (CheckoutAssetMail $mail) use ($checkoutAcceptance) {- return $mail->hasTo($checkoutAcceptance->assignedTo->email)- && $mail->hasSubject(trans('mail.unaccepted_asset_reminder'));+ Mail::assertSent($mailable, 1);+ Mail::assertSent($mailable, function ($mail) use ($assignee) {+ return $mail->hasTo($assignee->email);});}