Very basic checkin tests

Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
snipe 2024-07-26 13:16:31 +01:00
parent cd7f276c40
commit e8ec11652f
3 changed files with 58 additions and 0 deletions

View file

@ -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,
]);
});
}
}

View file

@ -0,0 +1,21 @@
<?php
namespace Tests\Feature\Checkins\Ui;
use App\Models\Component;
use App\Models\User;
use Tests\TestCase;
class ComponentCheckinTest extends TestCase
{
public function testCheckingInComponentRequiresCorrectPermission()
{
$this->actingAs(User::factory()->create())
->post(route('components.checkin.store', [
'componentID' => Component::factory()->checkedOutToAsset()->create()->id,
]))
->assertForbidden();
}
}

View file

@ -0,0 +1,21 @@
<?php
namespace Tests\Feature\Checkins\Ui;
use App\Models\LicenseSeat;
use App\Models\User;
use Tests\TestCase;
class LicenseCheckinTest extends TestCase
{
public function testCheckingInLicenseRequiresCorrectPermission()
{
$this->actingAs(User::factory()->create())
->post(route('licenses.checkin.save', [
'licenseId' => LicenseSeat::factory()->assignedToUser()->create()->id,
]))
->assertForbidden();
}
}