Added more tests

Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
snipe 2024-07-26 14:58:10 +01:00
parent 037cc4d098
commit ff100c0b9f
2 changed files with 66 additions and 4 deletions

View file

@ -83,18 +83,22 @@ class LicenseCheckoutController extends Controller
$checkoutMethod = 'checkoutTo'.ucwords(request('checkout_to_type'));
if (request('checkout_to_type')=='asset') {
if ($request->filled('asset_id')) {
$checkoutTarget = $this->checkoutToAsset($licenseSeat);
$request->request->add(['assigned_asset' => $checkoutTarget->id]);
} else {
session()->put(['redirect_option' => $request->get('redirect_option'), 'checkout_to_type' => 'asset']);
} elseif ($request->filled('assigned_to')) {
$checkoutTarget = $this->checkoutToUser($licenseSeat);
$request->request->add(['assigned_user' => $checkoutTarget->id]);
session()->put(['redirect_option' => $request->get('redirect_option'), 'checkout_to_type' => 'user']);
}
session()->put(['redirect_option' => $request->get('redirect_option'), 'checkout_to_type' => $request->get('checkout_to_type')]);
if ($checkoutTarget) {
return redirect()->to(Helper::getRedirectOption($request, $checkoutTarget->id, 'Licenses'))->with('success', trans('admin/licenses/message.checkout.success'));
return redirect()->to(Helper::getRedirectOption($request, $license->id, 'Licenses'))->with('success', trans('admin/licenses/message.checkout.success'));
}

View file

@ -56,4 +56,62 @@ class LicenseCheckoutTest extends TestCase
'note' => 'oh hi there',
]);
}
public function testConsumableCheckoutPagePostIsRedirectedIfRedirectSelectionIsIndex()
{
$license = License::factory()->create();
$this->actingAs(User::factory()->admin()->create())
->from(route('licenses.checkout', ['licenseId' => $license->id]))
->post(route('licenses.checkout', ['licenseId' => $license->id]), [
'assigned_to' => User::factory()->create()->id,
'redirect_option' => 'index',
'assigned_qty' => 1,
])
->assertStatus(302)
->assertRedirect(route('licenses.index'));
}
public function testLicenseCheckoutPagePostIsRedirectedIfRedirectSelectionIsItem()
{
$license = License::factory()->create();
$this->actingAs(User::factory()->admin()->create())
->from(route('licenses.checkout', ['licenseId' => $license->id]))
->post(route('licenses.checkout' , ['licenseId' => $license->id]), [
'assigned_to' => User::factory()->create()->id,
'redirect_option' => 'item',
])
->assertStatus(302)
->assertRedirect(route('licenses.show', ['license' => $license->id]));
}
public function testLicenseCheckoutPagePostIsRedirectedIfRedirectSelectionIsUserTarget()
{
$user = User::factory()->create();
$license = License::factory()->create();
$this->actingAs(User::factory()->admin()->create())
->from(route('licenses.checkout', ['licenseId' => $license->id]))
->post(route('licenses.checkout' , $license), [
'assigned_to' => $user->id,
'redirect_option' => 'target',
])
->assertStatus(302)
->assertRedirect(route('users.show', ['user' => $user->id]));
}
public function testLicenseCheckoutPagePostIsRedirectedIfRedirectSelectionIsAssetTarget()
{
$asset = Asset::factory()->create();
$license = License::factory()->create();
$this->actingAs(User::factory()->admin()->create())
->from(route('licenses.checkout', ['licenseId' => $license->id]))
->post(route('licenses.checkout' , $license), [
'asset_id' => $asset->id,
'redirect_option' => 'target',
])
->assertStatus(302)
->assertRedirect(route('hardware.show', ['hardware' => $asset->id]));
}
}