attempt to fix tests

This commit is contained in:
Godfrey M 2024-10-17 13:11:39 -07:00
parent 123cdeb858
commit dceb8e305f
4 changed files with 22 additions and 19 deletions

View file

@ -3,10 +3,12 @@
namespace Tests\Feature\Checkins\Ui;
use App\Events\CheckoutableCheckedIn;
use App\Mail\CheckoutAccessoryMail;
use App\Models\Accessory;
use App\Models\User;
use App\Notifications\CheckinAccessoryNotification;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Facades\Notification;
use Tests\TestCase;
@ -40,7 +42,7 @@ class AccessoryCheckinTest extends TestCase
public function testEmailSentToUserIfSettingEnabled()
{
Notification::fake();
Mail::fake();
$user = User::factory()->create();
$accessory = Accessory::factory()->checkedOutToUser($user)->create();
@ -54,17 +56,14 @@ class AccessoryCheckinTest extends TestCase
'',
));
Notification::assertSentTo(
[$user],
function (CheckinAccessoryNotification $notification, $channels) {
return in_array('mail', $channels);
},
);
Mail::assertSent(CheckoutAccessoryMail::class, function ($mail) use ($accessory, $user) {
return $mail->hasTo($user) && $mail->contains($accessory);
});
}
public function testEmailNotSentToUserIfSettingDisabled()
{
Notification::fake();
Mail::fake();
$user = User::factory()->create();
$accessory = Accessory::factory()->checkedOutToUser($user)->create();
@ -78,11 +77,8 @@ class AccessoryCheckinTest extends TestCase
'',
));
Notification::assertNotSentTo(
[$user],
function (CheckinAccessoryNotification $notification, $channels) {
return in_array('mail', $channels);
},
);
Mail::assertSent(CheckoutAccessoryMail::class, function ($mail) use ($accessory, $user) {
return $mail->hasTo($user) && $mail->contains($accessory);
});
}
}

View file

@ -2,12 +2,14 @@
namespace Tests\Feature\Checkouts\Ui;
use App\Mail\CheckoutAccessoryMail;
use App\Models\Accessory;
use App\Models\Actionlog;
use App\Models\Asset;
use App\Models\Location;
use App\Models\User;
use App\Notifications\CheckoutAccessoryNotification;
use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Facades\Notification;
use Tests\TestCase;
@ -156,7 +158,7 @@ class AccessoryCheckoutTest extends TestCase
public function testUserSentNotificationUponCheckout()
{
Notification::fake();
Mail::fake();
$accessory = Accessory::factory()->requiringAcceptance()->create();
$user = User::factory()->create();
@ -168,7 +170,9 @@ class AccessoryCheckoutTest extends TestCase
'checkout_to_type' => 'user',
]);
Notification::assertSentTo($user, CheckoutAccessoryNotification::class);
Mail::assertSent(CheckoutAccessoryMail::class, function ($mail) use ($accessory, $user) {
return $mail->hasTo($user) && $mail->contains($accessory);
});
}
public function testActionLogCreatedUponCheckout()

View file

@ -2,6 +2,7 @@
namespace Tests\Feature\Checkouts\Ui;
use App\Mail\CheckoutConsumableMail;
use App\Models\Actionlog;
use App\Models\Asset;
use App\Models\Component;
@ -64,7 +65,7 @@ class ConsumableCheckoutTest extends TestCase
'assigned_to' => $user->id,
]);
Mail::assertSent(CheckoutConsumableNotification::class, function ($mail) use ($consumable, $user) {
Mail::assertSent(CheckoutConsumableMail::class, function ($mail) use ($consumable, $user) {
return $mail->hasTo($user) && $mail->consumables->contains($consumable);
});
}

View file

@ -2,6 +2,7 @@
namespace Tests\Feature\Importing\Api;
use App\Mail\CheckoutAssetMail;
use App\Models\Actionlog as ActionLog;
use App\Models\Asset;
use App\Models\CustomField;
@ -11,6 +12,7 @@ use App\Notifications\CheckoutAssetNotification;
use Carbon\Carbon;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Facades\Notification;
use Illuminate\Support\Str;
use Illuminate\Testing\TestResponse;
@ -54,7 +56,7 @@ class ImportAssetsTest extends ImportDataTestCase implements TestsPermissionsReq
#[Test]
public function importAsset(): void
{
Notification::fake();
Mail::fake();
$importFileBuilder = ImportFileBuilder::new();
$row = $importFileBuilder->firstRow();
@ -138,7 +140,7 @@ class ImportAssetsTest extends ImportDataTestCase implements TestsPermissionsReq
//Notes is never read.
// $this->assertEquals($row['notes'], $newAsset->notes);
Notification::assertSentTo($assignee, CheckoutAssetNotification::class);
Mail::assertSent($assignee, CheckoutAssetMail::class);
}
#[Test]