snipe-it/tests/Feature/Checkins/Ui/ComponentCheckinTest.php
snipe ff6e6ef88c Added more tests
Signed-off-by: snipe <snipe@snipe.net>
2024-07-26 13:43:10 +01:00

50 lines
1.5 KiB
PHP

<?php
namespace Tests\Feature\Checkins\Ui;
use App\Models\Component;
use App\Models\User;
use Tests\TestCase;
class ComponentCheckinTest extends TestCase
{
public function testCheckingInComponentRequiresCorrectPermission()
{
$this->actingAs(User::factory()->create())
->post(route('components.checkin.store', [
'componentID' => Component::factory()->checkedOutToAsset()->create()->id,
]))
->assertForbidden();
}
public function testAssetCheckinPagePostIsRedirectedIfModelIsInvalid()
{
$component = Component::factory()->checkedOutToAsset()->create();
$this->actingAs(User::factory()->admin()->create())
->from(route('components.index'))
->post(route('components.checkin.store', $component), [
'redirect_option' => 'index',
'checkin_qty' => 1,
])
->assertStatus(302)
->assertRedirect(route('components.index'));
}
public function testComponentCheckinPagePostIsRedirectedIfRedirectSelectioonGiven()
{
$component = Component::factory()->checkedOutToAsset()->create();
$this->actingAs(User::factory()->admin()->create())
->from(route('components.index'))
->post(route('components.checkin.store', $component), [
'redirect_option' => 'item',
'checkin_qty' => 1,
])
->assertStatus(302)
->assertRedirect(route('components.show', ['component' => $component->id]));
}
}