From eceaa72781a05bc6613ad1a866dee84cbcce66ec Mon Sep 17 00:00:00 2001 From: snipe Date: Fri, 26 Jul 2024 15:07:43 +0100 Subject: [PATCH] And more tests Signed-off-by: snipe --- .../Checkouts/Ui/AssetCheckoutTest.php | 80 +++++++++++++++++-- 1 file changed, 73 insertions(+), 7 deletions(-) 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])); + } }