mirror of
https://github.com/snipe/snipe-it.git
synced 2025-01-11 05:47:28 -08:00
checkout on store tests almost done
This commit is contained in:
parent
15d11f7f4e
commit
c886fb555b
|
@ -20,9 +20,18 @@ class StoreAssetRequest extends ImageUploadRequest
|
|||
|
||||
public function prepareForValidation(): void
|
||||
{
|
||||
if ($this->has('assigned_user')) {
|
||||
$assigned_to = $this->assigned_user;
|
||||
} elseif ($this->has('assigned_location')) {
|
||||
$assigned_to = $this->assigned_location;
|
||||
} elseif ($this->has('assigned_asset')) {
|
||||
$assigned_to = $this->assigned_asset;
|
||||
}
|
||||
|
||||
$this->merge([
|
||||
'asset_tag' => $this->asset_tag ?? Asset::autoincrement_asset(),
|
||||
'company_id' => Company::getIdForCurrentUser($this->company_id),
|
||||
'assigned_to' => $assigned_to ?? null,
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
|
@ -109,7 +109,7 @@ class Asset extends Depreciable
|
|||
'byod' => 'nullable|boolean',
|
||||
'order_number' => 'nullable|string|max:191',
|
||||
'notes' => 'nullable|string|max:65535',
|
||||
'assigned_to' => 'nullable|integer|exists:users,id',
|
||||
'assigned_to' => 'nullable|integer',
|
||||
'requestable' => 'nullable|boolean',
|
||||
];
|
||||
|
||||
|
|
|
@ -253,7 +253,6 @@ class AssetStoreTest extends TestCase
|
|||
$response = $this->actingAsForApi($user)
|
||||
->postJson(route('api.assets.store'), [
|
||||
'assigned_user' => $userAssigned->id,
|
||||
'assigned_to' => $userAssigned->id, // why are both of these needed? documentation says only assigned_user
|
||||
'model_id' => $model->id,
|
||||
'status_id' => $status->id,
|
||||
])
|
||||
|
@ -266,4 +265,54 @@ class AssetStoreTest extends TestCase
|
|||
$this->assertTrue($asset->adminuser->is($user));
|
||||
$this->assertTrue($asset->assignedTo->is($userAssigned));
|
||||
}
|
||||
|
||||
public function testAnAssetCanBeCheckedOutToLocationOnStore()
|
||||
{
|
||||
$model = AssetModel::factory()->create();
|
||||
$status = Statuslabel::factory()->create();
|
||||
$location = Location::factory()->create();
|
||||
$user = User::factory()->createAssets()->create();
|
||||
|
||||
$this->settings->enableAutoIncrement();
|
||||
|
||||
$response = $this->actingAsForApi($user)
|
||||
->postJson(route('api.assets.store'), [
|
||||
'assigned_location' => $location->id,
|
||||
'model_id' => $model->id,
|
||||
'status_id' => $status->id,
|
||||
])
|
||||
->assertOk()
|
||||
->assertStatusMessageIs('success')
|
||||
->json();
|
||||
|
||||
$asset = Asset::find($response['payload']['id']);
|
||||
|
||||
$this->assertTrue($asset->adminuser->is($user));
|
||||
$this->assertTrue($asset->location->is($location));
|
||||
}
|
||||
|
||||
public function testAnAssetCanBeCheckedOutToAssetOnStore()
|
||||
{
|
||||
$model = AssetModel::factory()->create();
|
||||
$status = Statuslabel::factory()->create();
|
||||
$asset = Asset::factory()->create();
|
||||
$user = User::factory()->createAssets()->create();
|
||||
|
||||
$this->settings->enableAutoIncrement();
|
||||
|
||||
$response = $this->actingAsForApi($user)
|
||||
->postJson(route('api.assets.store'), [
|
||||
'assigned_asset' => $asset->id,
|
||||
'model_id' => $model->id,
|
||||
'status_id' => $status->id,
|
||||
])
|
||||
->assertOk()
|
||||
->assertStatusMessageIs('success')
|
||||
->json();
|
||||
|
||||
$apiAsset = Asset::find($response['payload']['id']);
|
||||
|
||||
$this->assertTrue($apiAsset->adminuser->is($user));
|
||||
$this->assertTrue($apiAsset->assignedAssets()->is($asset)); //todo: figure this out
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue