mirror of
https://github.com/snipe/snipe-it.git
synced 2025-03-05 20:52:15 -08:00
Scaffold api test cases
This commit is contained in:
parent
70934e54cf
commit
7c2fae7b9d
|
@ -823,12 +823,15 @@ class AssetsController extends Controller
|
||||||
|
|
||||||
// This item is checked out to a location
|
// This item is checked out to a location
|
||||||
if (request('checkout_to_type') == 'location') {
|
if (request('checkout_to_type') == 'location') {
|
||||||
|
// @todo: test this
|
||||||
|
dd('asdfasdf');
|
||||||
$target = Location::find(request('assigned_location'));
|
$target = Location::find(request('assigned_location'));
|
||||||
$asset->location_id = ($target) ? $target->id : '';
|
$asset->location_id = ($target) ? $target->id : '';
|
||||||
$error_payload['target_id'] = $request->input('assigned_location');
|
$error_payload['target_id'] = $request->input('assigned_location');
|
||||||
$error_payload['target_type'] = 'location';
|
$error_payload['target_type'] = 'location';
|
||||||
|
|
||||||
} elseif (request('checkout_to_type') == 'asset') {
|
} elseif (request('checkout_to_type') == 'asset') {
|
||||||
|
// @todo: test this
|
||||||
$target = Asset::where('id', '!=', $asset_id)->find(request('assigned_asset'));
|
$target = Asset::where('id', '!=', $asset_id)->find(request('assigned_asset'));
|
||||||
// Override with the asset's location_id if it has one
|
// Override with the asset's location_id if it has one
|
||||||
$asset->location_id = (($target) && (isset($target->location_id))) ? $target->location_id : '';
|
$asset->location_id = (($target) && (isset($target->location_id))) ? $target->location_id : '';
|
||||||
|
@ -836,6 +839,7 @@ class AssetsController extends Controller
|
||||||
$error_payload['target_type'] = 'asset';
|
$error_payload['target_type'] = 'asset';
|
||||||
|
|
||||||
} elseif (request('checkout_to_type') == 'user') {
|
} elseif (request('checkout_to_type') == 'user') {
|
||||||
|
// @todo: test this
|
||||||
// Fetch the target and set the asset's new location_id
|
// Fetch the target and set the asset's new location_id
|
||||||
$target = User::find(request('assigned_user'));
|
$target = User::find(request('assigned_user'));
|
||||||
$asset->location_id = (($target) && (isset($target->location_id))) ? $target->location_id : '';
|
$asset->location_id = (($target) && (isset($target->location_id))) ? $target->location_id : '';
|
||||||
|
@ -844,20 +848,26 @@ class AssetsController extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($request->filled('status_id')) {
|
if ($request->filled('status_id')) {
|
||||||
|
// @todo: test this
|
||||||
$asset->status_id = $request->get('status_id');
|
$asset->status_id = $request->get('status_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (! isset($target)) {
|
if (! isset($target)) {
|
||||||
|
// @todo: test this
|
||||||
return response()->json(Helper::formatStandardApiResponse('error', $error_payload, 'Checkout target for asset '.e($asset->asset_tag).' is invalid - '.$error_payload['target_type'].' does not exist.'));
|
return response()->json(Helper::formatStandardApiResponse('error', $error_payload, 'Checkout target for asset '.e($asset->asset_tag).' is invalid - '.$error_payload['target_type'].' does not exist.'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// @todo: test this
|
||||||
$checkout_at = request('checkout_at', date('Y-m-d H:i:s'));
|
$checkout_at = request('checkout_at', date('Y-m-d H:i:s'));
|
||||||
|
// @todo: test this
|
||||||
$expected_checkin = request('expected_checkin', null);
|
$expected_checkin = request('expected_checkin', null);
|
||||||
|
// @todo: test this
|
||||||
$note = request('note', null);
|
$note = request('note', null);
|
||||||
// Using `->has` preserves the asset name if the name parameter was not included in request.
|
// Using `->has` preserves the asset name if the name parameter was not included in request.
|
||||||
|
// @todo: test this
|
||||||
$asset_name = request()->has('name') ? request('name') : $asset->name;
|
$asset_name = request()->has('name') ? request('name') : $asset->name;
|
||||||
|
|
||||||
// Set the location ID to the RTD location id if there is one
|
// Set the location ID to the RTD location id if there is one
|
||||||
|
|
81
tests/Feature/Api/Assets/AssetCheckoutTest.php
Normal file
81
tests/Feature/Api/Assets/AssetCheckoutTest.php
Normal file
|
@ -0,0 +1,81 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature\Api\Assets;
|
||||||
|
|
||||||
|
use App\Events\CheckoutableCheckedOut;
|
||||||
|
use App\Models\Asset;
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Support\Facades\Event;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class AssetCheckoutTest extends TestCase
|
||||||
|
{
|
||||||
|
|
||||||
|
protected function setUp(): void
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
Event::fake([CheckoutableCheckedOut::class]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCheckingOutAssetRequiresCorrectPermission()
|
||||||
|
{
|
||||||
|
$this->actingAsForApi(User::factory()->create())
|
||||||
|
->postJson(route('api.asset.checkout', Asset::factory()->create()), [
|
||||||
|
'checkout_to_type' => 'user',
|
||||||
|
'assigned_user' => User::factory()->create()->id,
|
||||||
|
])
|
||||||
|
->assertForbidden();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testNonExistentAssetCannotBeCheckedOut()
|
||||||
|
{
|
||||||
|
$this->actingAsForApi(User::factory()->checkoutAssets()->create())
|
||||||
|
->postJson(route('api.asset.checkout', 1000), [
|
||||||
|
'checkout_to_type' => 'user',
|
||||||
|
'assigned_user' => User::factory()->create()->id,
|
||||||
|
])
|
||||||
|
->assertStatusMessageIs('error');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testAssetNotAvailableForCheckoutCannotBeCheckedOut()
|
||||||
|
{
|
||||||
|
$assetAlreadyCheckedOut = Asset::factory()->assignedToUser()->create();
|
||||||
|
|
||||||
|
$this->actingAsForApi(User::factory()->checkoutAssets()->create())
|
||||||
|
->postJson(route('api.asset.checkout', $assetAlreadyCheckedOut), [
|
||||||
|
'checkout_to_type' => 'user',
|
||||||
|
'assigned_user' => User::factory()->create()->id,
|
||||||
|
])
|
||||||
|
->assertStatusMessageIs('error');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testValidationWhenCheckingOutAsset()
|
||||||
|
{
|
||||||
|
$this->actingAsForApi(User::factory()->checkoutAssets()->create())
|
||||||
|
->postJson(route('api.asset.checkout', Asset::factory()->create()), [])
|
||||||
|
->assertStatusMessageIs('error');
|
||||||
|
|
||||||
|
Event::assertNotDispatched(CheckoutableCheckedOut::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCannotCheckoutAcrossCompaniesWhenFullCompanySupportEnabled()
|
||||||
|
{
|
||||||
|
$this->markTestIncomplete('This is not implemented');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testAssetCanBeCheckedOut()
|
||||||
|
{
|
||||||
|
$this->markTestIncomplete();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testLicenseSeatsAreAssignedToUserUponCheckout()
|
||||||
|
{
|
||||||
|
$this->markTestIncomplete('This is not implemented');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testLastCheckoutUsesCurrentDateIfNotProvided()
|
||||||
|
{
|
||||||
|
$this->markTestIncomplete();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue