seed(ContentSeeder::class); View::share('PageList', Page::getCached() ->mapWithKeys(fn ($page) => [ $page->slug->value() => $page, ])); Cache::flush(); // WHEN $response = $this->get('/auth/inscription'); // THEN $response->assertStatus(200); }); it('can access post /auth/inscription', function () { /** @var \Tests\TestCase $this */ // GIVEN $this->seed(ContentSeeder::class); View::share('PageList', Page::getCached() ->mapWithKeys(fn ($page) => [ $page->slug->value() => $page, ])); Cache::flush(); // WHEN $response = $this->post('/auth/inscription', []); // THEN $response->assertStatus(302); }); it('returns 422 validation error on postJson /auth/inscription when employee already has a customer_id', function (): void { /** @var \Tests\TestCase $this */ // GIVEN $customer = new Customer(['email' => new Email('existing@example.com')]); $customer->hashcode = new CrmHashcode(Uuid::uuid4()); $customer->saveOrFail(); $employee = new Employee(); $employee->matricule = new Matricule('1234567'); $employee->code = new Code('ABCDEF'); $employee->nom = 'Doe'; $employee->prenom = 'John'; $employee->etablissement = new ShopperEstablishmentCode('ETAB01'); $employee->site = new ShopperSiteCode('SITE'); $employee->service = new ShopperServiceCode('1'); $employee->customer()->associate($customer); $employee->saveOrFail(); // WHEN $response = $this->postJson('/auth/inscription', [ 'matricule' => '1234567', 'code' => 'ABCDEF', 'lastname' => 'Doe', 'firstname' => 'John', 'postal_code' => '75001', 'city' => 'Paris', 'email' => 'john.doe@example.com', 'password' => 'Str0ng!Pass#2026', 'password_confirmation' => 'Str0ng!Pass#2026', 'ok_cgv' => '1', 'birth_date' => '1990-01-01', ]); // THEN $response->assertStatus(422) ->assertJsonValidationErrors(['matricule', 'code']); }); it('renders verify view when RegisterCustomer returns SUCCESS', function (): void { /** @var \Tests\TestCase $this */ // GIVEN $customer = new Customer(['email' => new Email('john.doe@example.com')]); $customer->hashcode = new CrmHashcode(Uuid::uuid4()); $customer->saveOrFail(); $input = new RegisterCustomerInput( matricule: new Matricule('1234567'), code: new Code('ABCDEF'), firstname: 'John', lastname: 'Doe', email: new Email('john.doe@example.com'), password: 'Str0ng!Pass#2026', birthDate: new \DateTimeImmutable('1990-01-01'), phone: null, address: null, postcode: '75001', city: 'Paris', ); $request = \Mockery::mock(RegisterRequest::class); $request->shouldReceive('toRegisterCustomerInput')->once()->andReturn($input); $action = $this->app->make(RegisterCustomer::class); $executor = \Mockery::mock(Executor::class); $executor->shouldReceive('execute') ->once() ->with($action, $input) ->andReturn(RegisterCustomerOutput::success($customer)); $controller = new RegisterController($executor); // WHEN $result = $controller->submitForm($request, $action); // THEN expect($result)->toBeInstanceOf(ViewContract::class) ->and($result->name())->toBe('fo.auth.verify'); }); it('redirects back with matricule error when RegisterCustomer returns EMPLOYEE_ALREADY_REGISTERED', function (): void { /** @var \Tests\TestCase $this */ // GIVEN $input = new RegisterCustomerInput( matricule: new Matricule('1234567'), code: new Code('ABCDEF'), firstname: 'John', lastname: 'Doe', email: new Email('john.doe@example.com'), password: 'Str0ng!Pass#2026', birthDate: new \DateTimeImmutable('1990-01-01'), phone: null, address: null, postcode: '75001', city: 'Paris', ); $request = \Mockery::mock(RegisterRequest::class); $request->shouldReceive('toRegisterCustomerInput')->once()->andReturn($input); $request->shouldReceive('except') ->once() ->with(['password', 'password_confirmation']) ->andReturn(['matricule' => '1234567']); $action = $this->app->make(RegisterCustomer::class); $executor = \Mockery::mock(Executor::class); $executor->shouldReceive('execute') ->once() ->with($action, $input) ->andReturn(RegisterCustomerOutput::employeeAlreadyRegistered()); $controller = new RegisterController($executor); // WHEN $result = $controller->submitForm($request, $action); // THEN expect($result)->toBeInstanceOf(RedirectResponse::class); $errors = $result->getSession()?->get('errors'); expect($errors?->get('matricule'))->toBe([__('This employee already has an account.')]); }); it('redirects back with matricule error when RegisterCustomer returns LOCK_TIMEOUT', function (): void { /** @var \Tests\TestCase $this */ // GIVEN $input = new RegisterCustomerInput( matricule: new Matricule('1234567'), code: new Code('ABCDEF'), firstname: 'John', lastname: 'Doe', email: new Email('john.doe@example.com'), password: 'Str0ng!Pass#2026', birthDate: new \DateTimeImmutable('1990-01-01'), phone: null, address: null, postcode: '75001', city: 'Paris', ); $request = \Mockery::mock(RegisterRequest::class); $request->shouldReceive('toRegisterCustomerInput')->once()->andReturn($input); $request->shouldReceive('except') ->once() ->with(['password', 'password_confirmation']) ->andReturn(['matricule' => '1234567']); $action = $this->app->make(RegisterCustomer::class); $executor = \Mockery::mock(Executor::class); $executor->shouldReceive('execute') ->once() ->with($action, $input) ->andReturn(RegisterCustomerOutput::lockTimeout()); $controller = new RegisterController($executor); // WHEN $result = $controller->submitForm($request, $action); // THEN expect($result)->toBeInstanceOf(RedirectResponse::class); $errors = $result->getSession()?->get('errors'); expect($errors?->get('matricule'))->toBe([__('Registration is already in progress. Please try again in a moment.')]); }); it('redirects back with matricule error when RegisterCustomer returns EMPLOYEE_INACTIVE', function (): void { /** @var \Tests\TestCase $this */ // GIVEN $input = new RegisterCustomerInput( matricule: new Matricule('1234567'), code: new Code('ABCDEF'), firstname: 'John', lastname: 'Doe', email: new Email('john.doe@example.com'), password: 'Str0ng!Pass#2026', birthDate: new \DateTimeImmutable('1990-01-01'), phone: null, address: null, postcode: '75001', city: 'Paris', ); $request = \Mockery::mock(RegisterRequest::class); $request->shouldReceive('toRegisterCustomerInput')->once()->andReturn($input); $request->shouldReceive('except') ->once() ->with(['password', 'password_confirmation']) ->andReturn(['matricule' => '1234567']); $action = $this->app->make(RegisterCustomer::class); $executor = \Mockery::mock(Executor::class); $executor->shouldReceive('execute') ->once() ->with($action, $input) ->andReturn(RegisterCustomerOutput::employeeInactive()); $controller = new RegisterController($executor); // WHEN $result = $controller->submitForm($request, $action); // THEN expect($result)->toBeInstanceOf(RedirectResponse::class); $errors = $result->getSession()?->get('errors'); expect($errors?->get('matricule'))->toBe([__('This employee account is no longer active.')]); }); });