Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions app/Models/Asset.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ public function declinedCheckout(User $declinedBy, $signature)
'assigned_to' => ['nullable', 'integer', 'required_with:assigned_type'],
'assigned_type' => ['nullable', 'required_with:assigned_to', 'in:'.User::class.",".Location::class.",".Asset::class],
'requestable' => ['nullable', 'boolean'],
'assigned_user' => ['nullable', 'exists:users,id,deleted_at,NULL'],
'assigned_location' => ['nullable', 'exists:locations,id,deleted_at,NULL', 'fmcs_location'],
'assigned_asset' => ['nullable', 'exists:assets,id,deleted_at,NULL']
'assigned_user' => ['integer', 'nullable', 'exists:users,id,deleted_at,NULL'],
'assigned_location' => ['integer', 'nullable', 'exists:locations,id,deleted_at,NULL', 'fmcs_location'],
'assigned_asset' => ['integer', 'nullable', 'exists:assets,id,deleted_at,NULL']
];


Expand Down
59 changes: 59 additions & 0 deletions tests/Feature/Assets/Api/StoreAssetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use App\Models\User;
use Illuminate\Support\Facades\Crypt;
use Illuminate\Testing\Fluent\AssertableJson;
use PHPUnit\Framework\Attributes\DataProvider;
use Tests\TestCase;

class StoreAssetTest extends TestCase
Expand Down Expand Up @@ -572,6 +573,64 @@ public function testAnAssetCanBeCheckedOutToUserOnStore()
$this->assertTrue($asset->assignedTo->is($userAssigned));
}

public static function checkoutTargets()
{
yield 'Users' => [
function () {
return [
'key' => 'assigned_user',
'value' => [
User::factory()->create()->id,
User::factory()->create()->id,
],
];
},
];

yield 'Locations' => [
function () {
return [
'key' => 'assigned_location',
'value' => [
Location::factory()->create()->id,
Location::factory()->create()->id,
],
];
},
];

yield 'Assets' => [
function () {
return [
'key' => 'assigned_asset',
'value' => [
Asset::factory()->create()->id,
Asset::factory()->create()->id,
],
];
},
];
}

/** @link https://app.shortcut.com/grokability/story/29181 */
#[DataProvider('checkoutTargets')]
public function testAssignedFieldValidationCannotBeArray($data)
{
['key' => $key, 'value' => $value] = $data();

$this->actingAsForApi(User::factory()->createAssets()->create())
->postJson(route('api.assets.store'), [
'asset_tag' => '123456',
'model_id' => AssetModel::factory()->create()->id,
'status_id' => Statuslabel::factory()->readyToDeploy()->create()->id,
$key => $value,
])
->assertStatusMessageIs('error')
->assertJson(function (AssertableJson $json) use ($key) {
$json->has("messages.{$key}")->etc();
});
}

public function testAnAssetCanBeCheckedOutToLocationOnStore()
{
$model = AssetModel::factory()->create();
Expand Down
Loading