2017-02-23 16:32:35 -08:00
|
|
|
<?php
|
|
|
|
|
2018-02-22 21:46:58 -08:00
|
|
|
use App\Models\Setting;
|
2017-02-23 16:32:35 -08:00
|
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
|
|
|
|
class ApiAssetsCest
|
|
|
|
{
|
|
|
|
protected $faker;
|
|
|
|
protected $user;
|
2018-02-22 21:46:58 -08:00
|
|
|
protected $timeFormat;
|
2017-02-23 16:32:35 -08:00
|
|
|
|
|
|
|
public function _before(ApiTester $I)
|
|
|
|
{
|
2018-02-22 21:46:58 -08:00
|
|
|
// $I->setupDatabase();
|
2017-02-23 16:32:35 -08:00
|
|
|
$this->faker = \Faker\Factory::create();
|
|
|
|
$this->user = \App\Models\User::find(1);
|
2018-02-22 21:46:58 -08:00
|
|
|
$this->timeFormat = Setting::getSettings()->date_display_format .' '. Setting::getSettings()->time_display_format;
|
2017-02-23 16:32:35 -08:00
|
|
|
$I->amBearerAuthenticated($I->getToken($this->user));
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @test */
|
|
|
|
public function indexAssets(ApiTester $I)
|
|
|
|
{
|
2017-10-01 12:59:55 -07:00
|
|
|
|
2017-02-23 16:32:35 -08:00
|
|
|
$I->wantTo('Get a list of assets');
|
|
|
|
|
2018-02-22 21:46:58 -08:00
|
|
|
// We rely on the seeded database for this. No need to create new assets.
|
|
|
|
// $assets = factory(\App\Models\Asset::class, 10)->create();
|
2017-02-23 16:32:35 -08:00
|
|
|
|
|
|
|
// call
|
2018-02-22 21:46:58 -08:00
|
|
|
$I->sendGET('/hardware?limit=10');
|
2017-02-23 16:32:35 -08:00
|
|
|
$I->seeResponseIsJson();
|
|
|
|
$I->seeResponseCodeIs(200);
|
|
|
|
|
2018-02-22 21:46:58 -08:00
|
|
|
$response = json_decode($I->grabResponse(), true);
|
2017-02-23 16:32:35 -08:00
|
|
|
// sample verify
|
2018-02-22 21:46:58 -08:00
|
|
|
$asset = App\Models\Asset::orderByDesc('created_at')->first();
|
2017-02-23 16:32:35 -08:00
|
|
|
|
|
|
|
$I->seeResponseContainsJson([
|
2018-02-22 21:46:58 -08:00
|
|
|
|
|
|
|
'id' => (int) $asset->id,
|
|
|
|
'name' => e($asset->name),
|
|
|
|
'asset_tag' => e($asset->asset_tag),
|
|
|
|
'serial' => e($asset->serial),
|
|
|
|
'model' => ($asset->model) ? [
|
|
|
|
'id' => (int) $asset->model->id,
|
|
|
|
'name'=> e($asset->model->name)
|
|
|
|
] : null,
|
|
|
|
'model_number' => ($asset->model) ? e($asset->model->model_number) : null,
|
|
|
|
'status_label' => ($asset->assetstatus) ? [
|
|
|
|
'id' => (int) $asset->assetstatus->id,
|
|
|
|
'name'=> e($asset->assetstatus->name)
|
|
|
|
] : null,
|
|
|
|
'category' => ($asset->model->category) ? [
|
|
|
|
'id' => (int) $asset->model->category->id,
|
|
|
|
'name'=> e($asset->model->category->name)
|
|
|
|
] : null,
|
|
|
|
'manufacturer' => ($asset->model->manufacturer) ? [
|
|
|
|
'id' => (int) $asset->model->manufacturer->id,
|
|
|
|
'name'=> e($asset->model->manufacturer->name)
|
|
|
|
] : null,
|
|
|
|
'supplier' => ($asset->supplier) ? [
|
|
|
|
'id' => (int) $asset->supplier->id,
|
|
|
|
'name'=> e($asset->supplier->name)
|
|
|
|
] : null,
|
|
|
|
'notes' => e($asset->notes),
|
|
|
|
'order_number' => e($asset->order_number),
|
|
|
|
'company' => ($asset->company) ? [
|
|
|
|
'id' => (int) $asset->company->id,
|
|
|
|
'name'=> e($asset->company->name)
|
|
|
|
] : null,
|
|
|
|
'location' => ($asset->location) ? [
|
|
|
|
'id' => (int) $asset->location->id,
|
|
|
|
'name'=> e($asset->location->name)
|
|
|
|
] : null,
|
|
|
|
'rtd_location' => ($asset->defaultLoc) ? [
|
|
|
|
'id' => (int) $asset->defaultLoc->id,
|
|
|
|
'name'=> e($asset->defaultLoc->name)
|
|
|
|
] : null,
|
|
|
|
'image' => ($asset->getImageUrl()) ? $asset->getImageUrl() : null,
|
|
|
|
'assigned_to' => ($asset->assigneduser) ? [
|
|
|
|
'id' => (int) $asset->assigneduser->id,
|
|
|
|
'name' => e($asset->assigneduser->getFullNameAttribute()),
|
|
|
|
'first_name'=> e($asset->assigneduser->first_name),
|
|
|
|
'last_name'=> e($asset->assigneduser->last_name)
|
|
|
|
] : null,
|
|
|
|
'warranty_months' => ($asset->warranty_months > 0) ? e($asset->warranty_months . ' ' . trans('admin/hardware/form.months')) : null,
|
|
|
|
'warranty_expires' => ($asset->warranty_months > 0) ? [
|
|
|
|
'datetime' => $asset->created_at->format('Y-m-d'),
|
|
|
|
'formatted' => $asset->created_at->format('Y-m-d'),
|
|
|
|
] : null,
|
|
|
|
|
|
|
|
// I have no idea why these cause the test to fail. I think it's something about nested json.
|
|
|
|
// 'created_at' => ($asset->created_at) ? [
|
|
|
|
// 'datetime' => $asset->created_at->format('Y-m-d H:i:s'),
|
|
|
|
// 'formatted' => $asset->created_at->format('Y-m-d H:i a'),
|
|
|
|
// ] : null,
|
|
|
|
// 'updated_at' => ($asset->updated_at) ? [
|
|
|
|
// 'datetime' => $asset->updated_at->format('Y-m-d H:i:s'),
|
|
|
|
// 'formatted' => $asset->updated_at->format('Y-m-d H:i a'),
|
|
|
|
// ] : null,
|
|
|
|
// // TODO: Implement last_audit_date and next_audit_date
|
|
|
|
// 'purchase_date' => ($asset->purchase_date) ? [
|
|
|
|
// 'datetime' => $asset->purchase_date->format('Y-m-d'),
|
|
|
|
// 'formatted' => $asset->purchase_date->format('Y-m-d'),
|
|
|
|
// ] : null,
|
|
|
|
// 'last_checkout' => ($asset->last_checkout) ? [
|
|
|
|
// 'datetime' => $asset->last_checkout->format('Y-m-d'),
|
|
|
|
// 'formatted' => $asset->last_checkout->format('Y-m-d'),
|
|
|
|
// ] : null,
|
|
|
|
// 'expected_checkin' => ($asset->created_at) ? [
|
|
|
|
// 'date' => $asset->created_at->format('Y-m-d'),
|
|
|
|
// 'formatted' => $asset->created_at->format('Y-m-d'),
|
|
|
|
// ] : null,
|
|
|
|
'purchase_cost' => (float) $asset->purchase_cost,
|
|
|
|
'user_can_checkout' => (bool) $asset->availableForCheckout(),
|
|
|
|
'available_actions' => [
|
|
|
|
'checkout' => (bool) Gate::allows('checkout', Asset::class),
|
|
|
|
'checkin' => (bool) Gate::allows('checkin', Asset::class),
|
|
|
|
'clone' => (bool) Gate::allows('create', Asset::class),
|
|
|
|
'restore' => (bool) false, // FIXME: when this gets implemented in assetstransformer it should be updated here
|
|
|
|
'update' => (bool) Gate::allows('update', Asset::class),
|
|
|
|
'delete' => (bool) Gate::allows('delete', Asset::class),
|
|
|
|
],
|
2017-02-23 16:32:35 -08:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @test */
|
|
|
|
public function createAsset(ApiTester $I, $scenario)
|
|
|
|
{
|
|
|
|
$I->wantTo('Create a new asset');
|
|
|
|
|
2018-02-22 21:46:58 -08:00
|
|
|
$temp_asset = factory(\App\Models\Asset::class)->states('laptop-mbp')->make([
|
|
|
|
'asset_tag' => "Test Asset Tag",
|
|
|
|
'company_id' => 2
|
|
|
|
]);
|
2017-02-23 16:32:35 -08:00
|
|
|
|
|
|
|
// setup
|
|
|
|
$data = [
|
2017-03-31 13:48:11 -07:00
|
|
|
'asset_tag' => $temp_asset->asset_tag,
|
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');
|
|
|
|
|
2017-03-31 13:48:11 -07:00
|
|
|
// create
|
2018-02-22 21:46:58 -08:00
|
|
|
$asset = factory(\App\Models\Asset::class)->states('laptop-mbp')->create([
|
|
|
|
'company_id' => 2,
|
|
|
|
'rtd_location_id' => 3
|
|
|
|
]);
|
2017-02-23 16:32:35 -08:00
|
|
|
$I->assertInstanceOf(\App\Models\Asset::class, $asset);
|
|
|
|
|
2018-02-22 21:46:58 -08:00
|
|
|
$temp_asset = factory(\App\Models\Asset::class)->states('laptop-air')->make([
|
|
|
|
'company_id' => 3,
|
|
|
|
'name' => "updated asset name",
|
|
|
|
'rtd_location_id' => 1,
|
|
|
|
]);
|
2017-03-31 13:48:11 -07:00
|
|
|
|
2017-02-23 16:32:35 -08:00
|
|
|
$data = [
|
2017-03-31 13:48:11 -07:00
|
|
|
'asset_tag' => $temp_asset->asset_tag,
|
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->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);
|
|
|
|
$I->seeResponseIsJson();
|
|
|
|
$I->seeResponseCodeIs(200);
|
|
|
|
|
|
|
|
$response = json_decode($I->grabResponse());
|
|
|
|
$I->assertEquals('success', $response->status);
|
2017-03-14 08:37:39 -07:00
|
|
|
$I->assertEquals(trans('admin/hardware/message.update.success'), $response->messages);
|
2017-03-31 13:48:11 -07:00
|
|
|
$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
|
2017-02-23 16:32:35 -08:00
|
|
|
|
|
|
|
// verify
|
|
|
|
$I->sendGET('/hardware/' . $asset->id);
|
2018-02-22 21:46:58 -08:00
|
|
|
// dd($I->grabResponse());
|
2017-02-23 16:32:35 -08:00
|
|
|
$I->seeResponseIsJson();
|
|
|
|
$I->seeResponseCodeIs(200);
|
|
|
|
$I->seeResponseContainsJson([
|
2017-03-14 08:37:39 -07:00
|
|
|
'id' => (int) $asset->id,
|
2017-03-31 13:48:11 -07:00
|
|
|
'name' => e($temp_asset->name),
|
|
|
|
'asset_tag' => e($temp_asset->asset_tag),
|
2017-03-14 08:37:39 -07:00
|
|
|
'serial' => e($temp_asset->serial),
|
|
|
|
'model' => ($temp_asset->model) ? [
|
|
|
|
'id' => (int) $temp_asset->model->id,
|
|
|
|
'name'=> e($temp_asset->model->name)
|
|
|
|
] : null,
|
|
|
|
'model_number' => ($temp_asset->model) ? e($temp_asset->model->model_number) : null,
|
|
|
|
'status_label' => ($temp_asset->assetstatus) ? [
|
|
|
|
'id' => (int) $temp_asset->assetstatus->id,
|
2018-02-22 21:46:58 -08:00
|
|
|
'name'=> e($temp_asset->assetstatus->name),
|
|
|
|
'status_type' => $temp_asset->assetstatus->getStatuslabelType(),
|
|
|
|
'status_meta' => $temp_asset->present()->statusMeta
|
2017-03-14 08:37:39 -07:00
|
|
|
] : null,
|
|
|
|
'category' => ($temp_asset->model->category) ? [
|
|
|
|
'id' => (int) $temp_asset->model->category->id,
|
|
|
|
'name'=> e($temp_asset->model->category->name)
|
|
|
|
] : null,
|
|
|
|
'manufacturer' => ($temp_asset->model->manufacturer) ? [
|
|
|
|
'id' => (int) $temp_asset->model->manufacturer->id,
|
|
|
|
'name'=> e($temp_asset->model->manufacturer->name)
|
|
|
|
] : null,
|
|
|
|
'notes' => e($temp_asset->notes),
|
|
|
|
'order_number' => e($asset->order_number),
|
2017-03-31 13:48:11 -07:00
|
|
|
'company' => ($asset->company) ? [
|
2017-03-14 08:37:39 -07:00
|
|
|
'id' => (int) $temp_asset->company->id,
|
|
|
|
'name'=> e($temp_asset->company->name)
|
|
|
|
] : null,
|
2017-03-31 13:48:11 -07:00
|
|
|
'rtd_location' => ($temp_asset->defaultLoc) ? [
|
|
|
|
'id' => (int) $temp_asset->defaultLoc->id,
|
|
|
|
'name'=> e($temp_asset->defaultLoc->name)
|
2017-03-14 08:37:39 -07:00
|
|
|
] : null,
|
2018-02-22 21:46:58 -08:00
|
|
|
'image' => ($temp_asset->getImageUrl()) ? $temp_asset->getImageUrl() : null,
|
2017-03-14 08:37:39 -07:00
|
|
|
'assigned_to' => ($temp_asset->assigneduser) ? [
|
|
|
|
'id' => (int) $temp_asset->assigneduser->id,
|
|
|
|
'name' => e($temp_asset->assigneduser->getFullNameAttribute()),
|
|
|
|
'first_name'=> e($temp_asset->assigneduser->first_name),
|
|
|
|
'last_name'=> e($temp_asset->assigneduser->last_name)
|
|
|
|
] : null,
|
2018-02-22 21:46:58 -08:00
|
|
|
'warranty_months' => ($asset->warranty_months > 0) ? e($asset->warranty_months . ' ' . trans('admin/hardware/form.months')) : null,
|
2017-03-14 08:37:39 -07:00
|
|
|
'warranty_expires' => ($asset->warranty_months > 0) ? [
|
|
|
|
'datetime' => $asset->created_at->format('Y-m-d'),
|
|
|
|
'formatted' => $asset->created_at->format('Y-m-d'),
|
|
|
|
] : null,
|
|
|
|
// 'created_at' => ($asset->created_at) ? [
|
|
|
|
// 'datetime' => $asset->created_at->format('Y-m-d H:i:s'),
|
2018-02-22 21:46:58 -08:00
|
|
|
// 'formatted' => $asset->created_at->format($this->timeFormat),
|
2017-03-14 08:37:39 -07:00
|
|
|
// ] : null,
|
|
|
|
// 'updated_at' => ($asset->updated_at) ? [
|
|
|
|
// 'datetime' => $asset->updated_at->format('Y-m-d H:i:s'),
|
2018-02-22 21:46:58 -08:00
|
|
|
// 'formatted' => $asset->updated_at->format($this->timeFormat),
|
2017-03-14 08:37:39 -07:00
|
|
|
// ] : null,
|
2018-02-22 21:46:58 -08:00
|
|
|
'purchase_date' => ($asset->purchase_date) ? [
|
|
|
|
'date' => $temp_asset->purchase_date->format('Y-m-d'),
|
|
|
|
'formatted' => $temp_asset->purchase_date->format('Y-m-d'),
|
|
|
|
] : null,
|
2017-03-14 08:37:39 -07:00
|
|
|
// 'last_checkout' => ($asset->last_checkout) ? [
|
|
|
|
// 'datetime' => $asset->last_checkout->format('Y-m-d'),
|
|
|
|
// 'formatted' => $asset->last_checkout->format('Y-m-d'),
|
|
|
|
// ] : null,
|
|
|
|
// 'expected_checkin' => ($asset->created_at) ? [
|
|
|
|
// 'date' => $asset->created_at->format('Y-m-d'),
|
|
|
|
// 'formatted' => $asset->created_at->format('Y-m-d'),
|
|
|
|
// ] : null,
|
|
|
|
// 'purchase_cost' => (float) $asset->purchase_cost,
|
|
|
|
'user_can_checkout' => (bool) $temp_asset->availableForCheckout(),
|
|
|
|
'available_actions' => [
|
|
|
|
'checkout' => (bool) Gate::allows('checkout', Asset::class),
|
|
|
|
'checkin' => (bool) Gate::allows('checkin', Asset::class),
|
|
|
|
'update' => (bool) Gate::allows('update', Asset::class),
|
|
|
|
'delete' => (bool) Gate::allows('delete', Asset::class),
|
|
|
|
],
|
2017-02-23 16:32:35 -08:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @test */
|
2017-03-14 08:37:39 -07:00
|
|
|
public function updateAssetWithPut(ApiTester $I)
|
2017-02-23 16:32:35 -08:00
|
|
|
{
|
|
|
|
$I->wantTo('Update a asset with PUT');
|
|
|
|
|
|
|
|
// create
|
2018-02-22 21:46:58 -08:00
|
|
|
$asset = factory(\App\Models\Asset::class)->states('laptop-mbp')->create([
|
|
|
|
'company_id' => 2,
|
|
|
|
'name' => "Original name"
|
|
|
|
]);
|
2017-02-23 16:32:35 -08:00
|
|
|
$I->assertInstanceOf(\App\Models\Asset::class, $asset);
|
|
|
|
|
2018-02-22 21:46:58 -08:00
|
|
|
$temp_asset = factory(\App\Models\Asset::class)->states('laptop-air')->make([
|
|
|
|
'company_id' => 1,
|
|
|
|
'name' => "Updated Name"
|
2017-03-31 13:48:11 -07:00
|
|
|
]);
|
|
|
|
|
|
|
|
$I->assertNotNull($temp_asset->asset_tag);
|
2017-03-14 08:37:39 -07:00
|
|
|
|
2017-02-23 16:32:35 -08:00
|
|
|
$data = [
|
2017-03-31 13:48:11 -07:00
|
|
|
'asset_tag' => $temp_asset->asset_tag,
|
|
|
|
'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->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,
|
2017-02-23 16:32:35 -08:00
|
|
|
];
|
|
|
|
|
|
|
|
$I->assertNotEquals($asset->name, $data['name']);
|
|
|
|
|
|
|
|
// update
|
|
|
|
$I->sendPUT('/hardware/' . $asset->id, $data);
|
|
|
|
$I->seeResponseIsJson();
|
|
|
|
$I->seeResponseCodeIs(200);
|
|
|
|
|
|
|
|
$response = json_decode($I->grabResponse());
|
|
|
|
$I->assertEquals('success', $response->status);
|
2017-03-14 08:37:39 -07:00
|
|
|
$I->assertEquals(trans('admin/hardware/message.update.success'), $response->messages);
|
2017-03-31 13:48:11 -07:00
|
|
|
$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
|
2017-02-23 16:32:35 -08:00
|
|
|
|
|
|
|
// verify
|
|
|
|
$I->sendGET('/hardware/' . $asset->id);
|
|
|
|
$I->seeResponseIsJson();
|
|
|
|
$I->seeResponseCodeIs(200);
|
|
|
|
$I->seeResponseContainsJson([
|
2017-03-14 08:37:39 -07:00
|
|
|
'id' => (int) $asset->id,
|
2017-03-31 13:48:11 -07:00
|
|
|
'name' => e($temp_asset->name),
|
|
|
|
'asset_tag' => e($temp_asset->asset_tag),
|
|
|
|
'serial' => e($temp_asset->serial),
|
|
|
|
'model' => ($temp_asset->model) ? [
|
|
|
|
'id' => (int) $temp_asset->model->id,
|
|
|
|
'name'=> e($temp_asset->model->name)
|
2017-03-14 08:37:39 -07:00
|
|
|
] : null,
|
2017-03-31 13:48:11 -07:00
|
|
|
'model_number' => ($temp_asset->model) ? e($temp_asset->model->model_number) : null,
|
|
|
|
'status_label' => ($temp_asset->assetstatus) ? [
|
|
|
|
'id' => (int) $temp_asset->assetstatus->id,
|
|
|
|
'name'=> e($temp_asset->assetstatus->name)
|
2017-03-14 08:37:39 -07:00
|
|
|
] : null,
|
2017-03-31 13:48:11 -07:00
|
|
|
'category' => ($temp_asset->model->category) ? [
|
|
|
|
'id' => (int) $temp_asset->model->category->id,
|
|
|
|
'name'=> e($temp_asset->model->category->name)
|
2017-03-14 08:37:39 -07:00
|
|
|
] : null,
|
2017-03-31 13:48:11 -07:00
|
|
|
'manufacturer' => ($temp_asset->model->manufacturer) ? [
|
|
|
|
'id' => (int) $temp_asset->model->manufacturer->id,
|
|
|
|
'name'=> e($temp_asset->model->manufacturer->name)
|
2017-03-14 08:37:39 -07:00
|
|
|
] : null,
|
2017-03-31 13:48:11 -07:00
|
|
|
'notes' => e($temp_asset->notes),
|
2017-03-14 08:37:39 -07:00
|
|
|
'order_number' => e($asset->order_number),
|
|
|
|
'company' => ($asset->company) ? [
|
2017-03-31 13:48:11 -07:00
|
|
|
'id' => (int) $temp_asset->company->id,
|
|
|
|
'name'=> e($temp_asset->company->name)
|
2017-03-14 08:37:39 -07:00
|
|
|
] : null,
|
2018-02-22 21:46:58 -08:00
|
|
|
// 'location' => ($temp_asset->location) ? [
|
|
|
|
// 'id' => (int) $temp_asset->location->id,
|
|
|
|
// 'name'=> e($temp_asset->location->name)
|
|
|
|
// ] : null,
|
2017-03-31 13:48:11 -07:00
|
|
|
'rtd_location' => ($temp_asset->defaultLoc) ? [
|
|
|
|
'id' => (int) $temp_asset->defaultLoc->id,
|
|
|
|
'name'=> e($temp_asset->defaultLoc->name)
|
2017-03-14 08:37:39 -07:00
|
|
|
] : null,
|
2018-02-22 21:46:58 -08:00
|
|
|
'image' => ($temp_asset->getImageUrl()) ? $temp_asset->getImageUrl() : null,
|
2017-03-31 13:48:11 -07:00
|
|
|
'assigned_to' => ($temp_asset->assigneduser) ? [
|
|
|
|
'id' => (int) $temp_asset->assigneduser->id,
|
|
|
|
'name' => e($temp_asset->assigneduser->getFullNameAttribute()),
|
|
|
|
'first_name'=> e($temp_asset->assigneduser->first_name),
|
|
|
|
'last_name'=> e($temp_asset->assigneduser->last_name)
|
2017-03-14 08:37:39 -07:00
|
|
|
] : null,
|
2018-02-22 21:46:58 -08:00
|
|
|
'warranty_months' => ($asset->warranty_months > 0) ? e($asset->warranty_months . ' ' . trans('admin/hardware/form.months')) : null,
|
2017-03-14 08:37:39 -07:00
|
|
|
'warranty_expires' => ($asset->warranty_months > 0) ? [
|
|
|
|
'datetime' => $asset->created_at->format('Y-m-d'),
|
|
|
|
'formatted' => $asset->created_at->format('Y-m-d'),
|
|
|
|
] : null,
|
|
|
|
// 'created_at' => ($asset->created_at) ? [
|
|
|
|
// 'datetime' => $asset->created_at->format('Y-m-d H:i:s'),
|
|
|
|
// 'formatted' => $asset->created_at->format('Y-m-d H:i a'),
|
|
|
|
// ] : null,
|
|
|
|
// 'updated_at' => ($asset->updated_at) ? [
|
|
|
|
// 'datetime' => $asset->updated_at->format('Y-m-d H:i:s'),
|
|
|
|
// 'formatted' => $asset->updated_at->format('Y-m-d H:i a'),
|
|
|
|
// ] : null,
|
2018-02-22 21:46:58 -08:00
|
|
|
'purchase_date' => ($asset->purchase_date) ? [
|
|
|
|
'date' => $temp_asset->purchase_date->format('Y-m-d'),
|
|
|
|
'formatted' => $temp_asset->purchase_date->format('Y-m-d'),
|
|
|
|
] : null,
|
2017-03-14 08:37:39 -07:00
|
|
|
// 'last_checkout' => ($asset->last_checkout) ? [
|
|
|
|
// 'datetime' => $asset->last_checkout->format('Y-m-d'),
|
|
|
|
// 'formatted' => $asset->last_checkout->format('Y-m-d'),
|
|
|
|
// ] : null,
|
|
|
|
// 'expected_checkin' => ($asset->created_at) ? [
|
|
|
|
// 'date' => $asset->created_at->format('Y-m-d'),
|
|
|
|
// 'formatted' => $asset->created_at->format('Y-m-d'),
|
|
|
|
// ] : null,
|
|
|
|
// 'purchase_cost' => (float) $asset->purchase_cost,
|
2017-03-31 13:48:11 -07:00
|
|
|
'user_can_checkout' => (bool) $temp_asset->availableForCheckout(),
|
2017-03-14 08:37:39 -07:00
|
|
|
'available_actions' => [
|
|
|
|
'checkout' => (bool) Gate::allows('checkout', Asset::class),
|
|
|
|
'checkin' => (bool) Gate::allows('checkin', Asset::class),
|
|
|
|
'update' => (bool) Gate::allows('update', Asset::class),
|
|
|
|
'delete' => (bool) Gate::allows('delete', Asset::class),
|
|
|
|
],
|
2017-02-23 16:32:35 -08:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @test */
|
2017-03-14 08:37:39 -07:00
|
|
|
public function deleteAssetTest(ApiTester $I, $scenario)
|
2017-02-23 16:32:35 -08:00
|
|
|
{
|
|
|
|
$I->wantTo('Delete an asset');
|
|
|
|
|
|
|
|
// create
|
2018-02-22 21:46:58 -08:00
|
|
|
$asset = factory(\App\Models\Asset::class)->states('laptop-mbp')->create();
|
2017-02-23 16:32:35 -08:00
|
|
|
$I->assertInstanceOf(\App\Models\Asset::class, $asset);
|
|
|
|
|
|
|
|
// delete
|
|
|
|
$I->sendDELETE('/hardware/' . $asset->id);
|
|
|
|
$I->seeResponseIsJson();
|
|
|
|
$I->seeResponseCodeIs(200);
|
|
|
|
|
2017-03-14 08:37:39 -07:00
|
|
|
$response = json_decode($I->grabResponse());
|
|
|
|
$I->assertEquals('success', $response->status);
|
|
|
|
$I->assertEquals(trans('admin/hardware/message.delete.success'), $response->messages);
|
|
|
|
|
|
|
|
// verify, expect a 200
|
2017-02-23 16:32:35 -08:00
|
|
|
$I->sendGET('/hardware/' . $asset->id);
|
2017-03-14 08:37:39 -07:00
|
|
|
$I->seeResponseCodeIs(200);
|
|
|
|
$I->seeResponseIsJson(); // @todo: response is not JSON
|
|
|
|
|
|
|
|
|
|
|
|
// $scenario->incomplete('not found response should be JSON, receiving HTML instead');
|
|
|
|
}
|
2017-02-23 16:32:35 -08:00
|
|
|
}
|