seed(ContentSeeder::class); View::share('PageList', Page::getCached() ->mapWithKeys(fn ($page) => [ $page->slug->value() => $page, ])); Cache::flush(); // WHEN $response = $this->get('/auth/connexion'); // THEN $response->assertStatus(200); }); it('can access post /auth/connexion', 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/connexion', []); // THEN $response->assertStatus(302); }); it('can access post /auth/deconnexion', function () { /** @var \Tests\TestCase $this */ // GIVEN $this->seed(ContentSeeder::class); View::share('PageList', Page::getCached() ->mapWithKeys(fn ($page) => [ $page->slug->value() => $page, ])); Cache::flush(); $user = \Mockery::mock(Customer::class)->makePartial(); $user->shouldReceive('getAuthIdentifier')->andReturn(1); $user->hashcode = 'dummy_hashcode'; $user->shouldReceive('getAuthPassword')->andReturn('dummy'); $this->actingAs($user, 'frontend'); // WHEN $response = $this->post('/auth/deconnexion'); // THEN $response->assertStatus(302); }); it('throws CustomerNotEmployedException when shopper is not active during login', function () { /** @var \Tests\TestCase $this */ // GIVEN $this->seed(ContentSeeder::class); View::share('PageList', Page::getCached() ->mapWithKeys(fn ($page) => [ $page->slug->value() => $page, ])); Cache::flush(); $customer = Customer::forceCreate([ 'email' => new Email('test@example.com'), 'hashcode' => (string) Str::uuid(), ]); $crmCustomer = new CrmCustomer( hashcode: $customer->hashcode->value, email: 'test@example.com', password: 'password', firstname: 'John', lastname: 'Doe', birthDate: null, phone: null, address: null, address2: null, city: null, postcode: null, country: Country::france, optIn: false, status: true, lastConnection: null, ); $crmService = $this->mock(CrmService::class); $crmService->shouldReceive('getCustomerFromEmail')->with('test@example.com')->andReturn($crmCustomer); $crmService->shouldReceive('login')->with('test@example.com', 'password')->andReturnTrue(); $shopperService = \Mockery::mock(ShopperService::class); $shopperService->shouldReceive('getShopperFor') ->withArgs(function ($arg) use ($customer) { return $arg instanceof ShopperId && (string) $arg->value === $customer->id; }) ->andReturn(null); $this->app->instance(ShopperService::class, $shopperService); // WHEN $this->withoutExceptionHandling(); $this->post('/auth/connexion', [ 'email' => 'test@example.com', 'password' => 'password', ]); })->throws(CustomerNotEmployedException::class); it('flashes success message when shopper is active during login', function () { // GIVEN /** @var \Tests\TestCase $this */ $this->seed(ContentSeeder::class); View::share('PageList', Page::getCached() ->mapWithKeys(fn ($page) => [ $page->slug->value() => $page, ])); Cache::flush(); $customer = Customer::forceCreate([ 'email' => new Email('test2@example.com'), 'hashcode' => (string) Str::uuid(), ]); $crmCustomer = new CrmCustomer( hashcode: $customer->hashcode->value, email: 'test2@example.com', password: 'password', firstname: 'John', lastname: 'Doe', birthDate: null, phone: null, address: null, address2: null, city: null, postcode: null, country: Country::france, optIn: false, status: true, lastConnection: null, ); $crmService = $this->mock(CrmService::class); $crmService->shouldReceive('getCustomerFromEmail')->with('test2@example.com')->andReturn($crmCustomer); $crmService->shouldReceive('login')->with('test2@example.com', 'password')->andReturnTrue(); $shopper = new Shopper( id: clone $customer->getId(), email: new Email('test2@example.com'), matricule: new Matricule('1234567'), nom: 'Doe', prenom: 'John', startDate: CarbonImmutable::now()->subDays(1), endDate: null, etablissement: new ShopperEstablishmentCode('FAC01'), site: new ShopperSiteCode('SITE'), service: new ShopperServiceCode('101'), ); $shopperService = \Mockery::mock(ShopperService::class); $shopperService->shouldReceive('getShopperFor') ->withArgs(function ($arg) use ($customer) { return $arg instanceof ShopperId && (string) $arg->value === $customer->id; }) ->andReturn($shopper); $this->app->instance(ShopperService::class, $shopperService); // WHEN $response = $this->post('/auth/connexion', [ 'email' => 'test2@example.com', 'password' => 'password', ]); // THEN $response->assertRedirect(route('fo.pages.home')); $response->assertSessionHas('success', \trans('You are logged in!')); }); });