diff --git a/tests/Feature/App/Listeners/CustomerPasswordUpdatedListenerTest.php b/tests/Feature/App/Listeners/CustomerPasswordUpdatedListenerTest.php new file mode 100644 index 00000000..bed6ab49 --- /dev/null +++ b/tests/Feature/App/Listeners/CustomerPasswordUpdatedListenerTest.php @@ -0,0 +1,27 @@ +handle($event); + + // THEN + Mail::assertQueued( + CustomerPasswordHasReset::class, + static fn (CustomerPasswordHasReset $mail): bool => $mail->hasTo('reset@example.com'), + ); +}); diff --git a/tests/Feature/App/Listeners/Orders/SendAdminOrderConfirmationTest.php b/tests/Feature/App/Listeners/Orders/SendAdminOrderConfirmationTest.php new file mode 100644 index 00000000..b5ba7690 --- /dev/null +++ b/tests/Feature/App/Listeners/Orders/SendAdminOrderConfirmationTest.php @@ -0,0 +1,87 @@ + new SendAdminOrderConfirmation()) + ->toThrow(\UnexpectedValueException::class); +}); + +it('queues OrderConfirmAdminMail to configured contact email when AnOrderHasBeenPlaced is handled', function (): void { + // GIVEN + Mail::fake(); + Config::set('mail.to.contact', 'contact@example.com'); + $listener = new SendAdminOrderConfirmation(); + $event = makeOrderPlacedEvent(); + + // WHEN + $listener->handle($event); + + // THEN + Mail::assertQueued( + OrderConfirmAdminMail::class, + static fn (OrderConfirmAdminMail $mail): bool => $mail->hasTo('contact@example.com'), + ); +}); diff --git a/tests/Feature/App/Listeners/Orders/SendCustomerOrderConfirmationTest.php b/tests/Feature/App/Listeners/Orders/SendCustomerOrderConfirmationTest.php new file mode 100644 index 00000000..68a51780 --- /dev/null +++ b/tests/Feature/App/Listeners/Orders/SendCustomerOrderConfirmationTest.php @@ -0,0 +1,98 @@ +matricule = new Matricule('1234567'); + $employee->nom = 'Dupont'; + $employee->prenom = 'Jean'; + $employee->etablissement = new ShopperEstablishmentCode('FAC01'); + $employee->site = new ShopperSiteCode('SITE'); + $employee->service = new ShopperServiceCode('101'); + $employee->code = new Code('ABCD2345'); + $employee->saveOrFail(); + + $listener = new SendCustomerOrderConfirmation(); + $event = makeCustomerOrderPlacedEvent('1234567'); + + // WHEN + $listener->handle($event); + + // THEN + Notification::assertSentTo($employee, OrderConfirmed::class); +}); + +it('sends nothing when no matching Employee exists', function (): void { + // GIVEN + Notification::fake(); + $listener = new SendCustomerOrderConfirmation(); + $event = makeCustomerOrderPlacedEvent('9999999'); + + // WHEN + $listener->handle($event); + + // THEN + Notification::assertNothingSent(); +}); diff --git a/tests/Integration/WithApp/Infra/Adapters/Services/AppSessionServiceTest.php b/tests/Integration/WithApp/Infra/Adapters/Services/AppSessionServiceTest.php new file mode 100644 index 00000000..495d1a8b --- /dev/null +++ b/tests/Integration/WithApp/Infra/Adapters/Services/AppSessionServiceTest.php @@ -0,0 +1,75 @@ +get(); + + // THEN + expect(UuidHelper::isV7($sessionId->value))->toBeTrue() + ->and(Session::has($sessionKey))->toBeTrue() + ->and(Session::get($sessionKey))->toBe($sessionId->value->toString()); + }); + + it('returns the exact same SessionId on subsequent get calls without overwriting the session value', function (): void { + // GIVEN + $sessionKey = 'test_session_id'; + Session::forget($sessionKey); + $service = new AppSessionService($sessionKey); + + // WHEN + $first = $service->get(); + $second = $service->get(); + + // THEN + expect($second->value->toString())->toBe($first->value->toString()) + ->and(Session::get($sessionKey))->toBe($first->value->toString()); + }); + + it('hydrates an existing UUID string already stored in Session under the configured key', function (): void { + // GIVEN + $sessionKey = 'test_session_id'; + $existingUuid = Uuid::uuid7()->toString(); + Session::put($sessionKey, $existingUuid); + $service = new AppSessionService($sessionKey); + + // WHEN + $sessionId = $service->get(); + + // THEN + expect($sessionId->value->toString())->toBe($existingUuid) + ->and(Session::get($sessionKey))->toBe($existingUuid); + }); + + it('keeps separate AppSessionService instances with distinct session keys isolated', function (): void { + // GIVEN + $firstKey = 'first_session_id'; + $secondKey = 'second_session_id'; + Session::forget([$firstKey, $secondKey]); + $firstService = new AppSessionService($firstKey); + $secondService = new AppSessionService($secondKey); + + // WHEN + $firstId = $firstService->get(); + $secondId = $secondService->get(); + + // THEN + expect($firstId->value->toString())->not->toBe($secondId->value->toString()) + ->and(Session::get($firstKey))->toBe($firstId->value->toString()) + ->and(Session::get($secondKey))->toBe($secondId->value->toString()); + }); +});