Skip to content

Commit 2a2acf6

Browse files
committed
Add failing test
1 parent 5c7b74e commit 2a2acf6

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

tests/Feature/Assets/Api/StoreAssetTest.php

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use App\Models\User;
1313
use Illuminate\Support\Facades\Crypt;
1414
use Illuminate\Testing\Fluent\AssertableJson;
15+
use PHPUnit\Framework\Attributes\DataProvider;
1516
use Tests\TestCase;
1617

1718
class StoreAssetTest extends TestCase
@@ -572,6 +573,64 @@ public function testAnAssetCanBeCheckedOutToUserOnStore()
572573
$this->assertTrue($asset->assignedTo->is($userAssigned));
573574
}
574575

576+
public static function checkoutTargets()
577+
{
578+
yield 'Users' => [
579+
function () {
580+
return [
581+
'key' => 'assigned_user',
582+
'value' => [
583+
User::factory()->create()->id,
584+
User::factory()->create()->id,
585+
],
586+
];
587+
},
588+
];
589+
590+
yield 'Locations' => [
591+
function () {
592+
return [
593+
'key' => 'assigned_location',
594+
'value' => [
595+
Location::factory()->create()->id,
596+
Location::factory()->create()->id,
597+
],
598+
];
599+
},
600+
];
601+
602+
yield 'Assets' => [
603+
function () {
604+
return [
605+
'key' => 'assigned_asset',
606+
'value' => [
607+
Asset::factory()->create()->id,
608+
Asset::factory()->create()->id,
609+
],
610+
];
611+
},
612+
];
613+
}
614+
615+
/** @link https://app.shortcut.com/grokability/story/29181 */
616+
#[DataProvider('checkoutTargets')]
617+
public function testAssignedFieldValidationCannotBeArray($data)
618+
{
619+
['key' => $key, 'value' => $value] = $data();
620+
621+
$this->actingAsForApi(User::factory()->createAssets()->create())
622+
->postJson(route('api.assets.store'), [
623+
'asset_tag' => '123456',
624+
'model_id' => AssetModel::factory()->create()->id,
625+
'status_id' => Statuslabel::factory()->readyToDeploy()->create()->id,
626+
$key => $value,
627+
])
628+
->assertStatusMessageIs('error')
629+
->assertJson(function (AssertableJson $json) use ($key) {
630+
$json->has("messages.{$key}")->etc();
631+
});
632+
}
633+
575634
public function testAnAssetCanBeCheckedOutToLocationOnStore()
576635
{
577636
$model = AssetModel::factory()->create();

0 commit comments

Comments
 (0)