diff --git a/database/factories/ComponentFactory.php b/database/factories/ComponentFactory.php index caac70078f..2557f29c77 100644 --- a/database/factories/ComponentFactory.php +++ b/database/factories/ComponentFactory.php @@ -2,10 +2,15 @@ namespace Database\Factories; +use App\Models\Accessory; +use App\Models\Asset; use App\Models\Category; use App\Models\Company; use App\Models\Component; +use App\Models\Consumable; use App\Models\Location; +use App\Models\User; +use Carbon\Carbon; use Illuminate\Database\Eloquent\Factories\Factory; use App\Models\Supplier; @@ -97,5 +102,16 @@ class ComponentFactory extends Factory }); } + public function checkedOutToAsset(Asset $asset = null) + { + return $this->afterCreating(function (Component $component) use ($asset) { + $component->assets()->attach($component->id, [ + 'component_id' => $component->id, + 'created_at' => Carbon::now(), + 'user_id' => 1, + 'asset_id' => $asset->id ?? Asset::factory()->create()->id, + ]); + }); + } } diff --git a/tests/Feature/Checkins/Ui/ComponentCheckinTest.php b/tests/Feature/Checkins/Ui/ComponentCheckinTest.php new file mode 100644 index 0000000000..a3fccb6c72 --- /dev/null +++ b/tests/Feature/Checkins/Ui/ComponentCheckinTest.php @@ -0,0 +1,21 @@ +actingAs(User::factory()->create()) + ->post(route('components.checkin.store', [ + 'componentID' => Component::factory()->checkedOutToAsset()->create()->id, + ])) + ->assertForbidden(); + } + + +} diff --git a/tests/Feature/Checkins/Ui/LicenseCheckinTest.php b/tests/Feature/Checkins/Ui/LicenseCheckinTest.php new file mode 100644 index 0000000000..e087cb442d --- /dev/null +++ b/tests/Feature/Checkins/Ui/LicenseCheckinTest.php @@ -0,0 +1,21 @@ +actingAs(User::factory()->create()) + ->post(route('licenses.checkin.save', [ + 'licenseId' => LicenseSeat::factory()->assignedToUser()->create()->id, + ])) + ->assertForbidden(); + } + + +}