Skip to content

A free open source IT asset/license management system

Add failing tests

Marcus Moore3c5f4067dd91
diff --git a/tests/Feature/Checkouts/Ui/ConsumableCheckoutTest.php b/tests/Feature/Checkouts/Ui/ConsumableCheckoutTest.php
index 5319638440..eb633ac6b7 100644
--- a/tests/Feature/Checkouts/Ui/ConsumableCheckoutTest.php
+++ b/tests/Feature/Checkouts/Ui/ConsumableCheckoutTest.php
@@ -5,6 +5,7 @@ namespace Tests\Feature\Checkouts\Ui;
use App\Mail\CheckoutConsumableMail;
use App\Models\Actionlog;
use App\Models\CheckoutAcceptance;
+use App\Models\Company;
use App\Models\Consumable;
use App\Models\User;
use Illuminate\Support\Facades\Mail;
@@ -249,4 +250,29 @@ class ConsumableCheckoutTest extends TestCase
$response->assertSessionHas('sign_in_place', true);
}
+
+ public function test_cannot_check_out_more_than_physically_remain_when_units_are_held_outside_viewers_company()
+ {
+ $this->settings->enableMultipleFullCompanySupport();
+
+ [$companyA, $companyB] = Company::factory()->count(2)->create();
+ $userInCompanyA = User::factory()->forCompany($companyA)->create();
+ $userInCompanyB = User::factory()->forCompany($companyB)->create();
+
+ $consumable = Consumable::factory()
+ ->for($companyA)
+ // this can happen if FMCS was toggled on after checkouts
+ ->checkedOutToUser($userInCompanyB)
+ ->checkedOutToUser($userInCompanyB)
+ ->create(['qty' => 2]);
+
+ $this->assertDatabaseCount('consumables_users', 2);
+
+ $this->actingAs(User::factory()->checkoutConsumables()->forCompany($companyA)->create())
+ ->post(route('consumables.checkout.store', $consumable), [
+ 'assigned_user' => $userInCompanyA->id,
+ ]);
+
+ $this->assertDatabaseCount('consumables_users', 2);
+ }
}
diff --git a/tests/Feature/Consumables/Api/ConsumableIndexTest.php b/tests/Feature/Consumables/Api/ConsumableIndexTest.php
index 4d85ada3ae..43f0416efb 100644
--- a/tests/Feature/Consumables/Api/ConsumableIndexTest.php
+++ b/tests/Feature/Consumables/Api/ConsumableIndexTest.php
@@ -143,4 +143,46 @@ class ConsumableIndexTest extends TestCase
->assertResponseDoesNotContainInRows($otherConsumable);
}
}
+
+ public function test_remaining_includes_checkouts_to_users_outside_viewers_company()
+ {
+ $this->settings->enableMultipleFullCompanySupport();
+
+ [$companyA, $companyB] = Company::factory()->count(2)->create();
+ $userInCompanyB = User::factory()->forCompany($companyB)->create();
+
+ $consumableForCompanyA = Consumable::factory()
+ ->for($companyA)
+ // this can happen if FMCS was toggled on after checkouts
+ ->checkedOutToUser($userInCompanyB)
+ ->checkedOutToUser($userInCompanyB)
+ ->create(['qty' => 3]);
+
+ $this->actingAsForApi(User::factory()->viewConsumables()->forCompany($companyA)->create())
+ ->getJson(route('api.consumables.index'))
+ ->assertOk()
+ ->assertJsonPath('rows.0.id', $consumableForCompanyA->id)
+ ->assertJsonPath('rows.0.remaining', 1);
+ }
+
+ public function test_requestable_remaining_includes_checkouts_to_users_outside_viewers_company()
+ {
+ $this->settings->enableMultipleFullCompanySupport();
+
+ [$companyA, $companyB] = Company::factory()->count(2)->create();
+ $userInCompanyB = User::factory()->forCompany($companyB)->create();
+
+ $consumableForCompanyA = Consumable::factory()
+ ->for($companyA)
+ // this can happen if FMCS was toggled on after checkouts
+ ->checkedOutToUser($userInCompanyB)
+ ->checkedOutToUser($userInCompanyB)
+ ->create(['qty' => 3, 'requestable' => true]);
+
+ $this->actingAsForApi(User::factory()->forCompany($companyA)->create())
+ ->getJson(route('api.consumables.requestable'))
+ ->assertOk()
+ ->assertJsonPath('rows.0.id', $consumableForCompanyA->id)
+ ->assertJsonPath('rows.0.remaining', 1);
+ }
}
diff --git a/tests/Unit/ConsumableTest.php b/tests/Unit/ConsumableTest.php
index 9ed12a64a2..4360f86649 100644
--- a/tests/Unit/ConsumableTest.php
+++ b/tests/Unit/ConsumableTest.php
@@ -2,7 +2,9 @@
namespace Tests\Unit;
+use App\Models\Company;
use App\Models\Consumable;
+use App\Models\User;
use Tests\TestCase;
class ConsumableTest extends TestCase
@@ -36,4 +38,28 @@ class ConsumableTest extends TestCase
$this->assertEqualsWithDelta(-66.66666666666667, $consumable->percentRemaining(), 0.0000000001);
}
+
+ public function test_num_checked_out_does_not_scope_by_company()
+ {
+ $this->settings->enableMultipleFullCompanySupport();
+
+ [$companyA, $companyB] = Company::factory()->count(2)->create();
+ $userInCompanyB = User::factory()->forCompany($companyB)->create();
+
+ $consumableForCompanyA = Consumable::factory()
+ ->for($companyA)
+ // this can happen if FMCS was toggled on after checkouts
+ ->checkedOutToUser($userInCompanyB)
+ ->checkedOutToUser($userInCompanyB)
+ ->create(['qty' => 3]);
+
+ $this->actingAs(User::factory()->superuser()->create());
+ $this->assertEquals(2, $consumableForCompanyA->fresh()->numCheckedOut());
+
+ $this->actingAs(User::factory()->admin()->forCompany($companyA)->create());
+ $this->assertEquals(2, $consumableForCompanyA->fresh()->numCheckedOut());
+
+ $this->actingAs(User::factory()->forCompany($companyA)->create());
+ $this->assertEquals(2, $consumableForCompanyA->fresh()->numCheckedOut());
+ }
}