2024-07-26 05:16:31 -07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Feature\Checkins\Ui;
|
|
|
|
|
|
|
|
use App\Models\Component;
|
|
|
|
use App\Models\User;
|
2024-08-13 15:31:16 -07:00
|
|
|
use Illuminate\Support\Facades\DB;
|
2024-07-26 05:16:31 -07:00
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
|
|
class ComponentCheckinTest extends TestCase
|
|
|
|
{
|
|
|
|
public function testCheckingInComponentRequiresCorrectPermission()
|
|
|
|
{
|
2024-08-13 15:31:16 -07:00
|
|
|
$component = Component::factory()->checkedOutToAsset()->create();
|
|
|
|
|
|
|
|
$componentAsset = DB::table('components_assets')->where('component_id', $component->id)->first();
|
|
|
|
|
2024-07-26 05:16:31 -07:00
|
|
|
$this->actingAs(User::factory()->create())
|
|
|
|
->post(route('components.checkin.store', [
|
2024-08-13 15:31:16 -07:00
|
|
|
'componentID' => $componentAsset->id,
|
2024-07-26 05:16:31 -07:00
|
|
|
]))
|
|
|
|
->assertForbidden();
|
|
|
|
}
|
|
|
|
|
2024-07-26 06:27:07 -07:00
|
|
|
public function testComponentCheckinPagePostIsRedirectedIfRedirectSelectionIsIndex()
|
2024-07-26 05:43:10 -07:00
|
|
|
{
|
|
|
|
$component = Component::factory()->checkedOutToAsset()->create();
|
|
|
|
|
2024-08-13 15:31:16 -07:00
|
|
|
$componentAsset = DB::table('components_assets')->where('component_id', $component->id)->first();
|
|
|
|
|
2024-07-26 05:43:10 -07:00
|
|
|
$this->actingAs(User::factory()->admin()->create())
|
|
|
|
->from(route('components.index'))
|
2024-08-13 15:31:16 -07:00
|
|
|
->post(route('components.checkin.store', [
|
|
|
|
'componentID' => $componentAsset->id,
|
|
|
|
]), [
|
2024-07-26 05:43:10 -07:00
|
|
|
'redirect_option' => 'index',
|
|
|
|
'checkin_qty' => 1,
|
|
|
|
])
|
|
|
|
->assertStatus(302)
|
|
|
|
->assertRedirect(route('components.index'));
|
|
|
|
}
|
|
|
|
|
2024-07-26 06:27:07 -07:00
|
|
|
public function testComponentCheckinPagePostIsRedirectedIfRedirectSelectionIsItem()
|
2024-07-26 05:43:10 -07:00
|
|
|
{
|
|
|
|
$component = Component::factory()->checkedOutToAsset()->create();
|
|
|
|
|
2024-08-13 15:31:16 -07:00
|
|
|
$componentAsset = DB::table('components_assets')->where('component_id', $component->id)->first();
|
|
|
|
|
2024-07-26 05:43:10 -07:00
|
|
|
$this->actingAs(User::factory()->admin()->create())
|
|
|
|
->from(route('components.index'))
|
2024-08-13 15:31:16 -07:00
|
|
|
->post(route('components.checkin.store', [
|
|
|
|
'componentID' => $componentAsset->id,
|
|
|
|
]), [
|
2024-07-26 05:43:10 -07:00
|
|
|
'redirect_option' => 'item',
|
|
|
|
'checkin_qty' => 1,
|
|
|
|
])
|
|
|
|
->assertStatus(302)
|
2024-07-26 06:27:07 -07:00
|
|
|
->assertSessionHasNoErrors()
|
2024-07-26 05:43:10 -07:00
|
|
|
->assertRedirect(route('components.show', ['component' => $component->id]));
|
|
|
|
}
|
2024-07-26 05:16:31 -07:00
|
|
|
}
|