Skip to content

A free open source IT asset/license management system

Added more tests

snipeff100c0b9fea
diff --git a/app/Http/Controllers/Licenses/LicenseCheckoutController.php b/app/Http/Controllers/Licenses/LicenseCheckoutController.php
index f08d33f9de..c08980fc06 100644
--- a/app/Http/Controllers/Licenses/LicenseCheckoutController.php
+++ b/app/Http/Controllers/Licenses/LicenseCheckoutController.php
@@ -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'));
}
diff --git a/tests/Feature/Checkouts/Ui/LicenseCheckoutTest.php b/tests/Feature/Checkouts/Ui/LicenseCheckoutTest.php
index 8e5cd83061..4ab5664db2 100644
--- a/tests/Feature/Checkouts/Ui/LicenseCheckoutTest.php
+++ b/tests/Feature/Checkouts/Ui/LicenseCheckoutTest.php
@@ -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]));
+ }
}