And more tests

Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
snipe 2024-07-26 15:07:43 +01:00
parent ddf45c5ee9
commit eceaa72781

View file

@ -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]));
}
}