mirror of
https://github.com/snipe/snipe-it.git
synced 2024-11-11 08:04:09 -08:00
7de8f71f58
* Use the formated date helper to clean up verifications. * Add Checkin/Checkout api tests. * Accessories api test * Add Companies API Test. * Return ModelNotFound as a 404. * Cleanups/simplficiations/updates. * Locations api test. * currency and image should be fillable on location. * Update components api test. * Use findOrFail so we return a 404 instead of a 200. Matches other item types. * order_number should be fillable in component. * Add updated_at and permissions to information returned from api for a user. * Add users test and flesh out factory and fillable fields. * Add test for assets method * API status label test. * Disable php7.2 for now on travis until the count(null) issues are remedied * Add serial to update. * API model not found should return a 200
142 lines
4.8 KiB
PHP
142 lines
4.8 KiB
PHP
<?php
|
|
|
|
use App\Exceptions\CheckoutNotAllowed;
|
|
use App\Helpers\Helper;
|
|
use App\Models\Asset;
|
|
use App\Models\Setting;
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
class ApiCheckoutAssetsCest
|
|
{
|
|
protected $faker;
|
|
protected $user;
|
|
protected $timeFormat;
|
|
|
|
public function _before(ApiTester $I)
|
|
{
|
|
$this->user = \App\Models\User::find(1);
|
|
$I->amBearerAuthenticated($I->getToken($this->user));
|
|
}
|
|
|
|
/** @test */
|
|
public function checkoutAssetToUser(ApiTester $I) {
|
|
$I->wantTo('Check out an asset to a user');
|
|
//Grab an asset from the database that isn't checked out.
|
|
$asset = Asset::whereNull('assigned_to')->first();
|
|
$targetUser = factory('App\Models\User')->create();
|
|
$data = [
|
|
'assigned_user' => $targetUser->id,
|
|
'note' => "This is a test checkout note",
|
|
'expected_checkin' => "2018-05-24",
|
|
'name' => "Updated Asset Name",
|
|
'checkout_to_type' => 'user'
|
|
];
|
|
$I->sendPOST("/hardware/{$asset->id}/checkout", $data);
|
|
$I->seeResponseIsJson();
|
|
$I->seeResponseCodeIs(200);
|
|
|
|
$response = json_decode($I->grabResponse());
|
|
$I->assertEquals('success', $response->status);
|
|
$I->assertEquals(trans('admin/hardware/message.checkout.success'), $response->messages);
|
|
|
|
// Confirm results.
|
|
$I->sendGET("/hardware/{$asset->id}");
|
|
$I->seeResponseContainsJson([
|
|
'assigned_to' => [
|
|
'id' => $targetUser->id,
|
|
'type' => 'user'
|
|
],
|
|
'name' => "Updated Asset Name",
|
|
'expected_checkin' => Helper::getFormattedDateObject('2018-05-24', 'date')
|
|
]);
|
|
|
|
}
|
|
|
|
/** @test */
|
|
public function checkoutAssetToAsset(ApiTester $I) {
|
|
$I->wantTo('Check out an asset to an asset');
|
|
//Grab an asset from the database that isn't checked out.
|
|
$asset = Asset::whereNull('assigned_to')->where('model_id',8)->first(); // We need to make sure that this is an asset/model that doesn't require acceptance
|
|
$targetAsset = factory('App\Models\Asset')->states('desktop-macpro')->create([
|
|
'name' => "Test Asset For Checkout to"
|
|
]);
|
|
// dd($targetAsset->model->category);
|
|
$data = [
|
|
'assigned_asset' => $targetAsset->id,
|
|
'checkout_to_type' => 'asset'
|
|
];
|
|
$I->sendPOST("/hardware/{$asset->id}/checkout", $data);
|
|
$I->seeResponseIsJson();
|
|
$I->seeResponseCodeIs(200);
|
|
|
|
$response = json_decode($I->grabResponse());
|
|
$I->assertEquals('success', $response->status);
|
|
$I->assertEquals(trans('admin/hardware/message.checkout.success'), $response->messages);
|
|
|
|
// Confirm results.
|
|
$I->sendGET("/hardware/{$asset->id}");
|
|
$I->seeResponseContainsJson([
|
|
'assigned_to' => [
|
|
'id' => $targetAsset->id,
|
|
'type' => 'asset'
|
|
]
|
|
]);
|
|
|
|
}
|
|
|
|
/** @test */
|
|
public function checkoutAssetToLocation(ApiTester $I) {
|
|
$I->wantTo('Check out an asset to an asset');
|
|
//Grab an asset from the database that isn't checked out.
|
|
$asset = Asset::whereNull('assigned_to')->where('model_id',8)->first();
|
|
$targetLocation = factory('App\Models\Location')->create([
|
|
'name' => "Test Location for Checkout"
|
|
]);
|
|
// dd($targetAsset->model->category);
|
|
$data = [
|
|
'assigned_location' => $targetLocation->id,
|
|
'checkout_to_type' => 'location'
|
|
];
|
|
$I->sendPOST("/hardware/{$asset->id}/checkout", $data);
|
|
$I->seeResponseIsJson();
|
|
$I->seeResponseCodeIs(200);
|
|
|
|
$response = json_decode($I->grabResponse());
|
|
$I->assertEquals('success', $response->status);
|
|
$I->assertEquals(trans('admin/hardware/message.checkout.success'), $response->messages);
|
|
|
|
// Confirm results.
|
|
$I->sendGET("/hardware/{$asset->id}");
|
|
$I->seeResponseContainsJson([
|
|
'assigned_to' => [
|
|
'id' => $targetLocation->id,
|
|
'type' => 'location'
|
|
]
|
|
]);
|
|
|
|
}
|
|
|
|
/** @test */
|
|
public function checkinAsset(ApiTester $I) {
|
|
$I->wantTo('Checkin an asset that is currently checked out');
|
|
|
|
$asset = Asset::whereNotNull('assigned_to')->first();
|
|
|
|
$I->sendPOST("/hardware/{$asset->id}/checkin", [
|
|
"note" => "Checkin Note"
|
|
]);
|
|
$I->seeResponseIsJson();
|
|
$I->seeResponseCodeIs(200);
|
|
|
|
$response = json_decode($I->grabResponse());
|
|
$I->assertEquals('success', $response->status);
|
|
$I->assertEquals(trans('admin/hardware/message.checkin.success'), $response->messages);
|
|
|
|
// Verify
|
|
$I->sendGET("/hardware/{$asset->id}");
|
|
$I->seeResponseContainsJson([
|
|
'assigned_to' => null
|
|
]);
|
|
}
|
|
}
|