104 lines
3.6 KiB
PHP
104 lines
3.6 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature\CheckoutAcceptances\Ui;
|
|
|
|
use App\Models\CheckoutAcceptance;
|
|
use App\Models\Consumable;
|
|
use App\Models\User;
|
|
use Tests\TestCase;
|
|
|
|
class ConsumableAcceptanceTest extends TestCase
|
|
{
|
|
public function test_can_accept_consumable_checkout()
|
|
{
|
|
$assignee = User::factory()->create();
|
|
$consumable = Consumable::factory()->create();
|
|
|
|
$checkoutAcceptance = CheckoutAcceptance::factory()
|
|
->pending()
|
|
->for($assignee, 'assignedTo')
|
|
->for($consumable, 'checkoutable')
|
|
->create(['qty' => 2]);
|
|
|
|
$this->actingAs($assignee)
|
|
->post(route('account.store-acceptance', $checkoutAcceptance), [
|
|
'asset_acceptance' => 'accepted',
|
|
'note' => 'A note here',
|
|
])
|
|
->assertRedirect();
|
|
|
|
$this->assertNotNull($checkoutAcceptance->refresh()->accepted_at);
|
|
$this->assertEquals('A note here', $checkoutAcceptance->note);
|
|
|
|
$assignee->consumables->contains($consumable);
|
|
|
|
$this->assertDatabaseHas('action_logs', [
|
|
'action_type' => 'accepted',
|
|
'target_id' => $assignee->id,
|
|
'target_type' => User::class,
|
|
'item_id' => $consumable->id,
|
|
'item_type' => Consumable::class,
|
|
'quantity' => 2,
|
|
]);
|
|
}
|
|
|
|
public function test_can_decline_consumable_checkout()
|
|
{
|
|
$assignee = User::factory()->create();
|
|
$consumable = Consumable::factory()->create();
|
|
|
|
$checkoutAcceptance = CheckoutAcceptance::factory()
|
|
->pending()
|
|
->for($assignee, 'assignedTo')
|
|
->for($consumable, 'checkoutable')
|
|
->create(['qty' => 2]);
|
|
|
|
$this->actingAs($assignee)
|
|
->post(route('account.store-acceptance', $checkoutAcceptance), [
|
|
'asset_acceptance' => 'declined',
|
|
'note' => 'A note here',
|
|
])
|
|
->assertRedirect();
|
|
|
|
$this->assertNotNull($checkoutAcceptance->refresh()->declined_at);
|
|
$this->assertEquals('A note here', $checkoutAcceptance->note);
|
|
|
|
$assignee->consumables->doesntContain($consumable);
|
|
|
|
$this->assertDatabaseHas('action_logs', [
|
|
'action_type' => 'declined',
|
|
'target_id' => $assignee->id,
|
|
'target_type' => User::class,
|
|
'item_id' => $consumable->id,
|
|
'item_type' => Consumable::class,
|
|
'quantity' => 2,
|
|
]);
|
|
}
|
|
|
|
public function test_acceptance_create_page_shows_email_info_when_always_send_email_enabled()
|
|
{
|
|
$checkoutAcceptance = CheckoutAcceptance::factory()->pending()->create();
|
|
config(['app.always_send_email' => true]);
|
|
|
|
$response = $this->actingAs($checkoutAcceptance->assignedTo)
|
|
->get(route('account.accept.item', $checkoutAcceptance));
|
|
|
|
$response->assertOk();
|
|
$response->assertSee(trans('general.acceptance_email_always_sent'), false);
|
|
$response->assertDontSee(trans('mail.send_pdf_copy'), false);
|
|
}
|
|
|
|
public function test_acceptance_create_page_shows_checkbox_when_always_send_email_disabled()
|
|
{
|
|
$checkoutAcceptance = CheckoutAcceptance::factory()->pending()->create();
|
|
config(['app.always_send_email' => false]);
|
|
|
|
$response = $this->actingAs($checkoutAcceptance->assignedTo)
|
|
->get(route('account.accept.item', $checkoutAcceptance));
|
|
|
|
$response->assertOk();
|
|
$response->assertSee(trans('mail.send_pdf_copy'), false);
|
|
$response->assertDontSee(trans('general.acceptance_email_always_sent'), false);
|
|
}
|
|
}
|