mirror of
https://github.com/snipe/snipe-it.git
synced 2024-11-09 23:24:06 -08:00
Scaffold and implement some tests around accessory checkout
This commit is contained in:
parent
3da7876631
commit
f16f62f76c
|
@ -33,7 +33,7 @@ class AccessoryFactory extends Factory
|
|||
$this->faker->randomElement(['Keyboard', 'Wired'])
|
||||
),
|
||||
'user_id' => User::factory()->superuser(),
|
||||
'category_id' => Category::factory(),
|
||||
'category_id' => Category::factory()->forAccessories(),
|
||||
'model_number' => $this->faker->numberBetween(1000000, 50000000),
|
||||
'location_id' => Location::factory(),
|
||||
'qty' => 1,
|
||||
|
@ -114,4 +114,23 @@ class AccessoryFactory extends Factory
|
|||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function withoutItemsRemaining()
|
||||
{
|
||||
return $this->state(function () {
|
||||
return [
|
||||
'qty' => 1,
|
||||
];
|
||||
})->afterCreating(function ($accessory) {
|
||||
$user = User::factory()->create();
|
||||
|
||||
$accessory->users()->attach($accessory->id, [
|
||||
'accessory_id' => $accessory->id,
|
||||
'created_at' => now(),
|
||||
'user_id' => $user->id,
|
||||
'assigned_to' => $user->id,
|
||||
'note' => '',
|
||||
]);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -172,4 +172,10 @@ class CategoryFactory extends Factory
|
|||
]);
|
||||
}
|
||||
|
||||
public function forAccessories()
|
||||
{
|
||||
return $this->state([
|
||||
'category_type' => 'accessory',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
67
tests/Feature/Checkouts/AccessoryCheckoutTest.php
Normal file
67
tests/Feature/Checkouts/AccessoryCheckoutTest.php
Normal file
|
@ -0,0 +1,67 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Feature\Checkouts;
|
||||
|
||||
use App\Models\Accessory;
|
||||
use App\Models\User;
|
||||
use Tests\Support\InteractsWithSettings;
|
||||
use Tests\TestCase;
|
||||
|
||||
class AccessoryCheckoutTest extends TestCase
|
||||
{
|
||||
use InteractsWithSettings;
|
||||
|
||||
public function testCheckingOutAccessoryRequiresCorrectPermission()
|
||||
{
|
||||
$this->actingAs(User::factory()->create())
|
||||
->post(route('accessories.checkout.store', Accessory::factory()->create()))
|
||||
->assertForbidden();
|
||||
}
|
||||
|
||||
public function testValidation()
|
||||
{
|
||||
$accessory = Accessory::factory()->create();
|
||||
|
||||
$this->actingAs(User::factory()->checkoutAccessories()->create())
|
||||
->post(route('accessories.checkout.store', $accessory), [
|
||||
// missing assigned_to
|
||||
])
|
||||
->assertSessionHas('error');
|
||||
}
|
||||
|
||||
public function testAccessoryMustBeAvailableWhenCheckingOut()
|
||||
{
|
||||
$this->actingAs(User::factory()->checkoutAccessories()->create())
|
||||
->post(route('accessories.checkout.store', Accessory::factory()->withoutItemsRemaining()->create()), [
|
||||
'assigned_to' => User::factory()->create()->id,
|
||||
])
|
||||
->assertSessionHas('error');
|
||||
}
|
||||
|
||||
public function testAccessoryCanBeCheckedOut()
|
||||
{
|
||||
$accessory = Accessory::factory()->create();
|
||||
|
||||
$user = User::factory()->create();
|
||||
|
||||
$this->actingAs(User::factory()->checkoutAccessories()->create())
|
||||
->post(route('accessories.checkout.store', $accessory), [
|
||||
'assigned_to' => $user->id,
|
||||
]);
|
||||
|
||||
$this->assertTrue($accessory->users->contains($user));
|
||||
}
|
||||
|
||||
public function testUserSentEulaUponCheckoutIfAcceptanceRequired()
|
||||
{
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
public function testActionLogCreatedUponCheckout()
|
||||
{
|
||||
$this->markTestIncomplete();
|
||||
|
||||
// check 'note' is saved in action_logs
|
||||
// check 'action_source' is saved in action_logs as gui
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue