mirror of
https://github.com/snipe/snipe-it.git
synced 2025-01-26 21:21:18 -08:00
Added more tests
Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
parent
037cc4d098
commit
ff100c0b9f
|
@ -83,18 +83,22 @@ class LicenseCheckoutController extends Controller
|
||||||
|
|
||||||
$checkoutMethod = 'checkoutTo'.ucwords(request('checkout_to_type'));
|
$checkoutMethod = 'checkoutTo'.ucwords(request('checkout_to_type'));
|
||||||
|
|
||||||
if (request('checkout_to_type')=='asset') {
|
if ($request->filled('asset_id')) {
|
||||||
|
|
||||||
$checkoutTarget = $this->checkoutToAsset($licenseSeat);
|
$checkoutTarget = $this->checkoutToAsset($licenseSeat);
|
||||||
$request->request->add(['assigned_asset' => $checkoutTarget->id]);
|
$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);
|
$checkoutTarget = $this->checkoutToUser($licenseSeat);
|
||||||
$request->request->add(['assigned_user' => $checkoutTarget->id]);
|
$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) {
|
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'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -56,4 +56,62 @@ class LicenseCheckoutTest extends TestCase
|
||||||
'note' => 'oh hi there',
|
'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]));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue