mirror of
https://github.com/snipe/snipe-it.git
synced 2025-02-02 08:21:09 -08:00
Added tests
Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
parent
16ae23dbeb
commit
6c3cafa72f
|
@ -33,18 +33,111 @@ class AccessoryCheckoutTest extends TestCase
|
||||||
->postJson(route('api.accessories.checkout', Accessory::factory()->withoutItemsRemaining()->create()), [
|
->postJson(route('api.accessories.checkout', Accessory::factory()->withoutItemsRemaining()->create()), [
|
||||||
'assigned_to' => User::factory()->create()->id,
|
'assigned_to' => User::factory()->create()->id,
|
||||||
])
|
])
|
||||||
->assertStatusMessageIs('error');
|
->assertOk()
|
||||||
|
->assertStatusMessageIs('error')
|
||||||
|
->assertJson([
|
||||||
|
'messages' => [
|
||||||
|
'assigned_to' => ['The assigned to field must be an integer.'],
|
||||||
|
],
|
||||||
|
])
|
||||||
|
->assertStatus(200)
|
||||||
|
->json();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testAccessoryCanBeCheckedOut()
|
public function testAccessoryCanBeCheckedOut()
|
||||||
{
|
{
|
||||||
$accessory = Accessory::factory()->create();
|
$accessory = Accessory::factory()->create();
|
||||||
$user = User::factory()->create();
|
$user = User::factory()->create();
|
||||||
|
$admin = User::factory()->checkoutAccessories()->create();
|
||||||
|
|
||||||
$this->actingAsForApi(User::factory()->checkoutAccessories()->create())
|
$this->actingAsForApi(User::factory()->checkoutAccessories()->create())
|
||||||
->postJson(route('api.accessories.checkout', $accessory), [
|
->postJson(route('api.accessories.checkout', $accessory), [
|
||||||
'assigned_to' => $user->id,
|
'assigned_to' => $user->id,
|
||||||
]);
|
])
|
||||||
|
->assertOk()
|
||||||
|
->assertStatusMessageIs('success')
|
||||||
|
->assertStatus(200)
|
||||||
|
->assertJson([
|
||||||
|
'messages' => [
|
||||||
|
'assigned_to' => ['Accessory checked out successfully.'],
|
||||||
|
],
|
||||||
|
])
|
||||||
|
->json();
|
||||||
|
|
||||||
|
$this->assertTrue($accessory->users->contains($user));
|
||||||
|
|
||||||
|
$this->assertEquals(
|
||||||
|
1,
|
||||||
|
Actionlog::where([
|
||||||
|
'action_type' => 'checkout',
|
||||||
|
'target_id' => $user->id,
|
||||||
|
'target_type' => User::class,
|
||||||
|
'item_id' => $accessory->id,
|
||||||
|
'item_type' => Accessory::class,
|
||||||
|
'user_id' => $admin->id,
|
||||||
|
'note' => 'oh hi there',
|
||||||
|
])->count(),
|
||||||
|
'Log entry either does not exist or there are more than expected'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testAccessoryCanBeCheckedOutWithQty()
|
||||||
|
{
|
||||||
|
$accessory = Accessory::factory()->create(['qty' => 20]);
|
||||||
|
$user = User::factory()->create();
|
||||||
|
$admin = User::factory()->checkoutAccessories()->create();
|
||||||
|
|
||||||
|
$this->actingAsForApi(User::factory()->checkoutAccessories()->create())
|
||||||
|
->postJson(route('api.accessories.checkout', $accessory), [
|
||||||
|
'assigned_to' => $user->id,
|
||||||
|
'checkout_qty' => 2,
|
||||||
|
])
|
||||||
|
->assertOk()
|
||||||
|
->assertStatusMessageIs('success')
|
||||||
|
->assertStatus(200)
|
||||||
|
->assertJson([
|
||||||
|
'messages' => [
|
||||||
|
'assigned_to' => ['The assigned to field must be an integer.'],
|
||||||
|
],
|
||||||
|
])
|
||||||
|
->json();
|
||||||
|
|
||||||
|
$this->assertTrue($accessory->users->contains($user));
|
||||||
|
|
||||||
|
$this->assertEquals(
|
||||||
|
1,
|
||||||
|
Actionlog::where([
|
||||||
|
'action_type' => 'checkout',
|
||||||
|
'target_id' => $user->id,
|
||||||
|
'target_type' => User::class,
|
||||||
|
'item_id' => $accessory->id,
|
||||||
|
'item_type' => Accessory::class,
|
||||||
|
'user_id' => $admin->id,
|
||||||
|
'note' => 'oh hi there',
|
||||||
|
])->count(),
|
||||||
|
'Log entry either does not exist or there are more than expected'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testAccessoryCannotBeCheckedOutToInvalidUser()
|
||||||
|
{
|
||||||
|
$accessory = Accessory::factory()->create();
|
||||||
|
$user = User::factory()->create();
|
||||||
|
|
||||||
|
$this->actingAsForApi(User::factory()->checkoutAccessories()->create())
|
||||||
|
->postJson(route('api.accessories.checkout', $accessory), [
|
||||||
|
'assigned_to' => 'invalid-user-id',
|
||||||
|
'note' => 'oh hi there',
|
||||||
|
])
|
||||||
|
->assertOk()
|
||||||
|
->assertStatusMessageIs('error')
|
||||||
|
->assertJson([
|
||||||
|
'messages' => [
|
||||||
|
'assigned_to' => ['The assigned to field must be an integer.'],
|
||||||
|
],
|
||||||
|
])
|
||||||
|
->assertStatus(200)
|
||||||
|
->json();
|
||||||
|
|
||||||
$this->assertTrue($accessory->users->contains($user));
|
$this->assertTrue($accessory->users->contains($user));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue