2017-08-31 11:14:21 -07:00
|
|
|
<?php
|
2021-11-30 20:09:29 -08:00
|
|
|
namespace Tests\Unit;
|
2021-06-10 13:15:52 -07:00
|
|
|
|
2017-08-31 11:14:21 -07:00
|
|
|
use App\Models\User;
|
2021-12-02 20:01:03 -08:00
|
|
|
use App\Models\Asset;
|
|
|
|
use App\Models\AssetModel;
|
|
|
|
use App\Models\Category;
|
|
|
|
use Carbon\Carbon;
|
2018-03-25 13:46:57 -07:00
|
|
|
use App\Notifications\CheckoutAssetNotification;
|
2017-08-31 11:14:21 -07:00
|
|
|
use Illuminate\Support\Facades\Notification;
|
2023-03-07 16:57:55 -08:00
|
|
|
use Tests\TestCase;
|
2021-12-02 20:01:03 -08:00
|
|
|
|
2023-03-07 16:57:55 -08:00
|
|
|
class NotificationTest extends TestCase
|
2017-08-31 11:14:21 -07:00
|
|
|
{
|
2021-06-10 13:15:52 -07:00
|
|
|
public function testAUserIsEmailedIfTheyCheckoutAnAssetWithEULA()
|
|
|
|
{
|
2023-03-06 12:40:47 -08:00
|
|
|
$admin = User::factory()->superuser()->create();
|
2021-12-02 20:01:03 -08:00
|
|
|
$user = User::factory()->create();
|
|
|
|
$asset = Asset::factory()
|
|
|
|
->create(
|
|
|
|
[
|
|
|
|
'model_id' => AssetModel::factory()
|
|
|
|
->create(
|
|
|
|
[
|
2023-03-13 16:45:43 -07:00
|
|
|
'category_id' => Category::factory()->assetLaptopCategory()->create()->id
|
2021-12-02 20:01:03 -08:00
|
|
|
]
|
2023-03-02 13:47:58 -08:00
|
|
|
)->id,
|
2021-12-02 20:01:03 -08:00
|
|
|
'warranty_months' => 24,
|
2023-03-02 13:47:58 -08:00
|
|
|
'purchase_date' => Carbon::createFromDate(2017, 1, 1)->hour(0)->minute(0)->second(0)->format('Y-m-d')
|
2021-12-02 20:01:03 -08:00
|
|
|
]);
|
|
|
|
|
2020-04-27 18:02:14 -07:00
|
|
|
Notification::fake();
|
2023-03-06 12:40:47 -08:00
|
|
|
$asset->checkOut($user, $admin->id);
|
2020-04-27 18:02:14 -07:00
|
|
|
Notification::assertSentTo($user, CheckoutAssetNotification::class);
|
2021-06-10 13:15:52 -07:00
|
|
|
}
|
2024-09-04 12:21:49 -07:00
|
|
|
public function testDefaultEulaIsSentWhenSetInCategory()
|
|
|
|
{
|
|
|
|
Notification::fake();
|
|
|
|
|
|
|
|
$this->settings->setEula('My Custom EULA Text');
|
|
|
|
|
|
|
|
$user = User::factory()->create();
|
|
|
|
|
|
|
|
$category = Category::factory()->create([
|
|
|
|
'use_default_eula' => 1,
|
|
|
|
'eula_text' => 'EULA Text that should not be used',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$model = AssetModel::factory()->for($category)->create();
|
|
|
|
$asset = Asset::factory()->for($model, 'model')->create();
|
|
|
|
|
|
|
|
$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');
|
|
|
|
});
|
|
|
|
}
|
2017-08-31 11:14:21 -07:00
|
|
|
}
|