snipe-it/tests/Feature/CheckoutAcceptances/AccessoryAcceptanceTest.php

83 lines
2.5 KiB
PHP
Raw Normal View History

<?php
namespace Tests\Feature\CheckoutAcceptances;
use App\Models\Accessory;
use App\Models\CheckoutAcceptance;
use App\Notifications\AcceptanceAssetAcceptedNotification;
use App\Notifications\AcceptanceAssetDeclinedNotification;
use Notification;
use Tests\Support\InteractsWithSettings;
use Tests\TestCase;
class AccessoryAcceptanceTest extends TestCase
{
use InteractsWithSettings;
/**
* This can be absorbed into a bigger test
*/
public function testUsersNameIsIncludedInAccessoryAcceptedNotification()
{
Notification::fake();
$this->settings->enableAlertEmail();
$acceptance = CheckoutAcceptance::factory()
->pending()
->for(Accessory::factory()->appleMouse(), 'checkoutable')
->create();
$this->actingAs($acceptance->assignedTo)
->post(route('account.store-acceptance', $acceptance), ['asset_acceptance' => 'accepted'])
->assertSessionHasNoErrors();
$this->assertNotNull($acceptance->fresh()->accepted_at);
Notification::assertSentTo(
$acceptance,
function (AcceptanceAssetAcceptedNotification $notification) use ($acceptance) {
$this->assertStringContainsString(
$acceptance->assignedTo->present()->fullName,
$notification->toMail()->render()
);
return true;
}
);
}
/**
* This can be absorbed into a bigger test
*/
public function testUsersNameIsIncludedInAccessoryDeclinedNotification()
{
Notification::fake();
$this->settings->enableAlertEmail();
$acceptance = CheckoutAcceptance::factory()
->pending()
->for(Accessory::factory()->appleMouse(), 'checkoutable')
->create();
$this->actingAs($acceptance->assignedTo)
->post(route('account.store-acceptance', $acceptance), ['asset_acceptance' => 'declined'])
->assertSessionHasNoErrors();
$this->assertNotNull($acceptance->fresh()->declined_at);
Notification::assertSentTo(
$acceptance,
function (AcceptanceAssetDeclinedNotification $notification) use ($acceptance) {
$this->assertStringContainsString(
$acceptance->assignedTo->present()->fullName,
$notification->toMail($acceptance)->render()
);
return true;
}
);
}
}