mirror of
https://github.com/snipe/snipe-it.git
synced 2026-02-05 02:45:39 +00:00
Add failing tests
This commit is contained in:
@ -14,6 +14,72 @@ use Tests\TestCase;
|
||||
|
||||
class AccessoryAcceptanceTest extends TestCase
|
||||
{
|
||||
public function test_can_accept_accessory_checkout()
|
||||
{
|
||||
$assignee = User::factory()->create();
|
||||
$accessory = Accessory::factory()->create();
|
||||
|
||||
$checkoutAcceptance = CheckoutAcceptance::factory()
|
||||
->pending()
|
||||
->for($assignee, 'assignedTo')
|
||||
->for($accessory, 'checkoutable')
|
||||
->create(['qty' => 2]);
|
||||
|
||||
$this->actingAs($assignee)
|
||||
->post(route('account.store-acceptance', $checkoutAcceptance), [
|
||||
'asset_acceptance' => 'accepted',
|
||||
'note' => 'A note here',
|
||||
])
|
||||
->assertRedirect();
|
||||
|
||||
$this->assertNotNull($checkoutAcceptance->refresh()->accepted_at);
|
||||
$this->assertEquals('A note here', $checkoutAcceptance->note);
|
||||
|
||||
$assignee->accessories->contains($accessory);
|
||||
|
||||
$this->assertDatabaseHas('action_logs', [
|
||||
'action_type' => 'accepted',
|
||||
'target_id' => $assignee->id,
|
||||
'target_type' => User::class,
|
||||
'item_id' => $accessory->id,
|
||||
'item_type' => Accessory::class,
|
||||
'qty' => 2,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_can_decline_accessory_checkout()
|
||||
{
|
||||
$assignee = User::factory()->create();
|
||||
$accessory = Accessory::factory()->create();
|
||||
|
||||
$checkoutAcceptance = CheckoutAcceptance::factory()
|
||||
->pending()
|
||||
->for($assignee, 'assignedTo')
|
||||
->for($accessory, 'checkoutable')
|
||||
->create(['qty' => 2]);
|
||||
|
||||
$this->actingAs($assignee)
|
||||
->post(route('account.store-acceptance', $checkoutAcceptance), [
|
||||
'asset_acceptance' => 'declined',
|
||||
'note' => 'A note here',
|
||||
])
|
||||
->assertRedirect();
|
||||
|
||||
$this->assertNotNull($checkoutAcceptance->refresh()->declined_at);
|
||||
$this->assertEquals('A note here', $checkoutAcceptance->note);
|
||||
|
||||
$assignee->accessories->doesntContain($accessory);
|
||||
|
||||
$this->assertDatabaseHas('action_logs', [
|
||||
'action_type' => 'declined',
|
||||
'target_id' => $assignee->id,
|
||||
'target_type' => User::class,
|
||||
'item_id' => $accessory->id,
|
||||
'item_type' => Accessory::class,
|
||||
'qty' => 2,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* This can be absorbed into a bigger test
|
||||
*/
|
||||
|
||||
@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\CheckoutAcceptances\Ui;
|
||||
|
||||
use App\Models\CheckoutAcceptance;
|
||||
use App\Models\Consumable;
|
||||
use App\Models\User;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ConsumableAcceptanceTest extends TestCase
|
||||
{
|
||||
public function test_can_accept_consumable_checkout()
|
||||
{
|
||||
$assignee = User::factory()->create();
|
||||
$consumable = Consumable::factory()->create();
|
||||
|
||||
$checkoutAcceptance = CheckoutAcceptance::factory()
|
||||
->pending()
|
||||
->for($assignee, 'assignedTo')
|
||||
->for($consumable, 'checkoutable')
|
||||
->create(['qty' => 2]);
|
||||
|
||||
$this->actingAs($assignee)
|
||||
->post(route('account.store-acceptance', $checkoutAcceptance), [
|
||||
'asset_acceptance' => 'accepted',
|
||||
'note' => 'A note here',
|
||||
])
|
||||
->assertRedirect();
|
||||
|
||||
$this->assertNotNull($checkoutAcceptance->refresh()->accepted_at);
|
||||
$this->assertEquals('A note here', $checkoutAcceptance->note);
|
||||
|
||||
$assignee->consumables->contains($consumable);
|
||||
|
||||
$this->assertDatabaseHas('action_logs', [
|
||||
'action_type' => 'accepted',
|
||||
'target_id' => $assignee->id,
|
||||
'target_type' => User::class,
|
||||
'item_id' => $consumable->id,
|
||||
'item_type' => Consumable::class,
|
||||
'qty' => 2,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_can_decline_consumable_checkout()
|
||||
{
|
||||
$assignee = User::factory()->create();
|
||||
$consumable = Consumable::factory()->create();
|
||||
|
||||
$checkoutAcceptance = CheckoutAcceptance::factory()
|
||||
->pending()
|
||||
->for($assignee, 'assignedTo')
|
||||
->for($consumable, 'checkoutable')
|
||||
->create(['qty' => 2]);
|
||||
|
||||
$this->actingAs($assignee)
|
||||
->post(route('account.store-acceptance', $checkoutAcceptance), [
|
||||
'asset_acceptance' => 'declined',
|
||||
'note' => 'A note here',
|
||||
])
|
||||
->assertRedirect();
|
||||
|
||||
$this->assertNotNull($checkoutAcceptance->refresh()->declined_at);
|
||||
$this->assertEquals('A note here', $checkoutAcceptance->note);
|
||||
|
||||
$assignee->consumables->doesntContain($consumable);
|
||||
|
||||
$this->assertDatabaseHas('action_logs', [
|
||||
'action_type' => 'declined',
|
||||
'target_id' => $assignee->id,
|
||||
'target_type' => User::class,
|
||||
'item_id' => $consumable->id,
|
||||
'item_type' => Consumable::class,
|
||||
'qty' => 2,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@ -123,6 +123,7 @@ class AccessoryCheckoutTest extends TestCase implements TestsPermissionsRequirem
|
||||
'target_type' => User::class,
|
||||
'item_id' => $accessory->id,
|
||||
'item_type' => Accessory::class,
|
||||
'qty' => 2,
|
||||
'created_by' => $admin->id,
|
||||
])->count(),
|
||||
'Log entry either does not exist or there are more than expected'
|
||||
|
||||
@ -109,7 +109,7 @@ class ComponentCheckoutTest extends TestCase implements TestsFullMultipleCompani
|
||||
$this->actingAsForApi($user)
|
||||
->postJson(route('api.components.checkout', $component->id), [
|
||||
'assigned_to' => $asset->id,
|
||||
'assigned_qty' => 1,
|
||||
'assigned_qty' => 2,
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('action_logs', [
|
||||
@ -120,6 +120,7 @@ class ComponentCheckoutTest extends TestCase implements TestsFullMultipleCompani
|
||||
'location_id' => $location->id,
|
||||
'item_type' => Component::class,
|
||||
'item_id' => $component->id,
|
||||
'qty' => 2,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@ -52,6 +52,27 @@ class ConsumableCheckoutTest extends TestCase
|
||||
$this->assertHasTheseActionLogs($consumable, ['create', 'checkout']);
|
||||
}
|
||||
|
||||
public function testConsumableCanBeCheckedOutWithQuantity()
|
||||
{
|
||||
$consumable = Consumable::factory()->create();
|
||||
$user = User::factory()->create();
|
||||
|
||||
$this->actingAsForApi(User::factory()->checkoutConsumables()->create())
|
||||
->postJson(route('api.consumables.checkout', $consumable), [
|
||||
'assigned_to' => $user->id,
|
||||
'checkout_qty' => 2,
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('action_logs', [
|
||||
'item_type' => Consumable::class,
|
||||
'item_id' => $consumable->id,
|
||||
'target_type' => User::class,
|
||||
'target_id' => $user->id,
|
||||
'action_type' => 'checkout',
|
||||
'qty' => 2,
|
||||
]);
|
||||
}
|
||||
|
||||
public function testUserSentNotificationUponCheckout()
|
||||
{
|
||||
Mail::fake();
|
||||
|
||||
@ -81,6 +81,7 @@ class AccessoryCheckoutTest extends TestCase
|
||||
'target_type' => User::class,
|
||||
'item_id' => $accessory->id,
|
||||
'item_type' => Accessory::class,
|
||||
'qty' => 1,
|
||||
'note' => 'oh hi there',
|
||||
]);
|
||||
$this->assertHasTheseActionLogs($accessory, ['create', 'checkout']);
|
||||
@ -108,6 +109,7 @@ class AccessoryCheckoutTest extends TestCase
|
||||
'target_type' => User::class,
|
||||
'item_id' => $accessory->id,
|
||||
'item_type' => Accessory::class,
|
||||
'qty' => 3,
|
||||
'note' => 'oh hi there',
|
||||
]);
|
||||
$this->assertHasTheseActionLogs($accessory, ['create', 'checkout']);
|
||||
@ -135,6 +137,7 @@ class AccessoryCheckoutTest extends TestCase
|
||||
'target_type' => Location::class,
|
||||
'item_id' => $accessory->id,
|
||||
'item_type' => Accessory::class,
|
||||
'qty' => 3,
|
||||
'note' => 'oh hi there',
|
||||
]);
|
||||
$this->assertHasTheseActionLogs($accessory, ['create', 'checkout']);
|
||||
@ -162,6 +165,7 @@ class AccessoryCheckoutTest extends TestCase
|
||||
'target_type' => Asset::class,
|
||||
'item_id' => $accessory->id,
|
||||
'item_type' => Accessory::class,
|
||||
'qty' => 3,
|
||||
'note' => 'oh hi there',
|
||||
]);
|
||||
$this->assertHasTheseActionLogs($accessory, ['create', 'checkout']);
|
||||
|
||||
@ -97,4 +97,30 @@ class ComponentsCheckoutTest extends TestCase
|
||||
->assertRedirect(route('hardware.show', $asset));
|
||||
$this->assertHasTheseActionLogs($component, ['create', 'checkout']);
|
||||
}
|
||||
|
||||
public function test_quantity_stored_in_action_log()
|
||||
{
|
||||
$component = Component::factory()->create();
|
||||
$asset = Asset::factory()->create();
|
||||
|
||||
$admin = User::factory()->admin()->create();
|
||||
|
||||
$this->actingAs($admin)
|
||||
->from(route('components.index'))
|
||||
->post(route('components.checkout.store', $component), [
|
||||
'asset_id' => $asset->id,
|
||||
'redirect_option' => 'index',
|
||||
'assigned_qty' => 2,
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('action_logs', [
|
||||
'action_type' => 'checkout',
|
||||
'target_id' => $asset->id,
|
||||
'target_type' => Asset::class,
|
||||
'item_id' => $component->id,
|
||||
'item_type' => Component::class,
|
||||
'qty' => 2,
|
||||
'created_by' => $admin->id,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -150,4 +150,29 @@ class ConsumableCheckoutTest extends TestCase
|
||||
->assertRedirect(route('users.show', $user));
|
||||
}
|
||||
|
||||
public function test_quantity_stored_in_action_log()
|
||||
{
|
||||
$consumable = Consumable::factory()->create();
|
||||
$user = User::factory()->create();
|
||||
|
||||
$admin = User::factory()->admin()->create();
|
||||
|
||||
$this->actingAs($admin)
|
||||
->from(route('components.index'))
|
||||
->post(route('consumables.checkout.store', $consumable), [
|
||||
'assigned_to' => $user->id,
|
||||
'redirect_option' => 'target',
|
||||
'assigned_qty' => 2,
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('action_logs', [
|
||||
'action_type' => 'checkout',
|
||||
'target_id' => $user->id,
|
||||
'target_type' => User::class,
|
||||
'item_id' => $consumable->id,
|
||||
'item_type' => Consumable::class,
|
||||
'qty' => 2,
|
||||
'created_by' => $admin->id,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user