Merge pull request #15185 from arne-kroeger/feat/accesspories-checkout-to-location-or-asset
Added #14979: add checkout to location and assets functionality to accessories
This commit is contained in:
@@ -17,7 +17,7 @@ class AccessoryCheckinTest extends TestCase
|
||||
$accessory = Accessory::factory()->checkedOutToUser()->create();
|
||||
|
||||
$this->actingAs(User::factory()->create())
|
||||
->post(route('accessories.checkin.store', $accessory->users->first()->pivot->id))
|
||||
->post(route('accessories.checkin.store', $accessory->checkouts->first()->id))
|
||||
->assertForbidden();
|
||||
}
|
||||
|
||||
@@ -28,12 +28,12 @@ class AccessoryCheckinTest extends TestCase
|
||||
$user = User::factory()->create();
|
||||
$accessory = Accessory::factory()->checkedOutToUser($user)->create();
|
||||
|
||||
$this->assertTrue($accessory->users->contains($user));
|
||||
$this->assertTrue($accessory->checkouts()->where('assigned_type', User::class)->where('assigned_to', $user->id)->count() > 0);
|
||||
|
||||
$this->actingAs(User::factory()->checkinAccessories()->create())
|
||||
->post(route('accessories.checkin.store', $accessory->users->first()->pivot->id));
|
||||
->post(route('accessories.checkin.store', $accessory->checkouts->first()->id));
|
||||
|
||||
$this->assertFalse($accessory->fresh()->users->contains($user));
|
||||
$this->assertFalse($accessory->fresh()->checkouts()->where('assigned_type', User::class)->where('assigned_to', $user->id)->count() > 0);
|
||||
|
||||
Event::assertDispatched(CheckoutableCheckedIn::class, 1);
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ class AccessoryCheckoutTest extends TestCase
|
||||
{
|
||||
$this->actingAsForApi(User::factory()->checkoutAccessories()->create())
|
||||
->postJson(route('api.accessories.checkout', Accessory::factory()->create()), [
|
||||
// missing assigned_to
|
||||
// missing assigned_user, assigned_location, assigned_asset
|
||||
])
|
||||
->assertStatusMessageIs('error');
|
||||
}
|
||||
@@ -31,7 +31,8 @@ class AccessoryCheckoutTest extends TestCase
|
||||
{
|
||||
$this->actingAsForApi(User::factory()->checkoutAccessories()->create())
|
||||
->postJson(route('api.accessories.checkout', Accessory::factory()->withoutItemsRemaining()->create()), [
|
||||
'assigned_to' => User::factory()->create()->id,
|
||||
'assigned_user' => User::factory()->create()->id,
|
||||
'checkout_to_type' => 'user'
|
||||
])
|
||||
->assertOk()
|
||||
->assertStatusMessageIs('error')
|
||||
@@ -65,7 +66,8 @@ class AccessoryCheckoutTest extends TestCase
|
||||
|
||||
$this->actingAsForApi($admin)
|
||||
->postJson(route('api.accessories.checkout', $accessory), [
|
||||
'assigned_to' => $user->id,
|
||||
'assigned_user' => $user->id,
|
||||
'checkout_to_type' => 'user'
|
||||
])
|
||||
->assertOk()
|
||||
->assertStatusMessageIs('success')
|
||||
@@ -73,7 +75,7 @@ class AccessoryCheckoutTest extends TestCase
|
||||
->assertJson(['messages' => trans('admin/accessories/message.checkout.success')])
|
||||
->json();
|
||||
|
||||
$this->assertTrue($accessory->users->contains($user));
|
||||
$this->assertTrue($accessory->checkouts()->where('assigned_type', User::class)->where('assigned_to', $user->id)->count() > 0);
|
||||
|
||||
$this->assertEquals(
|
||||
1,
|
||||
@@ -96,7 +98,8 @@ class AccessoryCheckoutTest extends TestCase
|
||||
|
||||
$this->actingAsForApi($admin)
|
||||
->postJson(route('api.accessories.checkout', $accessory), [
|
||||
'assigned_to' => $user->id,
|
||||
'assigned_user' => $user->id,
|
||||
'checkout_to_type' => 'user',
|
||||
'checkout_qty' => 2,
|
||||
])
|
||||
->assertOk()
|
||||
@@ -105,7 +108,7 @@ class AccessoryCheckoutTest extends TestCase
|
||||
->assertJson(['messages' => trans('admin/accessories/message.checkout.success')])
|
||||
->json();
|
||||
|
||||
$this->assertTrue($accessory->users->contains($user));
|
||||
$this->assertTrue($accessory->checkouts()->where('assigned_type', User::class)->where('assigned_to', $user->id)->count() > 0);
|
||||
|
||||
$this->assertEquals(
|
||||
1,
|
||||
@@ -128,7 +131,8 @@ class AccessoryCheckoutTest extends TestCase
|
||||
|
||||
$this->actingAsForApi(User::factory()->checkoutAccessories()->create())
|
||||
->postJson(route('api.accessories.checkout', $accessory), [
|
||||
'assigned_to' => 'invalid-user-id',
|
||||
'assigned_user' => 'invalid-user-id',
|
||||
'checkout_to_type' => 'user',
|
||||
'note' => 'oh hi there',
|
||||
])
|
||||
->assertOk()
|
||||
@@ -136,7 +140,7 @@ class AccessoryCheckoutTest extends TestCase
|
||||
->assertStatus(200)
|
||||
->json();
|
||||
|
||||
$this->assertFalse($accessory->users->contains($user));
|
||||
$this->assertFalse($accessory->checkouts()->where('assigned_type', User::class)->where('assigned_to', $user->id)->count() > 0);
|
||||
}
|
||||
|
||||
public function testUserSentNotificationUponCheckout()
|
||||
@@ -148,7 +152,8 @@ class AccessoryCheckoutTest extends TestCase
|
||||
|
||||
$this->actingAsForApi(User::factory()->checkoutAccessories()->create())
|
||||
->postJson(route('api.accessories.checkout', $accessory), [
|
||||
'assigned_to' => $user->id,
|
||||
'assigned_user' => $user->id,
|
||||
'checkout_to_type' => 'user',
|
||||
]);
|
||||
|
||||
Notification::assertSentTo($user, CheckoutAccessoryNotification::class);
|
||||
@@ -162,7 +167,8 @@ class AccessoryCheckoutTest extends TestCase
|
||||
|
||||
$this->actingAsForApi($actor)
|
||||
->postJson(route('api.accessories.checkout', $accessory), [
|
||||
'assigned_to' => $user->id,
|
||||
'assigned_user' => $user->id,
|
||||
'checkout_to_type' => 'user',
|
||||
'note' => 'oh hi there',
|
||||
]);
|
||||
|
||||
|
||||
@@ -4,6 +4,8 @@ namespace Tests\Feature\Checkouts\Ui;
|
||||
|
||||
use App\Models\Accessory;
|
||||
use App\Models\Actionlog;
|
||||
use App\Models\Asset;
|
||||
use App\Models\Location;
|
||||
use App\Models\User;
|
||||
use App\Notifications\CheckoutAccessoryNotification;
|
||||
use Illuminate\Support\Facades\Notification;
|
||||
@@ -40,7 +42,8 @@ class AccessoryCheckoutTest extends TestCase
|
||||
$response = $this->actingAs(User::factory()->viewAccessories()->checkoutAccessories()->create())
|
||||
->from(route('accessories.checkout.show', $accessory))
|
||||
->post(route('accessories.checkout.store', $accessory), [
|
||||
'assigned_to' => User::factory()->create()->id,
|
||||
'assigned_user' => User::factory()->create()->id,
|
||||
'checkout_to_type' => 'user',
|
||||
])
|
||||
->assertStatus(302)
|
||||
->assertSessionHas('errors')
|
||||
@@ -56,11 +59,12 @@ class AccessoryCheckoutTest extends TestCase
|
||||
|
||||
$this->actingAs(User::factory()->checkoutAccessories()->create())
|
||||
->post(route('accessories.checkout.store', $accessory), [
|
||||
'assigned_to' => $user->id,
|
||||
'assigned_user' => $user->id,
|
||||
'checkout_to_type' => 'user',
|
||||
'note' => 'oh hi there',
|
||||
]);
|
||||
|
||||
$this->assertTrue($accessory->users->contains($user));
|
||||
$this->assertTrue($accessory->checkouts()->where('assigned_type', User::class)->where('assigned_to', $user->id)->count() > 0);
|
||||
|
||||
$this->assertDatabaseHas('action_logs', [
|
||||
'action_type' => 'checkout',
|
||||
@@ -80,12 +84,13 @@ class AccessoryCheckoutTest extends TestCase
|
||||
$this->actingAs(User::factory()->checkoutAccessories()->create())
|
||||
->from(route('accessories.checkout.show', $accessory))
|
||||
->post(route('accessories.checkout.store', $accessory), [
|
||||
'assigned_to' => $user->id,
|
||||
'assigned_user' => $user->id,
|
||||
'checkout_to_type' => 'user',
|
||||
'checkout_qty' => 3,
|
||||
'note' => 'oh hi there',
|
||||
]);
|
||||
|
||||
$this->assertTrue($accessory->users->contains($user));
|
||||
$this->assertTrue($accessory->checkouts()->where('assigned_type', User::class)->where('assigned_to', $user->id)->count() > 0);
|
||||
|
||||
$this->assertDatabaseHas('action_logs', [
|
||||
'action_type' => 'checkout',
|
||||
@@ -97,6 +102,58 @@ class AccessoryCheckoutTest extends TestCase
|
||||
]);
|
||||
}
|
||||
|
||||
public function testAccessoryCanBeCheckedOutToLocationWithQuantity()
|
||||
{
|
||||
$accessory = Accessory::factory()->create(['qty'=>5]);
|
||||
$location = Location::factory()->create();
|
||||
|
||||
$this->actingAs(User::factory()->checkoutAccessories()->create())
|
||||
->from(route('accessories.checkout.show', $accessory))
|
||||
->post(route('accessories.checkout.store', $accessory), [
|
||||
'assigned_location' => $location->id,
|
||||
'checkout_to_type' => 'location',
|
||||
'checkout_qty' => 3,
|
||||
'note' => 'oh hi there',
|
||||
]);
|
||||
|
||||
$this->assertTrue($accessory->checkouts()->where('assigned_type', Location::class)->where('assigned_to', $location->id)->count() > 0);
|
||||
|
||||
$this->assertDatabaseHas('action_logs', [
|
||||
'action_type' => 'checkout',
|
||||
'target_id' => $location->id,
|
||||
'target_type' => Location::class,
|
||||
'item_id' => $accessory->id,
|
||||
'item_type' => Accessory::class,
|
||||
'note' => 'oh hi there',
|
||||
]);
|
||||
}
|
||||
|
||||
public function testAccessoryCanBeCheckedOutToAssetWithQuantity()
|
||||
{
|
||||
$accessory = Accessory::factory()->create(['qty'=>5]);
|
||||
$asset = Asset::factory()->create();
|
||||
|
||||
$this->actingAs(User::factory()->checkoutAccessories()->create())
|
||||
->from(route('accessories.checkout.show', $accessory))
|
||||
->post(route('accessories.checkout.store', $accessory), [
|
||||
'assigned_asset' => $asset->id,
|
||||
'checkout_to_type' => 'asset',
|
||||
'checkout_qty' => 3,
|
||||
'note' => 'oh hi there',
|
||||
]);
|
||||
|
||||
$this->assertTrue($accessory->checkouts()->where('assigned_type', Asset::class)->where('assigned_to', $asset->id)->count() > 0);
|
||||
|
||||
$this->assertDatabaseHas('action_logs', [
|
||||
'action_type' => 'checkout',
|
||||
'target_id' => $asset->id,
|
||||
'target_type' => Asset::class,
|
||||
'item_id' => $accessory->id,
|
||||
'item_type' => Accessory::class,
|
||||
'note' => 'oh hi there',
|
||||
]);
|
||||
}
|
||||
|
||||
public function testUserSentNotificationUponCheckout()
|
||||
{
|
||||
Notification::fake();
|
||||
@@ -107,7 +164,8 @@ class AccessoryCheckoutTest extends TestCase
|
||||
$this->actingAs(User::factory()->checkoutAccessories()->create())
|
||||
->from(route('accessories.checkout.show', $accessory))
|
||||
->post(route('accessories.checkout.store', $accessory), [
|
||||
'assigned_to' => $user->id,
|
||||
'assigned_user' => $user->id,
|
||||
'checkout_to_type' => 'user',
|
||||
]);
|
||||
|
||||
Notification::assertSentTo($user, CheckoutAccessoryNotification::class);
|
||||
@@ -122,7 +180,8 @@ class AccessoryCheckoutTest extends TestCase
|
||||
$this->actingAs($actor)
|
||||
->from(route('accessories.checkout.show', $accessory))
|
||||
->post(route('accessories.checkout.store', $accessory), [
|
||||
'assigned_to' => $user->id,
|
||||
'assigned_user' => $user->id,
|
||||
'checkout_to_type' => 'user',
|
||||
'note' => 'oh hi there',
|
||||
]);
|
||||
|
||||
@@ -148,7 +207,8 @@ class AccessoryCheckoutTest extends TestCase
|
||||
$this->actingAs(User::factory()->admin()->create())
|
||||
->from(route('accessories.index'))
|
||||
->post(route('accessories.checkout.store', $accessory), [
|
||||
'assigned_to' => User::factory()->create()->id,
|
||||
'assigned_user' => User::factory()->create()->id,
|
||||
'checkout_to_type' => 'user',
|
||||
'redirect_option' => 'index',
|
||||
'assigned_qty' => 1,
|
||||
])
|
||||
@@ -163,7 +223,8 @@ class AccessoryCheckoutTest extends TestCase
|
||||
$this->actingAs(User::factory()->admin()->create())
|
||||
->from(route('accessories.index'))
|
||||
->post(route('accessories.checkout.store' , $accessory), [
|
||||
'assigned_to' => User::factory()->create()->id,
|
||||
'assigned_user' => User::factory()->create()->id,
|
||||
'checkout_to_type' => 'user',
|
||||
'redirect_option' => 'item',
|
||||
'assigned_qty' => 1,
|
||||
])
|
||||
@@ -180,7 +241,8 @@ class AccessoryCheckoutTest extends TestCase
|
||||
$this->actingAs(User::factory()->admin()->create())
|
||||
->from(route('accessories.index'))
|
||||
->post(route('accessories.checkout.store' , $accessory), [
|
||||
'assigned_to' => $user->id,
|
||||
'assigned_user' => $user->id,
|
||||
'checkout_to_type' => 'user',
|
||||
'redirect_option' => 'target',
|
||||
'assigned_qty' => 1,
|
||||
])
|
||||
|
||||
Reference in New Issue
Block a user