|
12 | 12 | use App\Models\User; |
13 | 13 | use Illuminate\Support\Facades\Crypt; |
14 | 14 | use Illuminate\Testing\Fluent\AssertableJson; |
| 15 | +use PHPUnit\Framework\Attributes\DataProvider; |
15 | 16 | use Tests\TestCase; |
16 | 17 |
|
17 | 18 | class StoreAssetTest extends TestCase |
@@ -572,6 +573,64 @@ public function testAnAssetCanBeCheckedOutToUserOnStore() |
572 | 573 | $this->assertTrue($asset->assignedTo->is($userAssigned)); |
573 | 574 | } |
574 | 575 |
|
| 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 | + |
575 | 634 | public function testAnAssetCanBeCheckedOutToLocationOnStore() |
576 | 635 | { |
577 | 636 | $model = AssetModel::factory()->create(); |
|
0 commit comments