snipe-it/tests/api/ApiAssetsCest.php

169 lines
6 KiB
PHP
Raw Normal View History

REST API - Refactoring of routes file, more tests added (#3345) * Toggles the disabled state of auto_increment_prefix To insert a prefix you had to toggle the checkbox, save the settings and reload. With this script it is immediate. Fixes #1390 * Delete asset image: made checkbox more visible Related to #3153 * Added personal-access-token component * Created basic API testing configuration * First version of /components endpoind cest * On-the-fly bearer token generation * Completed testing of PATCH and PUT methods * Added /components/{id}/assets route with tests * Updated route and dataTable in view * Completed test assertion * Added links to assets in ComponentsAssets view * Linked Company in AssetView page * Fixed purchase_cost format expectation in ApiComponentsCest * Refactored api routes file Sorted all prefixes in alphabetical order, removed duplicate routes. For every prefix I placed first Route::resource and then any additional route in a Route::group. Expanded arrays for readability and consistency. Removed useless calls as create and edit everywhere. * Refactored and added one more test to ApiComponentsAssetsCest * Marked one test as incomplete, 404 response should return json * Fixed value expectation * Refactored getToken() * Added API debugging routes * Added more information to ValidationException reporting Now the payload contains the validation errors for each invalid attribute. * /apitests: refactored expectations in component assertions * Created ApiAssetsCest * /apitests: Cleanup in Exceptions/Handler * Reverted change to use * Marked two tests as incomplete, looking for solutions
2017-02-23 16:32:35 -08:00
<?php
use App\Helpers\Helper;
use App\Http\Transformers\AssetsTransformer;
use App\Models\Asset;
use App\Models\Setting;
REST API - Refactoring of routes file, more tests added (#3345) * Toggles the disabled state of auto_increment_prefix To insert a prefix you had to toggle the checkbox, save the settings and reload. With this script it is immediate. Fixes #1390 * Delete asset image: made checkbox more visible Related to #3153 * Added personal-access-token component * Created basic API testing configuration * First version of /components endpoind cest * On-the-fly bearer token generation * Completed testing of PATCH and PUT methods * Added /components/{id}/assets route with tests * Updated route and dataTable in view * Completed test assertion * Added links to assets in ComponentsAssets view * Linked Company in AssetView page * Fixed purchase_cost format expectation in ApiComponentsCest * Refactored api routes file Sorted all prefixes in alphabetical order, removed duplicate routes. For every prefix I placed first Route::resource and then any additional route in a Route::group. Expanded arrays for readability and consistency. Removed useless calls as create and edit everywhere. * Refactored and added one more test to ApiComponentsAssetsCest * Marked one test as incomplete, 404 response should return json * Fixed value expectation * Refactored getToken() * Added API debugging routes * Added more information to ValidationException reporting Now the payload contains the validation errors for each invalid attribute. * /apitests: refactored expectations in component assertions * Created ApiAssetsCest * /apitests: Cleanup in Exceptions/Handler * Reverted change to use * Marked two tests as incomplete, looking for solutions
2017-02-23 16:32:35 -08:00
use Illuminate\Support\Facades\Auth;
class ApiAssetsCest
{
protected $faker;
protected $user;
protected $timeFormat;
REST API - Refactoring of routes file, more tests added (#3345) * Toggles the disabled state of auto_increment_prefix To insert a prefix you had to toggle the checkbox, save the settings and reload. With this script it is immediate. Fixes #1390 * Delete asset image: made checkbox more visible Related to #3153 * Added personal-access-token component * Created basic API testing configuration * First version of /components endpoind cest * On-the-fly bearer token generation * Completed testing of PATCH and PUT methods * Added /components/{id}/assets route with tests * Updated route and dataTable in view * Completed test assertion * Added links to assets in ComponentsAssets view * Linked Company in AssetView page * Fixed purchase_cost format expectation in ApiComponentsCest * Refactored api routes file Sorted all prefixes in alphabetical order, removed duplicate routes. For every prefix I placed first Route::resource and then any additional route in a Route::group. Expanded arrays for readability and consistency. Removed useless calls as create and edit everywhere. * Refactored and added one more test to ApiComponentsAssetsCest * Marked one test as incomplete, 404 response should return json * Fixed value expectation * Refactored getToken() * Added API debugging routes * Added more information to ValidationException reporting Now the payload contains the validation errors for each invalid attribute. * /apitests: refactored expectations in component assertions * Created ApiAssetsCest * /apitests: Cleanup in Exceptions/Handler * Reverted change to use * Marked two tests as incomplete, looking for solutions
2017-02-23 16:32:35 -08:00
public function _before(ApiTester $I)
{
$this->faker = \Faker\Factory::create();
$this->user = \App\Models\User::find(1);
Setting::getSettings()->time_display_format = 'H:i';
REST API - Refactoring of routes file, more tests added (#3345) * Toggles the disabled state of auto_increment_prefix To insert a prefix you had to toggle the checkbox, save the settings and reload. With this script it is immediate. Fixes #1390 * Delete asset image: made checkbox more visible Related to #3153 * Added personal-access-token component * Created basic API testing configuration * First version of /components endpoind cest * On-the-fly bearer token generation * Completed testing of PATCH and PUT methods * Added /components/{id}/assets route with tests * Updated route and dataTable in view * Completed test assertion * Added links to assets in ComponentsAssets view * Linked Company in AssetView page * Fixed purchase_cost format expectation in ApiComponentsCest * Refactored api routes file Sorted all prefixes in alphabetical order, removed duplicate routes. For every prefix I placed first Route::resource and then any additional route in a Route::group. Expanded arrays for readability and consistency. Removed useless calls as create and edit everywhere. * Refactored and added one more test to ApiComponentsAssetsCest * Marked one test as incomplete, 404 response should return json * Fixed value expectation * Refactored getToken() * Added API debugging routes * Added more information to ValidationException reporting Now the payload contains the validation errors for each invalid attribute. * /apitests: refactored expectations in component assertions * Created ApiAssetsCest * /apitests: Cleanup in Exceptions/Handler * Reverted change to use * Marked two tests as incomplete, looking for solutions
2017-02-23 16:32:35 -08:00
$I->amBearerAuthenticated($I->getToken($this->user));
}
/** @test */
public function indexAssets(ApiTester $I)
{
$I->wantTo('Get a list of assets');
// call
$I->sendGET('/hardware?limit=20&sort=id&order=desc');
REST API - Refactoring of routes file, more tests added (#3345) * Toggles the disabled state of auto_increment_prefix To insert a prefix you had to toggle the checkbox, save the settings and reload. With this script it is immediate. Fixes #1390 * Delete asset image: made checkbox more visible Related to #3153 * Added personal-access-token component * Created basic API testing configuration * First version of /components endpoind cest * On-the-fly bearer token generation * Completed testing of PATCH and PUT methods * Added /components/{id}/assets route with tests * Updated route and dataTable in view * Completed test assertion * Added links to assets in ComponentsAssets view * Linked Company in AssetView page * Fixed purchase_cost format expectation in ApiComponentsCest * Refactored api routes file Sorted all prefixes in alphabetical order, removed duplicate routes. For every prefix I placed first Route::resource and then any additional route in a Route::group. Expanded arrays for readability and consistency. Removed useless calls as create and edit everywhere. * Refactored and added one more test to ApiComponentsAssetsCest * Marked one test as incomplete, 404 response should return json * Fixed value expectation * Refactored getToken() * Added API debugging routes * Added more information to ValidationException reporting Now the payload contains the validation errors for each invalid attribute. * /apitests: refactored expectations in component assertions * Created ApiAssetsCest * /apitests: Cleanup in Exceptions/Handler * Reverted change to use * Marked two tests as incomplete, looking for solutions
2017-02-23 16:32:35 -08:00
$I->seeResponseIsJson();
$I->seeResponseCodeIs(200);
// FIXME: This is disabled because the statuslabel join is doing something weird in Api/AssetsController@index
// However, it's hiding other real test errors in other parts of the code, so disabling this for now until we can fix.
// $response = json_decode($I->grabResponse(), true);
REST API - Refactoring of routes file, more tests added (#3345) * Toggles the disabled state of auto_increment_prefix To insert a prefix you had to toggle the checkbox, save the settings and reload. With this script it is immediate. Fixes #1390 * Delete asset image: made checkbox more visible Related to #3153 * Added personal-access-token component * Created basic API testing configuration * First version of /components endpoind cest * On-the-fly bearer token generation * Completed testing of PATCH and PUT methods * Added /components/{id}/assets route with tests * Updated route and dataTable in view * Completed test assertion * Added links to assets in ComponentsAssets view * Linked Company in AssetView page * Fixed purchase_cost format expectation in ApiComponentsCest * Refactored api routes file Sorted all prefixes in alphabetical order, removed duplicate routes. For every prefix I placed first Route::resource and then any additional route in a Route::group. Expanded arrays for readability and consistency. Removed useless calls as create and edit everywhere. * Refactored and added one more test to ApiComponentsAssetsCest * Marked one test as incomplete, 404 response should return json * Fixed value expectation * Refactored getToken() * Added API debugging routes * Added more information to ValidationException reporting Now the payload contains the validation errors for each invalid attribute. * /apitests: refactored expectations in component assertions * Created ApiAssetsCest * /apitests: Cleanup in Exceptions/Handler * Reverted change to use * Marked two tests as incomplete, looking for solutions
2017-02-23 16:32:35 -08:00
// sample verify
// $asset = Asset::orderByDesc('id')->take(20)->get()->first();
//
// $I->seeResponseContainsJson($I->removeTimestamps((new AssetsTransformer)->transformAsset($asset)));
REST API - Refactoring of routes file, more tests added (#3345) * Toggles the disabled state of auto_increment_prefix To insert a prefix you had to toggle the checkbox, save the settings and reload. With this script it is immediate. Fixes #1390 * Delete asset image: made checkbox more visible Related to #3153 * Added personal-access-token component * Created basic API testing configuration * First version of /components endpoind cest * On-the-fly bearer token generation * Completed testing of PATCH and PUT methods * Added /components/{id}/assets route with tests * Updated route and dataTable in view * Completed test assertion * Added links to assets in ComponentsAssets view * Linked Company in AssetView page * Fixed purchase_cost format expectation in ApiComponentsCest * Refactored api routes file Sorted all prefixes in alphabetical order, removed duplicate routes. For every prefix I placed first Route::resource and then any additional route in a Route::group. Expanded arrays for readability and consistency. Removed useless calls as create and edit everywhere. * Refactored and added one more test to ApiComponentsAssetsCest * Marked one test as incomplete, 404 response should return json * Fixed value expectation * Refactored getToken() * Added API debugging routes * Added more information to ValidationException reporting Now the payload contains the validation errors for each invalid attribute. * /apitests: refactored expectations in component assertions * Created ApiAssetsCest * /apitests: Cleanup in Exceptions/Handler * Reverted change to use * Marked two tests as incomplete, looking for solutions
2017-02-23 16:32:35 -08:00
}
/** @test */
public function createAsset(ApiTester $I, $scenario)
{
$I->wantTo('Create a new asset');
2021-06-10 13:17:44 -07:00
$temp_asset = \App\Models\Asset::factory()->laptopMbp()->make([
'asset_tag' => 'Test Asset Tag',
'company_id' => 2,
]);
REST API - Refactoring of routes file, more tests added (#3345) * Toggles the disabled state of auto_increment_prefix To insert a prefix you had to toggle the checkbox, save the settings and reload. With this script it is immediate. Fixes #1390 * Delete asset image: made checkbox more visible Related to #3153 * Added personal-access-token component * Created basic API testing configuration * First version of /components endpoind cest * On-the-fly bearer token generation * Completed testing of PATCH and PUT methods * Added /components/{id}/assets route with tests * Updated route and dataTable in view * Completed test assertion * Added links to assets in ComponentsAssets view * Linked Company in AssetView page * Fixed purchase_cost format expectation in ApiComponentsCest * Refactored api routes file Sorted all prefixes in alphabetical order, removed duplicate routes. For every prefix I placed first Route::resource and then any additional route in a Route::group. Expanded arrays for readability and consistency. Removed useless calls as create and edit everywhere. * Refactored and added one more test to ApiComponentsAssetsCest * Marked one test as incomplete, 404 response should return json * Fixed value expectation * Refactored getToken() * Added API debugging routes * Added more information to ValidationException reporting Now the payload contains the validation errors for each invalid attribute. * /apitests: refactored expectations in component assertions * Created ApiAssetsCest * /apitests: Cleanup in Exceptions/Handler * Reverted change to use * Marked two tests as incomplete, looking for solutions
2017-02-23 16:32:35 -08:00
// setup
$data = [
'asset_tag' => $temp_asset->asset_tag,
REST API - Refactoring of routes file, more tests added (#3345) * Toggles the disabled state of auto_increment_prefix To insert a prefix you had to toggle the checkbox, save the settings and reload. With this script it is immediate. Fixes #1390 * Delete asset image: made checkbox more visible Related to #3153 * Added personal-access-token component * Created basic API testing configuration * First version of /components endpoind cest * On-the-fly bearer token generation * Completed testing of PATCH and PUT methods * Added /components/{id}/assets route with tests * Updated route and dataTable in view * Completed test assertion * Added links to assets in ComponentsAssets view * Linked Company in AssetView page * Fixed purchase_cost format expectation in ApiComponentsCest * Refactored api routes file Sorted all prefixes in alphabetical order, removed duplicate routes. For every prefix I placed first Route::resource and then any additional route in a Route::group. Expanded arrays for readability and consistency. Removed useless calls as create and edit everywhere. * Refactored and added one more test to ApiComponentsAssetsCest * Marked one test as incomplete, 404 response should return json * Fixed value expectation * Refactored getToken() * Added API debugging routes * Added more information to ValidationException reporting Now the payload contains the validation errors for each invalid attribute. * /apitests: refactored expectations in component assertions * Created ApiAssetsCest * /apitests: Cleanup in Exceptions/Handler * Reverted change to use * Marked two tests as incomplete, looking for solutions
2017-02-23 16:32:35 -08:00
'assigned_to' => $temp_asset->assigned_to,
'company_id' => $temp_asset->company->id,
'image' => $temp_asset->image,
'model_id' => $temp_asset->model_id,
'name' => $temp_asset->name,
'notes' => $temp_asset->notes,
'purchase_cost' => $temp_asset->purchase_cost,
'purchase_date' => $temp_asset->purchase_date,
'rtd_location_id' => $temp_asset->rtd_location_id,
'serial' => $temp_asset->serial,
'status_id' => $temp_asset->status_id,
'supplier_id' => $temp_asset->supplier_id,
'warranty_months' => $temp_asset->warranty_months,
];
// create
$I->sendPOST('/hardware', $data);
$I->seeResponseIsJson();
$I->seeResponseCodeIs(200);
}
/** @test */
public function updateAssetWithPatch(ApiTester $I, $scenario)
{
$I->wantTo('Update an asset with PATCH');
// create
2021-06-10 13:17:44 -07:00
$asset = \App\Models\Asset::factory()->laptopMbp()->create([
'company_id' => 2,
'rtd_location_id' => 3,
]);
REST API - Refactoring of routes file, more tests added (#3345) * Toggles the disabled state of auto_increment_prefix To insert a prefix you had to toggle the checkbox, save the settings and reload. With this script it is immediate. Fixes #1390 * Delete asset image: made checkbox more visible Related to #3153 * Added personal-access-token component * Created basic API testing configuration * First version of /components endpoind cest * On-the-fly bearer token generation * Completed testing of PATCH and PUT methods * Added /components/{id}/assets route with tests * Updated route and dataTable in view * Completed test assertion * Added links to assets in ComponentsAssets view * Linked Company in AssetView page * Fixed purchase_cost format expectation in ApiComponentsCest * Refactored api routes file Sorted all prefixes in alphabetical order, removed duplicate routes. For every prefix I placed first Route::resource and then any additional route in a Route::group. Expanded arrays for readability and consistency. Removed useless calls as create and edit everywhere. * Refactored and added one more test to ApiComponentsAssetsCest * Marked one test as incomplete, 404 response should return json * Fixed value expectation * Refactored getToken() * Added API debugging routes * Added more information to ValidationException reporting Now the payload contains the validation errors for each invalid attribute. * /apitests: refactored expectations in component assertions * Created ApiAssetsCest * /apitests: Cleanup in Exceptions/Handler * Reverted change to use * Marked two tests as incomplete, looking for solutions
2017-02-23 16:32:35 -08:00
$I->assertInstanceOf(\App\Models\Asset::class, $asset);
2021-06-10 13:17:44 -07:00
$temp_asset = \App\Models\Asset::factory()->laptopAir()->make([
'company_id' => 3,
'name' => 'updated asset name',
'rtd_location_id' => 1,
]);
REST API - Refactoring of routes file, more tests added (#3345) * Toggles the disabled state of auto_increment_prefix To insert a prefix you had to toggle the checkbox, save the settings and reload. With this script it is immediate. Fixes #1390 * Delete asset image: made checkbox more visible Related to #3153 * Added personal-access-token component * Created basic API testing configuration * First version of /components endpoind cest * On-the-fly bearer token generation * Completed testing of PATCH and PUT methods * Added /components/{id}/assets route with tests * Updated route and dataTable in view * Completed test assertion * Added links to assets in ComponentsAssets view * Linked Company in AssetView page * Fixed purchase_cost format expectation in ApiComponentsCest * Refactored api routes file Sorted all prefixes in alphabetical order, removed duplicate routes. For every prefix I placed first Route::resource and then any additional route in a Route::group. Expanded arrays for readability and consistency. Removed useless calls as create and edit everywhere. * Refactored and added one more test to ApiComponentsAssetsCest * Marked one test as incomplete, 404 response should return json * Fixed value expectation * Refactored getToken() * Added API debugging routes * Added more information to ValidationException reporting Now the payload contains the validation errors for each invalid attribute. * /apitests: refactored expectations in component assertions * Created ApiAssetsCest * /apitests: Cleanup in Exceptions/Handler * Reverted change to use * Marked two tests as incomplete, looking for solutions
2017-02-23 16:32:35 -08:00
$data = [
'asset_tag' => $temp_asset->asset_tag,
REST API - Refactoring of routes file, more tests added (#3345) * Toggles the disabled state of auto_increment_prefix To insert a prefix you had to toggle the checkbox, save the settings and reload. With this script it is immediate. Fixes #1390 * Delete asset image: made checkbox more visible Related to #3153 * Added personal-access-token component * Created basic API testing configuration * First version of /components endpoind cest * On-the-fly bearer token generation * Completed testing of PATCH and PUT methods * Added /components/{id}/assets route with tests * Updated route and dataTable in view * Completed test assertion * Added links to assets in ComponentsAssets view * Linked Company in AssetView page * Fixed purchase_cost format expectation in ApiComponentsCest * Refactored api routes file Sorted all prefixes in alphabetical order, removed duplicate routes. For every prefix I placed first Route::resource and then any additional route in a Route::group. Expanded arrays for readability and consistency. Removed useless calls as create and edit everywhere. * Refactored and added one more test to ApiComponentsAssetsCest * Marked one test as incomplete, 404 response should return json * Fixed value expectation * Refactored getToken() * Added API debugging routes * Added more information to ValidationException reporting Now the payload contains the validation errors for each invalid attribute. * /apitests: refactored expectations in component assertions * Created ApiAssetsCest * /apitests: Cleanup in Exceptions/Handler * Reverted change to use * Marked two tests as incomplete, looking for solutions
2017-02-23 16:32:35 -08:00
'assigned_to' => $temp_asset->assigned_to,
'company_id' => $temp_asset->company->id,
'image' => $temp_asset->image,
'model_id' => $temp_asset->model_id,
'name' => $temp_asset->name,
'notes' => $temp_asset->notes,
'order_number' => $temp_asset->order_number,
REST API - Refactoring of routes file, more tests added (#3345) * Toggles the disabled state of auto_increment_prefix To insert a prefix you had to toggle the checkbox, save the settings and reload. With this script it is immediate. Fixes #1390 * Delete asset image: made checkbox more visible Related to #3153 * Added personal-access-token component * Created basic API testing configuration * First version of /components endpoind cest * On-the-fly bearer token generation * Completed testing of PATCH and PUT methods * Added /components/{id}/assets route with tests * Updated route and dataTable in view * Completed test assertion * Added links to assets in ComponentsAssets view * Linked Company in AssetView page * Fixed purchase_cost format expectation in ApiComponentsCest * Refactored api routes file Sorted all prefixes in alphabetical order, removed duplicate routes. For every prefix I placed first Route::resource and then any additional route in a Route::group. Expanded arrays for readability and consistency. Removed useless calls as create and edit everywhere. * Refactored and added one more test to ApiComponentsAssetsCest * Marked one test as incomplete, 404 response should return json * Fixed value expectation * Refactored getToken() * Added API debugging routes * Added more information to ValidationException reporting Now the payload contains the validation errors for each invalid attribute. * /apitests: refactored expectations in component assertions * Created ApiAssetsCest * /apitests: Cleanup in Exceptions/Handler * Reverted change to use * Marked two tests as incomplete, looking for solutions
2017-02-23 16:32:35 -08:00
'purchase_cost' => $temp_asset->purchase_cost,
'purchase_date' => $temp_asset->purchase_date->format('Y-m-d'),
'rtd_location_id' => $temp_asset->rtd_location_id,
'serial' => $temp_asset->serial,
'status_id' => $temp_asset->status_id,
'supplier_id' => $temp_asset->supplier_id,
'warranty_months' => $temp_asset->warranty_months,
];
$I->assertNotEquals($asset->name, $data['name']);
// update
$I->sendPATCH('/hardware/'.$asset->id, $data);
REST API - Refactoring of routes file, more tests added (#3345) * Toggles the disabled state of auto_increment_prefix To insert a prefix you had to toggle the checkbox, save the settings and reload. With this script it is immediate. Fixes #1390 * Delete asset image: made checkbox more visible Related to #3153 * Added personal-access-token component * Created basic API testing configuration * First version of /components endpoind cest * On-the-fly bearer token generation * Completed testing of PATCH and PUT methods * Added /components/{id}/assets route with tests * Updated route and dataTable in view * Completed test assertion * Added links to assets in ComponentsAssets view * Linked Company in AssetView page * Fixed purchase_cost format expectation in ApiComponentsCest * Refactored api routes file Sorted all prefixes in alphabetical order, removed duplicate routes. For every prefix I placed first Route::resource and then any additional route in a Route::group. Expanded arrays for readability and consistency. Removed useless calls as create and edit everywhere. * Refactored and added one more test to ApiComponentsAssetsCest * Marked one test as incomplete, 404 response should return json * Fixed value expectation * Refactored getToken() * Added API debugging routes * Added more information to ValidationException reporting Now the payload contains the validation errors for each invalid attribute. * /apitests: refactored expectations in component assertions * Created ApiAssetsCest * /apitests: Cleanup in Exceptions/Handler * Reverted change to use * Marked two tests as incomplete, looking for solutions
2017-02-23 16:32:35 -08:00
$I->seeResponseIsJson();
$I->seeResponseCodeIs(200);
$response = json_decode($I->grabResponse());
// dd($response);
REST API - Refactoring of routes file, more tests added (#3345) * Toggles the disabled state of auto_increment_prefix To insert a prefix you had to toggle the checkbox, save the settings and reload. With this script it is immediate. Fixes #1390 * Delete asset image: made checkbox more visible Related to #3153 * Added personal-access-token component * Created basic API testing configuration * First version of /components endpoind cest * On-the-fly bearer token generation * Completed testing of PATCH and PUT methods * Added /components/{id}/assets route with tests * Updated route and dataTable in view * Completed test assertion * Added links to assets in ComponentsAssets view * Linked Company in AssetView page * Fixed purchase_cost format expectation in ApiComponentsCest * Refactored api routes file Sorted all prefixes in alphabetical order, removed duplicate routes. For every prefix I placed first Route::resource and then any additional route in a Route::group. Expanded arrays for readability and consistency. Removed useless calls as create and edit everywhere. * Refactored and added one more test to ApiComponentsAssetsCest * Marked one test as incomplete, 404 response should return json * Fixed value expectation * Refactored getToken() * Added API debugging routes * Added more information to ValidationException reporting Now the payload contains the validation errors for each invalid attribute. * /apitests: refactored expectations in component assertions * Created ApiAssetsCest * /apitests: Cleanup in Exceptions/Handler * Reverted change to use * Marked two tests as incomplete, looking for solutions
2017-02-23 16:32:35 -08:00
$I->assertEquals('success', $response->status);
$I->assertEquals(trans('admin/hardware/message.update.success'), $response->messages);
$I->assertEquals($asset->id, $response->payload->id); // asset id does not change
$I->assertEquals($temp_asset->asset_tag, $response->payload->asset_tag); // asset tag updated
$I->assertEquals($temp_asset->name, $response->payload->name); // asset name updated
$I->assertEquals($temp_asset->rtd_location_id, $response->payload->rtd_location_id); // asset rtd_location_id updated
$temp_asset->created_at = Carbon::parse($response->payload->created_at);
$temp_asset->updated_at = Carbon::parse($response->payload->updated_at);
$temp_asset->id = $asset->id;
$temp_asset->location_id = $response->payload->rtd_location_id;
REST API - Refactoring of routes file, more tests added (#3345) * Toggles the disabled state of auto_increment_prefix To insert a prefix you had to toggle the checkbox, save the settings and reload. With this script it is immediate. Fixes #1390 * Delete asset image: made checkbox more visible Related to #3153 * Added personal-access-token component * Created basic API testing configuration * First version of /components endpoind cest * On-the-fly bearer token generation * Completed testing of PATCH and PUT methods * Added /components/{id}/assets route with tests * Updated route and dataTable in view * Completed test assertion * Added links to assets in ComponentsAssets view * Linked Company in AssetView page * Fixed purchase_cost format expectation in ApiComponentsCest * Refactored api routes file Sorted all prefixes in alphabetical order, removed duplicate routes. For every prefix I placed first Route::resource and then any additional route in a Route::group. Expanded arrays for readability and consistency. Removed useless calls as create and edit everywhere. * Refactored and added one more test to ApiComponentsAssetsCest * Marked one test as incomplete, 404 response should return json * Fixed value expectation * Refactored getToken() * Added API debugging routes * Added more information to ValidationException reporting Now the payload contains the validation errors for each invalid attribute. * /apitests: refactored expectations in component assertions * Created ApiAssetsCest * /apitests: Cleanup in Exceptions/Handler * Reverted change to use * Marked two tests as incomplete, looking for solutions
2017-02-23 16:32:35 -08:00
// verify
$I->sendGET('/hardware/'.$asset->id);
REST API - Refactoring of routes file, more tests added (#3345) * Toggles the disabled state of auto_increment_prefix To insert a prefix you had to toggle the checkbox, save the settings and reload. With this script it is immediate. Fixes #1390 * Delete asset image: made checkbox more visible Related to #3153 * Added personal-access-token component * Created basic API testing configuration * First version of /components endpoind cest * On-the-fly bearer token generation * Completed testing of PATCH and PUT methods * Added /components/{id}/assets route with tests * Updated route and dataTable in view * Completed test assertion * Added links to assets in ComponentsAssets view * Linked Company in AssetView page * Fixed purchase_cost format expectation in ApiComponentsCest * Refactored api routes file Sorted all prefixes in alphabetical order, removed duplicate routes. For every prefix I placed first Route::resource and then any additional route in a Route::group. Expanded arrays for readability and consistency. Removed useless calls as create and edit everywhere. * Refactored and added one more test to ApiComponentsAssetsCest * Marked one test as incomplete, 404 response should return json * Fixed value expectation * Refactored getToken() * Added API debugging routes * Added more information to ValidationException reporting Now the payload contains the validation errors for each invalid attribute. * /apitests: refactored expectations in component assertions * Created ApiAssetsCest * /apitests: Cleanup in Exceptions/Handler * Reverted change to use * Marked two tests as incomplete, looking for solutions
2017-02-23 16:32:35 -08:00
$I->seeResponseIsJson();
$I->seeResponseCodeIs(200);
$I->seeResponseContainsJson((new AssetsTransformer)->transformAsset($temp_asset));
REST API - Refactoring of routes file, more tests added (#3345) * Toggles the disabled state of auto_increment_prefix To insert a prefix you had to toggle the checkbox, save the settings and reload. With this script it is immediate. Fixes #1390 * Delete asset image: made checkbox more visible Related to #3153 * Added personal-access-token component * Created basic API testing configuration * First version of /components endpoind cest * On-the-fly bearer token generation * Completed testing of PATCH and PUT methods * Added /components/{id}/assets route with tests * Updated route and dataTable in view * Completed test assertion * Added links to assets in ComponentsAssets view * Linked Company in AssetView page * Fixed purchase_cost format expectation in ApiComponentsCest * Refactored api routes file Sorted all prefixes in alphabetical order, removed duplicate routes. For every prefix I placed first Route::resource and then any additional route in a Route::group. Expanded arrays for readability and consistency. Removed useless calls as create and edit everywhere. * Refactored and added one more test to ApiComponentsAssetsCest * Marked one test as incomplete, 404 response should return json * Fixed value expectation * Refactored getToken() * Added API debugging routes * Added more information to ValidationException reporting Now the payload contains the validation errors for each invalid attribute. * /apitests: refactored expectations in component assertions * Created ApiAssetsCest * /apitests: Cleanup in Exceptions/Handler * Reverted change to use * Marked two tests as incomplete, looking for solutions
2017-02-23 16:32:35 -08:00
}
/** @test */
public function deleteAssetTest(ApiTester $I, $scenario)
REST API - Refactoring of routes file, more tests added (#3345) * Toggles the disabled state of auto_increment_prefix To insert a prefix you had to toggle the checkbox, save the settings and reload. With this script it is immediate. Fixes #1390 * Delete asset image: made checkbox more visible Related to #3153 * Added personal-access-token component * Created basic API testing configuration * First version of /components endpoind cest * On-the-fly bearer token generation * Completed testing of PATCH and PUT methods * Added /components/{id}/assets route with tests * Updated route and dataTable in view * Completed test assertion * Added links to assets in ComponentsAssets view * Linked Company in AssetView page * Fixed purchase_cost format expectation in ApiComponentsCest * Refactored api routes file Sorted all prefixes in alphabetical order, removed duplicate routes. For every prefix I placed first Route::resource and then any additional route in a Route::group. Expanded arrays for readability and consistency. Removed useless calls as create and edit everywhere. * Refactored and added one more test to ApiComponentsAssetsCest * Marked one test as incomplete, 404 response should return json * Fixed value expectation * Refactored getToken() * Added API debugging routes * Added more information to ValidationException reporting Now the payload contains the validation errors for each invalid attribute. * /apitests: refactored expectations in component assertions * Created ApiAssetsCest * /apitests: Cleanup in Exceptions/Handler * Reverted change to use * Marked two tests as incomplete, looking for solutions
2017-02-23 16:32:35 -08:00
{
$I->wantTo('Delete an asset');
// create
2021-06-10 13:17:44 -07:00
$asset = \App\Models\Asset::factory()->laptopMbp()->create();
REST API - Refactoring of routes file, more tests added (#3345) * Toggles the disabled state of auto_increment_prefix To insert a prefix you had to toggle the checkbox, save the settings and reload. With this script it is immediate. Fixes #1390 * Delete asset image: made checkbox more visible Related to #3153 * Added personal-access-token component * Created basic API testing configuration * First version of /components endpoind cest * On-the-fly bearer token generation * Completed testing of PATCH and PUT methods * Added /components/{id}/assets route with tests * Updated route and dataTable in view * Completed test assertion * Added links to assets in ComponentsAssets view * Linked Company in AssetView page * Fixed purchase_cost format expectation in ApiComponentsCest * Refactored api routes file Sorted all prefixes in alphabetical order, removed duplicate routes. For every prefix I placed first Route::resource and then any additional route in a Route::group. Expanded arrays for readability and consistency. Removed useless calls as create and edit everywhere. * Refactored and added one more test to ApiComponentsAssetsCest * Marked one test as incomplete, 404 response should return json * Fixed value expectation * Refactored getToken() * Added API debugging routes * Added more information to ValidationException reporting Now the payload contains the validation errors for each invalid attribute. * /apitests: refactored expectations in component assertions * Created ApiAssetsCest * /apitests: Cleanup in Exceptions/Handler * Reverted change to use * Marked two tests as incomplete, looking for solutions
2017-02-23 16:32:35 -08:00
$I->assertInstanceOf(\App\Models\Asset::class, $asset);
// delete
$I->sendDELETE('/hardware/'.$asset->id);
REST API - Refactoring of routes file, more tests added (#3345) * Toggles the disabled state of auto_increment_prefix To insert a prefix you had to toggle the checkbox, save the settings and reload. With this script it is immediate. Fixes #1390 * Delete asset image: made checkbox more visible Related to #3153 * Added personal-access-token component * Created basic API testing configuration * First version of /components endpoind cest * On-the-fly bearer token generation * Completed testing of PATCH and PUT methods * Added /components/{id}/assets route with tests * Updated route and dataTable in view * Completed test assertion * Added links to assets in ComponentsAssets view * Linked Company in AssetView page * Fixed purchase_cost format expectation in ApiComponentsCest * Refactored api routes file Sorted all prefixes in alphabetical order, removed duplicate routes. For every prefix I placed first Route::resource and then any additional route in a Route::group. Expanded arrays for readability and consistency. Removed useless calls as create and edit everywhere. * Refactored and added one more test to ApiComponentsAssetsCest * Marked one test as incomplete, 404 response should return json * Fixed value expectation * Refactored getToken() * Added API debugging routes * Added more information to ValidationException reporting Now the payload contains the validation errors for each invalid attribute. * /apitests: refactored expectations in component assertions * Created ApiAssetsCest * /apitests: Cleanup in Exceptions/Handler * Reverted change to use * Marked two tests as incomplete, looking for solutions
2017-02-23 16:32:35 -08:00
$I->seeResponseIsJson();
$I->seeResponseCodeIs(200);
$response = json_decode($I->grabResponse());
$I->assertEquals('success', $response->status);
$I->assertEquals(trans('admin/hardware/message.delete.success'), $response->messages);
// verify, expect a 200
$I->sendGET('/hardware/'.$asset->id);
$I->seeResponseCodeIs(200);
$I->seeResponseIsJson();
// Make sure we're soft deleted.
$response = json_decode($I->grabResponse());
$I->assertNotNull($response->deleted_at);
}
REST API - Refactoring of routes file, more tests added (#3345) * Toggles the disabled state of auto_increment_prefix To insert a prefix you had to toggle the checkbox, save the settings and reload. With this script it is immediate. Fixes #1390 * Delete asset image: made checkbox more visible Related to #3153 * Added personal-access-token component * Created basic API testing configuration * First version of /components endpoind cest * On-the-fly bearer token generation * Completed testing of PATCH and PUT methods * Added /components/{id}/assets route with tests * Updated route and dataTable in view * Completed test assertion * Added links to assets in ComponentsAssets view * Linked Company in AssetView page * Fixed purchase_cost format expectation in ApiComponentsCest * Refactored api routes file Sorted all prefixes in alphabetical order, removed duplicate routes. For every prefix I placed first Route::resource and then any additional route in a Route::group. Expanded arrays for readability and consistency. Removed useless calls as create and edit everywhere. * Refactored and added one more test to ApiComponentsAssetsCest * Marked one test as incomplete, 404 response should return json * Fixed value expectation * Refactored getToken() * Added API debugging routes * Added more information to ValidationException reporting Now the payload contains the validation errors for each invalid attribute. * /apitests: refactored expectations in component assertions * Created ApiAssetsCest * /apitests: Cleanup in Exceptions/Handler * Reverted change to use * Marked two tests as incomplete, looking for solutions
2017-02-23 16:32:35 -08:00
}