Skip to content

A free open source IT asset/license management system

Added more tests

snipeff6e6ef88cc4
diff --git a/tests/Feature/Checkins/Ui/ComponentCheckinTest.php b/tests/Feature/Checkins/Ui/ComponentCheckinTest.php
index a3fccb6c72..a87b5c1609 100644
--- a/tests/Feature/Checkins/Ui/ComponentCheckinTest.php
+++ b/tests/Feature/Checkins/Ui/ComponentCheckinTest.php
@@ -17,5 +17,33 @@ class ComponentCheckinTest extends TestCase
->assertForbidden();
}
+ public function testAssetCheckinPagePostIsRedirectedIfModelIsInvalid()
+ {
+ $component = Component::factory()->checkedOutToAsset()->create();
+
+ $this->actingAs(User::factory()->admin()->create())
+ ->from(route('components.index'))
+ ->post(route('components.checkin.store', $component), [
+ 'redirect_option' => 'index',
+ 'checkin_qty' => 1,
+ ])
+ ->assertStatus(302)
+ ->assertRedirect(route('components.index'));
+ }
+
+ public function testComponentCheckinPagePostIsRedirectedIfRedirectSelectioonGiven()
+ {
+ $component = Component::factory()->checkedOutToAsset()->create();
+
+ $this->actingAs(User::factory()->admin()->create())
+ ->from(route('components.index'))
+ ->post(route('components.checkin.store', $component), [
+ 'redirect_option' => 'item',
+ 'checkin_qty' => 1,
+ ])
+ ->assertStatus(302)
+ ->assertRedirect(route('components.show', ['component' => $component->id]));
+ }
+
}
diff --git a/tests/Feature/Checkouts/Ui/ComponentsCheckoutTest.php b/tests/Feature/Checkouts/Ui/ComponentsCheckoutTest.php
new file mode 100644
index 0000000000..9948de7ed2
--- /dev/null
+++ b/tests/Feature/Checkouts/Ui/ComponentsCheckoutTest.php
@@ -0,0 +1,68 @@
+<?php
+
+namespace Tests\Feature\Checkins\Ui;
+
+use App\Models\Asset;
+use App\Models\Component;
+use App\Models\User;
+use Tests\TestCase;
+
+class ComponentCheckoutTest extends TestCase
+{
+ public function testCheckingOutComponentRequiresCorrectPermission()
+ {
+ $this->actingAs(User::factory()->create())
+ ->post(route('components.checkout.store', [
+ 'componentID' => Component::factory()->checkedOutToAsset()->create()->id,
+ ]))
+ ->assertForbidden();
+ }
+
+ 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]));
+ }
+
+
+}