diff --git a/database/factories/AccessoryFactory.php b/database/factories/AccessoryFactory.php index a0d7fbbff6..4066526770 100644 --- a/database/factories/AccessoryFactory.php +++ b/database/factories/AccessoryFactory.php @@ -133,4 +133,11 @@ class AccessoryFactory extends Factory ]); }); } + + public function requiringAcceptance() + { + return $this->afterCreating(function ($accessory) { + $accessory->category->update(['require_acceptance' => 1]); + }); + } } diff --git a/tests/Feature/Checkouts/AccessoryCheckoutTest.php b/tests/Feature/Checkouts/AccessoryCheckoutTest.php index e81d1f7af3..df89c5037b 100644 --- a/tests/Feature/Checkouts/AccessoryCheckoutTest.php +++ b/tests/Feature/Checkouts/AccessoryCheckoutTest.php @@ -3,7 +3,10 @@ namespace Tests\Feature\Checkouts; use App\Models\Accessory; +use App\Models\Actionlog; use App\Models\User; +use App\Notifications\CheckoutAccessoryNotification; +use Illuminate\Support\Facades\Notification; use Tests\Support\InteractsWithSettings; use Tests\TestCase; @@ -52,16 +55,41 @@ class AccessoryCheckoutTest extends TestCase $this->assertTrue($accessory->users->contains($user)); } - public function testUserSentEulaUponCheckoutIfAcceptanceRequired() + public function testUserSentNotificationUponCheckout() { - $this->markTestIncomplete(); + Notification::fake(); + + $accessory = Accessory::factory()->requiringAcceptance()->create(); + $user = User::factory()->create(); + + $this->actingAs(User::factory()->checkoutAccessories()->create()) + ->post(route('accessories.checkout.store', $accessory), [ + 'assigned_to' => $user->id, + ]); + + Notification::assertSentTo($user, CheckoutAccessoryNotification::class); } public function testActionLogCreatedUponCheckout() { - $this->markTestIncomplete(); + $accessory = Accessory::factory()->create(); + $actor = User::factory()->checkoutAccessories()->create(); + $user = User::factory()->create(); - // check 'note' is saved in action_logs - // check 'action_source' is saved in action_logs as gui + $this->actingAs($actor) + ->post(route('accessories.checkout.store', $accessory), [ + 'assigned_to' => $user->id, + 'note' => 'oh hi there', + ]); + + $this->assertDatabaseHas('action_logs', [ + 'action_type' => 'checkout', + 'target_id' => $user->id, + 'target_type' => User::class, + 'item_id' => $accessory->id, + 'item_type' => Accessory::class, + 'user_id' => $actor->id, + 'note' => 'oh hi there', + ]); } }