A free open source IT asset/license management system
Add failing tests
Marcus Mooree9088383764f
diff --git a/tests/Feature/CheckoutAcceptances/Ui/AccessoryAcceptanceTest.php b/tests/Feature/CheckoutAcceptances/Ui/AccessoryAcceptanceTest.phpindex 7b3d8c49aa..0d036591d0 100644--- a/tests/Feature/CheckoutAcceptances/Ui/AccessoryAcceptanceTest.php+++ b/tests/Feature/CheckoutAcceptances/Ui/AccessoryAcceptanceTest.php@@ -14,6 +14,72 @@ use Tests\TestCase;class AccessoryAcceptanceTest extends TestCase{+ public function test_can_accept_accessory_checkout()+ {+ $assignee = User::factory()->create();+ $accessory = Accessory::factory()->create();++ $checkoutAcceptance = CheckoutAcceptance::factory()+ ->pending()+ ->for($assignee, 'assignedTo')+ ->for($accessory, 'checkoutable')+ ->create(['qty' => 2]);++ $this->actingAs($assignee)+ ->post(route('account.store-acceptance', $checkoutAcceptance), [+ 'asset_acceptance' => 'accepted',+ 'note' => 'A note here',+ ])+ ->assertRedirect();++ $this->assertNotNull($checkoutAcceptance->refresh()->accepted_at);+ $this->assertEquals('A note here', $checkoutAcceptance->note);++ $assignee->accessories->contains($accessory);++ $this->assertDatabaseHas('action_logs', [+ 'action_type' => 'accepted',+ 'target_id' => $assignee->id,+ 'target_type' => User::class,+ 'item_id' => $accessory->id,+ 'item_type' => Accessory::class,+ 'qty' => 2,+ ]);+ }++ public function test_can_decline_accessory_checkout()+ {+ $assignee = User::factory()->create();+ $accessory = Accessory::factory()->create();++ $checkoutAcceptance = CheckoutAcceptance::factory()+ ->pending()+ ->for($assignee, 'assignedTo')+ ->for($accessory, 'checkoutable')+ ->create(['qty' => 2]);++ $this->actingAs($assignee)+ ->post(route('account.store-acceptance', $checkoutAcceptance), [+ 'asset_acceptance' => 'declined',+ 'note' => 'A note here',+ ])+ ->assertRedirect();++ $this->assertNotNull($checkoutAcceptance->refresh()->declined_at);+ $this->assertEquals('A note here', $checkoutAcceptance->note);++ $assignee->accessories->doesntContain($accessory);++ $this->assertDatabaseHas('action_logs', [+ 'action_type' => 'declined',+ 'target_id' => $assignee->id,+ 'target_type' => User::class,+ 'item_id' => $accessory->id,+ 'item_type' => Accessory::class,+ 'qty' => 2,+ ]);+ }+/*** This can be absorbed into a bigger test*/diff --git a/tests/Feature/CheckoutAcceptances/Ui/ConsumableAcceptanceTest.php b/tests/Feature/CheckoutAcceptances/Ui/ConsumableAcceptanceTest.phpnew file mode 100644index 0000000000..2877bd4498--- /dev/null+++ b/tests/Feature/CheckoutAcceptances/Ui/ConsumableAcceptanceTest.php@@ -0,0 +1,77 @@+<?php++namespace Tests\Feature\CheckoutAcceptances\Ui;++use App\Models\CheckoutAcceptance;+use App\Models\Consumable;+use App\Models\User;+use Tests\TestCase;++class ConsumableAcceptanceTest extends TestCase+{+ public function test_can_accept_consumable_checkout()+ {+ $assignee = User::factory()->create();+ $consumable = Consumable::factory()->create();++ $checkoutAcceptance = CheckoutAcceptance::factory()+ ->pending()+ ->for($assignee, 'assignedTo')+ ->for($consumable, 'checkoutable')+ ->create(['qty' => 2]);++ $this->actingAs($assignee)+ ->post(route('account.store-acceptance', $checkoutAcceptance), [+ 'asset_acceptance' => 'accepted',+ 'note' => 'A note here',+ ])+ ->assertRedirect();++ $this->assertNotNull($checkoutAcceptance->refresh()->accepted_at);+ $this->assertEquals('A note here', $checkoutAcceptance->note);++ $assignee->consumables->contains($consumable);++ $this->assertDatabaseHas('action_logs', [+ 'action_type' => 'accepted',+ 'target_id' => $assignee->id,+ 'target_type' => User::class,+ 'item_id' => $consumable->id,+ 'item_type' => Consumable::class,+ 'qty' => 2,+ ]);+ }++ public function test_can_decline_consumable_checkout()+ {+ $assignee = User::factory()->create();+ $consumable = Consumable::factory()->create();++ $checkoutAcceptance = CheckoutAcceptance::factory()+ ->pending()+ ->for($assignee, 'assignedTo')+ ->for($consumable, 'checkoutable')+ ->create(['qty' => 2]);++ $this->actingAs($assignee)+ ->post(route('account.store-acceptance', $checkoutAcceptance), [+ 'asset_acceptance' => 'declined',+ 'note' => 'A note here',+ ])+ ->assertRedirect();++ $this->assertNotNull($checkoutAcceptance->refresh()->declined_at);+ $this->assertEquals('A note here', $checkoutAcceptance->note);++ $assignee->consumables->doesntContain($consumable);++ $this->assertDatabaseHas('action_logs', [+ 'action_type' => 'declined',+ 'target_id' => $assignee->id,+ 'target_type' => User::class,+ 'item_id' => $consumable->id,+ 'item_type' => Consumable::class,+ 'qty' => 2,+ ]);+ }+}diff --git a/tests/Feature/Checkouts/Api/AccessoryCheckoutTest.php b/tests/Feature/Checkouts/Api/AccessoryCheckoutTest.phpindex 2af6cf49a2..8ca281b09b 100644--- a/tests/Feature/Checkouts/Api/AccessoryCheckoutTest.php+++ b/tests/Feature/Checkouts/Api/AccessoryCheckoutTest.php@@ -123,6 +123,7 @@ class AccessoryCheckoutTest extends TestCase implements TestsPermissionsRequirem'target_type' => User::class,'item_id' => $accessory->id,'item_type' => Accessory::class,+ 'qty' => 2,'created_by' => $admin->id,])->count(),'Log entry either does not exist or there are more than expected'diff --git a/tests/Feature/Checkouts/Api/ComponentCheckoutTest.php b/tests/Feature/Checkouts/Api/ComponentCheckoutTest.phpindex 50f9df8641..8440e2d695 100644--- a/tests/Feature/Checkouts/Api/ComponentCheckoutTest.php+++ b/tests/Feature/Checkouts/Api/ComponentCheckoutTest.php@@ -109,7 +109,7 @@ class ComponentCheckoutTest extends TestCase implements TestsFullMultipleCompani$this->actingAsForApi($user)->postJson(route('api.components.checkout', $component->id), ['assigned_to' => $asset->id,- 'assigned_qty' => 1,+ 'assigned_qty' => 2,]);$this->assertDatabaseHas('action_logs', [@@ -120,6 +120,7 @@ class ComponentCheckoutTest extends TestCase implements TestsFullMultipleCompani'location_id' => $location->id,'item_type' => Component::class,'item_id' => $component->id,+ 'qty' => 2,]);}diff --git a/tests/Feature/Checkouts/Api/ConsumableCheckoutTest.php b/tests/Feature/Checkouts/Api/ConsumableCheckoutTest.phpindex 44aa5e11ea..c78fac2251 100644--- a/tests/Feature/Checkouts/Api/ConsumableCheckoutTest.php+++ b/tests/Feature/Checkouts/Api/ConsumableCheckoutTest.php@@ -52,6 +52,27 @@ class ConsumableCheckoutTest extends TestCase$this->assertHasTheseActionLogs($consumable, ['create', 'checkout']);}+ public function testConsumableCanBeCheckedOutWithQuantity()+ {+ $consumable = Consumable::factory()->create();+ $user = User::factory()->create();++ $this->actingAsForApi(User::factory()->checkoutConsumables()->create())+ ->postJson(route('api.consumables.checkout', $consumable), [+ 'assigned_to' => $user->id,+ 'checkout_qty' => 2,+ ]);++ $this->assertDatabaseHas('action_logs', [+ 'item_type' => Consumable::class,+ 'item_id' => $consumable->id,+ 'target_type' => User::class,+ 'target_id' => $user->id,+ 'action_type' => 'checkout',+ 'qty' => 2,+ ]);+ }+public function testUserSentNotificationUponCheckout(){Mail::fake();diff --git a/tests/Feature/Checkouts/Ui/AccessoryCheckoutTest.php b/tests/Feature/Checkouts/Ui/AccessoryCheckoutTest.phpindex f9e84015e2..0b0d62d03d 100644--- a/tests/Feature/Checkouts/Ui/AccessoryCheckoutTest.php+++ b/tests/Feature/Checkouts/Ui/AccessoryCheckoutTest.php@@ -81,6 +81,7 @@ class AccessoryCheckoutTest extends TestCase'target_type' => User::class,'item_id' => $accessory->id,'item_type' => Accessory::class,+ 'qty' => 1,'note' => 'oh hi there',]);$this->assertHasTheseActionLogs($accessory, ['create', 'checkout']);@@ -108,6 +109,7 @@ class AccessoryCheckoutTest extends TestCase'target_type' => User::class,'item_id' => $accessory->id,'item_type' => Accessory::class,+ 'qty' => 3,'note' => 'oh hi there',]);$this->assertHasTheseActionLogs($accessory, ['create', 'checkout']);@@ -135,6 +137,7 @@ class AccessoryCheckoutTest extends TestCase'target_type' => Location::class,'item_id' => $accessory->id,'item_type' => Accessory::class,+ 'qty' => 3,'note' => 'oh hi there',]);$this->assertHasTheseActionLogs($accessory, ['create', 'checkout']);@@ -162,6 +165,7 @@ class AccessoryCheckoutTest extends TestCase'target_type' => Asset::class,'item_id' => $accessory->id,'item_type' => Accessory::class,+ 'qty' => 3,'note' => 'oh hi there',]);$this->assertHasTheseActionLogs($accessory, ['create', 'checkout']);diff --git a/tests/Feature/Checkouts/Ui/ComponentsCheckoutTest.php b/tests/Feature/Checkouts/Ui/ComponentsCheckoutTest.phpindex 96c7b89322..f29bff589a 100644--- a/tests/Feature/Checkouts/Ui/ComponentsCheckoutTest.php+++ b/tests/Feature/Checkouts/Ui/ComponentsCheckoutTest.php@@ -97,4 +97,30 @@ class ComponentsCheckoutTest extends TestCase->assertRedirect(route('hardware.show', $asset));$this->assertHasTheseActionLogs($component, ['create', 'checkout']);}++ public function test_quantity_stored_in_action_log()+ {+ $component = Component::factory()->create();+ $asset = Asset::factory()->create();++ $admin = User::factory()->admin()->create();++ $this->actingAs($admin)+ ->from(route('components.index'))+ ->post(route('components.checkout.store', $component), [+ 'asset_id' => $asset->id,+ 'redirect_option' => 'index',+ 'assigned_qty' => 2,+ ]);++ $this->assertDatabaseHas('action_logs', [+ 'action_type' => 'checkout',+ 'target_id' => $asset->id,+ 'target_type' => Asset::class,+ 'item_id' => $component->id,+ 'item_type' => Component::class,+ 'qty' => 2,+ 'created_by' => $admin->id,+ ]);+ }}diff --git a/tests/Feature/Checkouts/Ui/ConsumableCheckoutTest.php b/tests/Feature/Checkouts/Ui/ConsumableCheckoutTest.phpindex fa92cb7417..76814eb819 100644--- a/tests/Feature/Checkouts/Ui/ConsumableCheckoutTest.php+++ b/tests/Feature/Checkouts/Ui/ConsumableCheckoutTest.php@@ -150,4 +150,29 @@ class ConsumableCheckoutTest extends TestCase->assertRedirect(route('users.show', $user));}+ public function test_quantity_stored_in_action_log()+ {+ $consumable = Consumable::factory()->create();+ $user = User::factory()->create();++ $admin = User::factory()->admin()->create();++ $this->actingAs($admin)+ ->from(route('components.index'))+ ->post(route('consumables.checkout.store', $consumable), [+ 'assigned_to' => $user->id,+ 'redirect_option' => 'target',+ 'assigned_qty' => 2,+ ]);++ $this->assertDatabaseHas('action_logs', [+ 'action_type' => 'checkout',+ 'target_id' => $user->id,+ 'target_type' => User::class,+ 'item_id' => $consumable->id,+ 'item_type' => Consumable::class,+ 'qty' => 2,+ 'created_by' => $admin->id,+ ]);+ }}