Skip to content

A free open source IT asset/license management system

Scaffold additional failed tests

Marcus Moore0aff35b62253
diff --git a/tests/Feature/Checkouts/Ui/ComponentsCheckoutTest.php b/tests/Feature/Checkouts/Ui/ComponentsCheckoutTest.php
index 601eeb0b55..e2e91823c1 100644
--- a/tests/Feature/Checkouts/Ui/ComponentsCheckoutTest.php
+++ b/tests/Feature/Checkouts/Ui/ComponentsCheckoutTest.php
@@ -21,7 +21,7 @@ class ComponentsCheckoutTest extends TestCase
->assertForbidden();
}
- public function testCannotCheckoutAcrossCompaniesWhenFullCompanySupportEnabled()
+ public function test_cannot_checkout_across_companies_when_full_company_support_enabled()
{
Event::fake([CheckoutableCheckedOut::class]);
@@ -36,9 +36,6 @@ class ComponentsCheckoutTest extends TestCase
->post(route('components.checkout.store', $component), [
'asset_id' => $asset->id,
'assigned_qty' => '1',
- // @todo:
- 'note' => null,
- // @todo:
'redirect_option' => 'index',
]);
diff --git a/tests/Unit/ComponentTest.php b/tests/Unit/ComponentTest.php
index df8f64771f..6abbffd82d 100644
--- a/tests/Unit/ComponentTest.php
+++ b/tests/Unit/ComponentTest.php
@@ -1,10 +1,12 @@
<?php
namespace Tests\Unit;
+use App\Models\Asset;
use App\Models\Category;
use App\Models\Company;
use App\Models\Component;
use App\Models\Location;
+use App\Models\User;
use Tests\TestCase;
class ComponentTest extends TestCase
@@ -41,4 +43,58 @@ class ComponentTest extends TestCase
$this->assertInstanceOf(Category::class, $component->category);
$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());
+ }
}