mirror of
https://github.com/snipe/snipe-it.git
synced 2025-01-11 22:07:29 -08:00
Scaffold and implement some license checkin tests
This commit is contained in:
parent
4bd6c2171c
commit
699476da90
|
@ -63,6 +63,7 @@ class LicenseCheckinController extends Controller
|
|||
$license = License::find($licenseSeat->license_id);
|
||||
|
||||
// LicenseSeat is not assigned, it can't be checked in
|
||||
// @todo:
|
||||
if (is_null($licenseSeat->assigned_to) && is_null($licenseSeat->asset_id)) {
|
||||
return redirect()->route('licenses.index')->with('error', trans('admin/licenses/message.checkin.error'));
|
||||
}
|
||||
|
@ -71,7 +72,7 @@ class LicenseCheckinController extends Controller
|
|||
|
||||
if (! $license->reassignable) {
|
||||
// Not allowed to checkin
|
||||
Session::flash('error', 'License not reassignable.');
|
||||
Session::flash('error', trans('admin/licenses/message.checkin.not_reassignable') . '.');
|
||||
|
||||
return redirect()->back()->withInput();
|
||||
}
|
||||
|
@ -90,12 +91,14 @@ class LicenseCheckinController extends Controller
|
|||
return redirect()->back()->withInput()->withErrors($validator);
|
||||
}
|
||||
|
||||
// @todo:
|
||||
if($licenseSeat->assigned_to != null){
|
||||
$return_to = User::find($licenseSeat->assigned_to);
|
||||
} else {
|
||||
$return_to = Asset::find($licenseSeat->asset_id);
|
||||
}
|
||||
|
||||
// @todo:
|
||||
// Update the asset data
|
||||
$licenseSeat->assigned_to = null;
|
||||
$licenseSeat->asset_id = null;
|
||||
|
@ -106,6 +109,7 @@ class LicenseCheckinController extends Controller
|
|||
|
||||
// Was the asset updated?
|
||||
if ($licenseSeat->save()) {
|
||||
// @todo:
|
||||
event(new CheckoutableCheckedIn($licenseSeat, $return_to, auth()->user(), $request->input('notes')));
|
||||
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ namespace Database\Factories;
|
|||
|
||||
use App\Models\Asset;
|
||||
use App\Models\License;
|
||||
use App\Models\LicenseSeat;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
|
@ -33,4 +34,18 @@ class LicenseSeatFactory extends Factory
|
|||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function reassignable()
|
||||
{
|
||||
return $this->afterCreating(function (LicenseSeat $seat) {
|
||||
$seat->license->update(['reassignable' => true]);
|
||||
});
|
||||
}
|
||||
|
||||
public function notReassignable()
|
||||
{
|
||||
return $this->afterCreating(function (LicenseSeat $seat) {
|
||||
$seat->license->update(['reassignable' => false]);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,6 +50,7 @@ return array(
|
|||
|
||||
'checkin' => array(
|
||||
'error' => 'There was an issue checking in the license. Please try again.',
|
||||
'not_reassignable' => 'License not reassignable',
|
||||
'success' => 'The license was checked in successfully'
|
||||
),
|
||||
|
||||
|
|
|
@ -17,5 +17,60 @@ class LicenseCheckinTest extends TestCase
|
|||
->assertForbidden();
|
||||
}
|
||||
|
||||
public function testCannotCheckinNonReassignableLicense()
|
||||
{
|
||||
$licenseSeat = LicenseSeat::factory()
|
||||
->notReassignable()
|
||||
->assignedToUser()
|
||||
->create();
|
||||
|
||||
$this->actingAs(User::factory()->checkoutLicenses()->create())
|
||||
->post(route('licenses.checkin.save', $licenseSeat), [
|
||||
'notes' => 'my note',
|
||||
'redirect_option' => 'index',
|
||||
])
|
||||
->assertSessionHas('error', trans('admin/licenses/message.checkin.not_reassignable') . '.');
|
||||
|
||||
$this->assertNotNull($licenseSeat->fresh()->assigned_to);
|
||||
}
|
||||
|
||||
public function testCanCheckInLicenseAssignedToAsset()
|
||||
{
|
||||
$licenseSeat = LicenseSeat::factory()
|
||||
->reassignable()
|
||||
->assignedToAsset()
|
||||
->create();
|
||||
|
||||
$this->assertNotNull($licenseSeat->asset_id);
|
||||
|
||||
$this->actingAs(User::factory()->checkoutLicenses()->create())
|
||||
->post(route('licenses.checkin.save', $licenseSeat), [
|
||||
'notes' => 'my note',
|
||||
'redirect_option' => 'index',
|
||||
])
|
||||
->assertRedirect(route('licenses.index'));
|
||||
|
||||
$this->assertNull($licenseSeat->fresh()->asset_id);
|
||||
$this->assertNull($licenseSeat->fresh()->assigned_to);
|
||||
}
|
||||
|
||||
public function testCanCheckInLicenseAssignedToUser()
|
||||
{
|
||||
$licenseSeat = LicenseSeat::factory()
|
||||
->reassignable()
|
||||
->assignedToUser()
|
||||
->create();
|
||||
|
||||
$this->assertNotNull($licenseSeat->assigned_to);
|
||||
|
||||
$this->actingAs(User::factory()->checkoutLicenses()->create())
|
||||
->post(route('licenses.checkin.save', $licenseSeat), [
|
||||
'notes' => 'my note',
|
||||
'redirect_option' => 'index',
|
||||
])
|
||||
->assertRedirect(route('licenses.index'));
|
||||
|
||||
$this->assertNull($licenseSeat->fresh()->asset_id);
|
||||
$this->assertNull($licenseSeat->fresh()->assigned_to);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue