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 = new CrmHashcode(Uuid::uuid4()); $user->shouldReceive('getAuthPassword')->andReturn('dummy'); $this->actingAs($user, 'frontend'); $crmMock = \Mockery::mock(CrmService::class)->makePartial(); $crmMock->shouldReceive('getCustomerFromHashCode')->andReturn(null); App::instance(CrmService::class, $crmMock); // WHEN $response = $this->get('/compte'); // THEN $response->assertStatus(302); }); it('can access get /compte/profil', function () { // GIVEN /** @var \Tests\TestCase $this */ $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 = new CrmHashcode(Uuid::uuid4()); $user->shouldReceive('getAuthPassword')->andReturn('dummy'); $this->actingAs($user, 'frontend'); $crmMock = \Mockery::mock(CrmService::class)->makePartial(); $crmMock->shouldReceive('getCustomerFromHashCode')->andReturn(null); App::instance(CrmService::class, $crmMock); // WHEN $response = $this->get('/compte/profil'); // THEN $response->assertStatus(302); }); it('can access post /compte/profil', function () { // GIVEN /** @var \Tests\TestCase $this */ $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 = new CrmHashcode(Uuid::uuid4()); $user->shouldReceive('getAuthPassword')->andReturn('dummy'); $this->actingAs($user, 'frontend'); $crmMock = \Mockery::mock(CrmService::class)->makePartial(); $crmMock->shouldReceive('getCustomerFromHashCode')->andReturn(null); App::instance(CrmService::class, $crmMock); // WHEN $response = $this->post('/compte/profil', []); // THEN $response->assertStatus(302); }); it('renders customer edit infos page with crm customer data', function () { /** @var \Tests\TestCase $this */ // GIVEN $this->seed(ContentSeeder::class); View::share('PageList', Page::getCached() ->mapWithKeys(fn ($page) => [ $page->slug->value() => $page, ])); Cache::flush(); $hashcode = new CrmHashcode(Uuid::uuid4()); $customer = Customer::forceCreate([ 'id' => Uuid::uuid7()->toString(), 'hashcode' => $hashcode->value, 'email' => new Email('jean.dupont@example.com'), ]); Employee::forceCreate([ 'id' => 8882, 'customer_id' => $customer->id, 'matricule' => new Matricule('8888002'), 'nom' => 'Dupont', 'prenom' => 'Jean', 'code' => new Code('ABCDEF13'), 'etablissement' => 'ETAB', 'site' => 'SITE', 'service' => '101', 'created_at' => CarbonImmutable::now(), 'updated_at' => CarbonImmutable::now(), ]); $crmCustomer = new CrmCustomer( hashcode: $hashcode->value, email: 'jean.dupont@example.com', password: 'pwd', firstname: 'Jean', lastname: 'Dupont', birthDate: '1985-05-15', phone: '0123456789', address: '10 rue de la Paix', address2: null, city: 'Paris', postcode: '75002', country: Country::france, optIn: true, status: true, lastConnection: null, ); $crmMock = \Mockery::mock(CrmService::class)->makePartial(); $crmMock->shouldReceive('getCustomerFromHashCode')->andReturn($crmCustomer); App::instance(CrmService::class, $crmMock); $this->actingAs($customer, 'frontend'); // WHEN $response = $this->get('/compte/profil'); // THEN $response->assertOk(); $response->assertViewIs('fo.customer.edit.infos'); $response->assertViewHas('crmCustomer', $crmCustomer); $response->assertSee('value="Dupont"', false); $response->assertSee('value="Jean"', false); }); it('successfully updates customer infos and redirects back', function () { /** @var \Tests\TestCase $this */ // GIVEN $this->seed(ContentSeeder::class); View::share('PageList', Page::getCached() ->mapWithKeys(fn ($page) => [ $page->slug->value() => $page, ])); Cache::flush(); $hashcode = new CrmHashcode(Uuid::uuid4()); $customer = Customer::forceCreate([ 'id' => Uuid::uuid7()->toString(), 'hashcode' => $hashcode->value, 'email' => new Email('jean.dupont@example.com'), ]); Employee::forceCreate([ 'id' => 8883, 'customer_id' => $customer->id, 'matricule' => new Matricule('8888003'), 'nom' => 'Dupont', 'prenom' => 'Jean', 'code' => new Code('ABCDEF14'), 'etablissement' => 'ETAB', 'site' => 'SITE', 'service' => '101', 'created_at' => CarbonImmutable::now(), 'updated_at' => CarbonImmutable::now(), ]); $updatedCrmCustomer = new CrmCustomer( hashcode: $hashcode->value, email: 'jean.dupont@example.com', password: 'pwd', firstname: 'Jean-Pierre', lastname: 'Durand', birthDate: '1985-05-15', phone: '0123456789', address: '20 avenue Foch', address2: null, city: 'Lyon', postcode: '69001', country: Country::france, optIn: true, status: true, lastConnection: null, ); $crmMock = \Mockery::mock(CrmService::class); $crmMock->shouldReceive('getCustomerFromHashCode') ->andReturn($updatedCrmCustomer); $crmMock->shouldReceive('updateCustomerInfos') ->once() ->andReturn($updatedCrmCustomer); App::instance(CrmService::class, $crmMock); $this->actingAs($customer, 'frontend'); // WHEN $response = $this->post('/compte/profil', [ 'firstname' => 'Jean-Pierre', 'lastname' => 'Durand', 'birth_date' => '1985-05-15', 'phone' => '0123456789', 'address' => '20 avenue Foch', 'city' => 'Lyon', 'postcode' => '69001', 'opt_in' => true, ]); // THEN $response->assertRedirect(); $response->assertSessionHas('success', trans('Your information has been saved.')); }); });