Skip to content

A free open source IT asset/license management system

And more tests

snipeeceaa72781a0
diff --git a/tests/Feature/Checkouts/Ui/AssetCheckoutTest.php b/tests/Feature/Checkouts/Ui/AssetCheckoutTest.php
index eed0908c1d..165c6a4194 100644
--- a/tests/Feature/Checkouts/Ui/AssetCheckoutTest.php
+++ b/tests/Feature/Checkouts/Ui/AssetCheckoutTest.php
@@ -3,6 +3,7 @@
namespace Tests\Feature\Checkouts\Ui;
use App\Events\CheckoutableCheckedOut;
+use App\Models\Accessory;
use App\Models\Asset;
use App\Models\Company;
use App\Models\LicenseSeat;
@@ -251,20 +252,85 @@ class AssetCheckoutTest extends TestCase
->assertRedirect(route('hardware.show',['hardware' => $asset->id]));
}
- public function testAssetCheckoutPagePostIsRedirectedIfModelIsInvalid()
+ public function testAssetCheckoutPagePostIsRedirectedIfRedirectSelectionIsIndex()
{
$asset = Asset::factory()->create();
- $asset->model_id = 0;
- $asset->forceSave();
- $user = User::factory()->create();
-
+
$this->actingAs(User::factory()->admin()->create())
+ ->from(route('hardware.checkout.create', $asset))
->post(route('hardware.checkout.store', $asset), [
'checkout_to_type' => 'user',
- 'assigned_user' => $user->id,
+ 'assigned_user' => User::factory()->create()->id,
+ 'redirect_option' => 'index',
])
->assertStatus(302)
- ->assertSessionHas('error')
+ ->assertRedirect(route('hardware.index'));
+ }
+
+ public function testAssetCheckoutPagePostIsRedirectedIfRedirectSelectionIsItem()
+ {
+ $asset = Asset::factory()->create();
+
+ $this->actingAs(User::factory()->admin()->create())
+ ->from(route('hardware.checkout.create', $asset))
+ ->post(route('hardware.checkout.store' , $asset), [
+ 'checkout_to_type' => 'user',
+ 'assigned_user' => User::factory()->create()->id,
+ 'redirect_option' => 'item',
+ ])
+ ->assertStatus(302)
+ ->assertSessionHasNoErrors()
->assertRedirect(route('hardware.show', ['hardware' => $asset->id]));
}
+
+ public function testAssetCheckoutPagePostIsRedirectedIfRedirectSelectionIsUserTarget()
+ {
+ $user = User::factory()->create();
+ $asset = Asset::factory()->create();
+
+ $this->actingAs(User::factory()->admin()->create())
+ ->from(route('hardware.checkout.create', $asset))
+ ->post(route('hardware.checkout.store' , $asset), [
+ 'checkout_to_type' => 'user',
+ 'assigned_user' => $user->id,
+ 'redirect_option' => 'target',
+ 'assigned_qty' => 1,
+ ])
+ ->assertStatus(302)
+ ->assertRedirect(route('users.show', ['user' => $user]));
+ }
+
+ public function testAssetCheckoutPagePostIsRedirectedIfRedirectSelectionIsAssetTarget()
+ {
+ $target = Asset::factory()->create();
+ $asset = Asset::factory()->create();
+
+ $this->actingAs(User::factory()->admin()->create())
+ ->from(route('hardware.checkout.create', $asset))
+ ->post(route('hardware.checkout.store' , $asset), [
+ 'checkout_to_type' => 'asset',
+ 'assigned_asset' => $target->id,
+ 'redirect_option' => 'target',
+ 'assigned_qty' => 1,
+ ])
+ ->assertStatus(302)
+ ->assertRedirect(route('hardware.show', ['hardware' => $target]));
+ }
+
+ public function testAssetCheckoutPagePostIsRedirectedIfRedirectSelectionIsLocationTarget()
+ {
+ $target = Location::factory()->create();
+ $asset = Asset::factory()->create();
+
+ $this->actingAs(User::factory()->admin()->create())
+ ->from(route('hardware.checkout.create', $asset))
+ ->post(route('hardware.checkout.store' , $asset), [
+ 'checkout_to_type' => 'location',
+ 'assigned_location' => $target->id,
+ 'redirect_option' => 'target',
+ 'assigned_qty' => 1,
+ ])
+ ->assertStatus(302)
+ ->assertRedirect(route('locations.show', ['location' => $target]));
+ }
}