attempt to fix tests p2

This commit is contained in:
Godfrey M 2024-10-17 13:34:55 -07:00
parent dceb8e305f
commit cdd4fef7df
8 changed files with 26 additions and 16 deletions

View file

@ -77,7 +77,7 @@ class AccessoryCheckinTest extends TestCase
'',
));
Mail::assertSent(CheckoutAccessoryMail::class, function ($mail) use ($accessory, $user) {
Mail::assertNotSent(CheckoutAccessoryMail::class, function ($mail) use ($accessory, $user) {
return $mail->hasTo($user) && $mail->contains($accessory);
});
}

View file

@ -2,10 +2,12 @@
namespace Tests\Feature\Checkouts\Api;
use App\Mail\CheckoutAccessoryMail;
use App\Models\Accessory;
use App\Models\Actionlog;
use App\Models\User;
use App\Notifications\CheckoutAccessoryNotification;
use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Facades\Notification;
use Tests\Concerns\TestsPermissionsRequirement;
use Tests\TestCase;
@ -146,7 +148,7 @@ class AccessoryCheckoutTest extends TestCase implements TestsPermissionsRequirem
public function testUserSentNotificationUponCheckout()
{
Notification::fake();
Mail::fake();
$accessory = Accessory::factory()->requiringAcceptance()->create();
$user = User::factory()->create();
@ -157,7 +159,9 @@ class AccessoryCheckoutTest extends TestCase implements TestsPermissionsRequirem
'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,10 +2,12 @@
namespace Tests\Feature\Checkouts\Api;
use App\Mail\CheckoutConsumableMail;
use App\Models\Actionlog;
use App\Models\Consumable;
use App\Models\User;
use App\Notifications\CheckoutConsumableNotification;
use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Facades\Notification;
use Tests\TestCase;
@ -51,7 +53,7 @@ class ConsumableCheckoutTest extends TestCase
public function testUserSentNotificationUponCheckout()
{
Notification::fake();
Mail::fake();
$consumable = Consumable::factory()->requiringAcceptance()->create();
@ -62,7 +64,7 @@ class ConsumableCheckoutTest extends TestCase
'assigned_to' => $user->id,
]);
Notification::assertSentTo($user, CheckoutConsumableNotification::class);
Mail::assertSentTo($user, CheckoutConsumableMail::class);
}
public function testActionLogCreatedUponCheckout()

View file

@ -171,7 +171,7 @@ class AccessoryCheckoutTest extends TestCase
]);
Mail::assertSent(CheckoutAccessoryMail::class, function ($mail) use ($accessory, $user) {
return $mail->hasTo($user) && $mail->contains($accessory);
return $mail->hasTo($user->email) && $mail->accessory->is($accessory);
});
}

View file

@ -66,7 +66,7 @@ class ConsumableCheckoutTest extends TestCase
]);
Mail::assertSent(CheckoutConsumableMail::class, function ($mail) use ($consumable, $user) {
return $mail->hasTo($user) && $mail->consumables->contains($consumable);
return $mail->hasTo($user->email) && $mail->consumable->is($consumable);
});
}

View file

@ -140,7 +140,9 @@ class ImportAssetsTest extends ImportDataTestCase implements TestsPermissionsReq
//Notes is never read.
// $this->assertEquals($row['notes'], $newAsset->notes);
Mail::assertSent($assignee, CheckoutAssetMail::class);
Mail::assertSent(CheckoutAssetMail::class, function ($mail) use ($assignee) {
return $mail->hasTo($assignee->email);
});
}
#[Test]

View file

@ -19,7 +19,7 @@ class EmailNotificationsUponCheckinTest extends TestCase
{
parent::setUp();
Notification::fake();
Mail::fake();
}
public function testCheckInEmailSentToUserIfSettingEnabled()

View file

@ -1,12 +1,14 @@
<?php
namespace Tests\Unit;
use App\Mail\CheckoutAssetMail;
use App\Models\User;
use App\Models\Asset;
use App\Models\AssetModel;
use App\Models\Category;
use Carbon\Carbon;
use App\Notifications\CheckoutAssetNotification;
use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Facades\Notification;
use Tests\TestCase;
@ -29,13 +31,13 @@ class NotificationTest extends TestCase
'purchase_date' => Carbon::createFromDate(2017, 1, 1)->hour(0)->minute(0)->second(0)->format('Y-m-d')
]);
Notification::fake();
Mail::fake();
$asset->checkOut($user, $admin->id);
Notification::assertSentTo($user, CheckoutAssetNotification::class);
Mail::assertSent($user, CheckoutAssetMail::class);
}
public function testDefaultEulaIsSentWhenSetInCategory()
{
Notification::fake();
Mail::fake();
$this->settings->setEula('My Custom EULA Text');
@ -51,10 +53,10 @@ class NotificationTest extends TestCase
$asset->checkOut($user, User::factory()->superuser()->create()->id);
Notification::assertSentTo($user, CheckoutAssetNotification::class, function ($notification) {
$content = $notification->toMail()->render();
return str_contains($content, 'My Custom EULA Text') && !str_contains($content, 'EULA Text that should not be used');
Mail::assertSent(CheckoutAssetMail::class, function ($mail) use ($user) {
return $mail->hasTo($user->email) &&
str_contains($mail->render(), 'My Custom EULA Text') &&
!str_contains($mail->render(), 'EULA Text that should not be used');
});
}
}