2024-07-26 05:43:10 -07:00
|
|
|
<?php
|
|
|
|
|
2024-08-06 10:48:38 -07:00
|
|
|
namespace Tests\Feature\Checkouts\Ui;
|
2024-07-26 05:43:10 -07:00
|
|
|
|
2024-08-06 10:48:38 -07:00
|
|
|
use App\Events\CheckoutableCheckedOut;
|
2024-07-26 05:43:10 -07:00
|
|
|
use App\Models\Asset;
|
2024-08-06 10:48:38 -07:00
|
|
|
use App\Models\Company;
|
2024-07-26 05:43:10 -07:00
|
|
|
use App\Models\Component;
|
|
|
|
use App\Models\User;
|
2024-08-06 10:48:38 -07:00
|
|
|
use Illuminate\Support\Facades\Event;
|
2024-07-26 05:43:10 -07:00
|
|
|
use Tests\TestCase;
|
|
|
|
|
2024-07-29 06:34:10 -07:00
|
|
|
class ComponentsCheckoutTest extends TestCase
|
2024-07-26 05:43:10 -07:00
|
|
|
{
|
|
|
|
public function testCheckingOutComponentRequiresCorrectPermission()
|
|
|
|
{
|
|
|
|
$this->actingAs(User::factory()->create())
|
|
|
|
->post(route('components.checkout.store', [
|
|
|
|
'componentID' => Component::factory()->checkedOutToAsset()->create()->id,
|
|
|
|
]))
|
|
|
|
->assertForbidden();
|
|
|
|
}
|
|
|
|
|
2024-08-06 12:07:34 -07:00
|
|
|
public function test_cannot_checkout_across_companies_when_full_company_support_enabled()
|
2024-08-06 10:48:38 -07:00
|
|
|
{
|
|
|
|
Event::fake([CheckoutableCheckedOut::class]);
|
|
|
|
|
|
|
|
$this->settings->enableMultipleFullCompanySupport();
|
|
|
|
|
|
|
|
[$assetCompany, $componentCompany] = Company::factory()->count(2)->create();
|
|
|
|
|
|
|
|
$asset = Asset::factory()->for($assetCompany)->create();
|
|
|
|
$component = Component::factory()->for($componentCompany)->create();
|
|
|
|
|
|
|
|
$this->actingAs(User::factory()->superuser()->create())
|
|
|
|
->post(route('components.checkout.store', $component), [
|
|
|
|
'asset_id' => $asset->id,
|
|
|
|
'assigned_qty' => '1',
|
|
|
|
'redirect_option' => 'index',
|
|
|
|
]);
|
|
|
|
|
|
|
|
Event::assertNotDispatched(CheckoutableCheckedOut::class);
|
|
|
|
}
|
|
|
|
|
2024-07-26 05:43:10 -07:00
|
|
|
public function testComponentCheckoutPagePostIsRedirectedIfRedirectSelectionIsIndex()
|
|
|
|
{
|
|
|
|
$component = Component::factory()->create();
|
|
|
|
|
|
|
|
$this->actingAs(User::factory()->admin()->create())
|
|
|
|
->from(route('components.index'))
|
|
|
|
->post(route('components.checkout.store', $component), [
|
|
|
|
'asset_id' => Asset::factory()->create()->id,
|
|
|
|
'redirect_option' => 'index',
|
|
|
|
'assigned_qty' => 1,
|
|
|
|
])
|
|
|
|
->assertStatus(302)
|
|
|
|
->assertRedirect(route('components.index'));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testComponentCheckoutPagePostIsRedirectedIfRedirectSelectionIsItem()
|
|
|
|
{
|
|
|
|
$component = Component::factory()->create();
|
|
|
|
|
|
|
|
$this->actingAs(User::factory()->admin()->create())
|
|
|
|
->from(route('components.index'))
|
|
|
|
->post(route('components.checkout.store' , $component), [
|
|
|
|
'asset_id' => Asset::factory()->create()->id,
|
|
|
|
'redirect_option' => 'item',
|
|
|
|
'assigned_qty' => 1,
|
|
|
|
])
|
|
|
|
->assertStatus(302)
|
|
|
|
->assertRedirect(route('components.show', ['component' => $component->id]));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testComponentCheckoutPagePostIsRedirectedIfRedirectSelectionIsTarget()
|
|
|
|
{
|
|
|
|
$asset = Asset::factory()->create();
|
|
|
|
$component = Component::factory()->create();
|
|
|
|
|
|
|
|
$this->actingAs(User::factory()->admin()->create())
|
|
|
|
->from(route('components.index'))
|
|
|
|
->post(route('components.checkout.store' , $component), [
|
|
|
|
'asset_id' => $asset->id,
|
|
|
|
'redirect_option' => 'target',
|
|
|
|
'assigned_qty' => 1,
|
|
|
|
])
|
|
|
|
->assertStatus(302)
|
|
|
|
->assertRedirect(route('hardware.show', ['hardware' => $asset]));
|
|
|
|
}
|
|
|
|
}
|