Scaffold additional failed tests
This commit is contained in:
parent
374812f8fe
commit
0aff35b622
2 changed files with 57 additions and 4 deletions
|
@ -21,7 +21,7 @@ class ComponentsCheckoutTest extends TestCase
|
||||||
->assertForbidden();
|
->assertForbidden();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCannotCheckoutAcrossCompaniesWhenFullCompanySupportEnabled()
|
public function test_cannot_checkout_across_companies_when_full_company_support_enabled()
|
||||||
{
|
{
|
||||||
Event::fake([CheckoutableCheckedOut::class]);
|
Event::fake([CheckoutableCheckedOut::class]);
|
||||||
|
|
||||||
|
@ -36,9 +36,6 @@ class ComponentsCheckoutTest extends TestCase
|
||||||
->post(route('components.checkout.store', $component), [
|
->post(route('components.checkout.store', $component), [
|
||||||
'asset_id' => $asset->id,
|
'asset_id' => $asset->id,
|
||||||
'assigned_qty' => '1',
|
'assigned_qty' => '1',
|
||||||
// @todo:
|
|
||||||
'note' => null,
|
|
||||||
// @todo:
|
|
||||||
'redirect_option' => 'index',
|
'redirect_option' => 'index',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
<?php
|
<?php
|
||||||
namespace Tests\Unit;
|
namespace Tests\Unit;
|
||||||
|
|
||||||
|
use App\Models\Asset;
|
||||||
use App\Models\Category;
|
use App\Models\Category;
|
||||||
use App\Models\Company;
|
use App\Models\Company;
|
||||||
use App\Models\Component;
|
use App\Models\Component;
|
||||||
use App\Models\Location;
|
use App\Models\Location;
|
||||||
|
use App\Models\User;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
|
|
||||||
class ComponentTest extends TestCase
|
class ComponentTest extends TestCase
|
||||||
|
@ -41,4 +43,58 @@ class ComponentTest extends TestCase
|
||||||
$this->assertInstanceOf(Category::class, $component->category);
|
$this->assertInstanceOf(Category::class, $component->category);
|
||||||
$this->assertEquals('component', $component->category->category_type);
|
$this->assertEquals('component', $component->category->category_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function test_num_checked_out_takes_does_not_scope_by_company()
|
||||||
|
{
|
||||||
|
$this->settings->enableMultipleFullCompanySupport();
|
||||||
|
|
||||||
|
[$companyA, $companyB] = Company::factory()->count(2)->create();
|
||||||
|
|
||||||
|
$componentForCompanyA = Component::factory()->for($companyA)->create(['qty' => 5]);
|
||||||
|
$assetForCompanyB = Asset::factory()->for($companyB)->create();
|
||||||
|
|
||||||
|
// Ideally, we shouldn't have a component attached to an
|
||||||
|
// asset from a different company but alas...
|
||||||
|
$componentForCompanyA->assets()->attach($componentForCompanyA->id, [
|
||||||
|
'component_id' => $componentForCompanyA->id,
|
||||||
|
'assigned_qty' => 4,
|
||||||
|
'asset_id' => $assetForCompanyB->id,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->actingAs(User::factory()->superuser()->create());
|
||||||
|
$this->assertEquals(4, $componentForCompanyA->fresh()->numCheckedOut());
|
||||||
|
|
||||||
|
$this->actingAs(User::factory()->admin()->create());
|
||||||
|
$this->assertEquals(4, $componentForCompanyA->fresh()->numCheckedOut());
|
||||||
|
|
||||||
|
$this->actingAs(User::factory()->for($companyA)->create());
|
||||||
|
$this->assertEquals(4, $componentForCompanyA->fresh()->numCheckedOut());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_num_remaining_takes_company_scoping_into_account()
|
||||||
|
{
|
||||||
|
$this->settings->enableMultipleFullCompanySupport();
|
||||||
|
|
||||||
|
[$companyA, $companyB] = Company::factory()->count(2)->create();
|
||||||
|
|
||||||
|
$componentForCompanyA = Component::factory()->for($companyA)->create(['qty' => 5]);
|
||||||
|
$assetForCompanyB = Asset::factory()->for($companyB)->create();
|
||||||
|
|
||||||
|
// Ideally, we shouldn't have a component attached to an
|
||||||
|
// asset from a different company but alas...
|
||||||
|
$componentForCompanyA->assets()->attach($componentForCompanyA->id, [
|
||||||
|
'component_id' => $componentForCompanyA->id,
|
||||||
|
'assigned_qty' => 4,
|
||||||
|
'asset_id' => $assetForCompanyB->id,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->actingAs(User::factory()->superuser()->create());
|
||||||
|
$this->assertEquals(1, $componentForCompanyA->fresh()->numRemaining());
|
||||||
|
|
||||||
|
$this->actingAs(User::factory()->admin()->create());
|
||||||
|
$this->assertEquals(1, $componentForCompanyA->fresh()->numRemaining());
|
||||||
|
|
||||||
|
$this->actingAs(User::factory()->for($companyA)->create());
|
||||||
|
$this->assertEquals(1, $componentForCompanyA->fresh()->numRemaining());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue