2023-05-03 14:22:05 -07:00
|
|
|
<?php
|
|
|
|
|
2024-06-04 10:48:53 -07:00
|
|
|
namespace Tests\Feature\CheckoutAcceptances\Ui;
|
2023-05-03 14:22:05 -07:00
|
|
|
|
|
|
|
use App\Models\Accessory;
|
2024-07-09 08:35:16 -07:00
|
|
|
use App\Models\Asset;
|
2023-05-03 14:22:05 -07:00
|
|
|
use App\Models\CheckoutAcceptance;
|
2024-07-09 08:35:16 -07:00
|
|
|
use App\Models\User;
|
2023-05-03 14:22:05 -07:00
|
|
|
use App\Notifications\AcceptanceAssetAcceptedNotification;
|
|
|
|
use App\Notifications\AcceptanceAssetDeclinedNotification;
|
2024-07-19 14:27:03 -07:00
|
|
|
use Illuminate\Support\Facades\Notification;
|
2023-05-03 14:22:05 -07:00
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
|
|
class AccessoryAcceptanceTest extends TestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2024-07-09 08:35:16 -07:00
|
|
|
|
|
|
|
public function testUserIsNotAbleToAcceptAnAssetAssignedToADifferentUser()
|
|
|
|
{
|
|
|
|
Notification::fake();
|
|
|
|
|
|
|
|
$otherUser = User::factory()->create();
|
|
|
|
|
|
|
|
$acceptance = CheckoutAcceptance::factory()
|
|
|
|
->pending()
|
|
|
|
->for(Asset::factory()->laptopMbp(), 'checkoutable')
|
|
|
|
->create();
|
|
|
|
|
2024-07-09 09:13:06 -07:00
|
|
|
$this->actingAs($otherUser)
|
2024-07-09 08:35:16 -07:00
|
|
|
->post(route('account.store-acceptance', $acceptance), ['asset_acceptance' => 'accepted'])
|
2024-07-09 09:13:06 -07:00
|
|
|
->assertSessionHas(['error' => trans('admin/users/message.error.incorrect_user_accepted')]);
|
2024-07-09 08:35:16 -07:00
|
|
|
|
2024-07-09 09:13:06 -07:00
|
|
|
$this->assertNull($acceptance->fresh()->accepted_at);
|
2024-07-09 08:35:16 -07:00
|
|
|
}
|
2023-05-03 14:22:05 -07:00
|
|
|
}
|