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/commandes'); // THEN $response->assertStatus(302); }); it('can access get /compte/commandes/1', 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 = 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/commandes/1'); // THEN $response->assertStatus(404); }); it('renders customer orders index with DTOs when verified', 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('verified@example.com'), ]); Employee::forceCreate([ 'id' => 8881, 'customer_id' => $customer->id, 'matricule' => new Matricule('8888001'), 'nom' => 'Dupont', 'prenom' => 'Jean', 'code' => new Code('ABCDEF12'), 'etablissement' => 'E', 'site' => 'S', 'service' => 'S', 'created_at' => CarbonImmutable::now(), 'updated_at' => CarbonImmutable::now(), ]); $shop = Shop::factory()->create(); $ref = \Symfony\Component\Uid\Uuid::v7()->toBase58(); Order::forceCreate([ 'id' => Uuid::uuid7()->toString(), 'shop_id' => $shop->id, 'reference' => new OrderReference($ref), 'status' => OrderStatus::VALIDATED->value, 'total' => new Money(5000, new Currency('EUR')), 'employee' => new OrderEmployee(new Matricule('8888001'), 'Jean', 'Dupont', 'F', 'S', 'S'), 'delivery_address' => new DeliveryAddress('Shop Name', 'Address', '75000', 'Paris'), 'pickup_day' => Date::now()->toDateString(), ]); $crmCustomer = new CrmCustomer( hashcode: $hashcode->value, email: 'verified@example.com', password: 'pwd', firstname: 'Jean', lastname: 'Dupont', birthDate: null, phone: '0123456789', address: '10 rue test', address2: null, city: 'Paris', postcode: '75000', 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/commandes'); // THEN expect($response->status())->toBe(200); $response->assertViewIs('fo.customer.orders.index'); $response->assertViewHas('orders', function ($orders) use ($ref): bool { return $orders instanceof LengthAwarePaginator && $orders->total() === 1 && (string) $orders->first()->reference === $ref; }); }); it('renders customer order detail when owned by customer', 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('verified_show@example.com'), ]); Employee::forceCreate([ 'id' => 8882, 'customer_id' => $customer->id, 'matricule' => new Matricule('8888002'), 'nom' => 'Martin', 'prenom' => 'Paul', 'code' => new Code('ABCDEF34'), 'etablissement' => 'E', 'site' => 'S', 'service' => 'S', 'created_at' => CarbonImmutable::now(), 'updated_at' => CarbonImmutable::now(), ]); $shop = Shop::factory()->create(); $ref = \Symfony\Component\Uid\Uuid::v7()->toBase58(); $order = Order::forceCreate([ 'id' => Uuid::uuid7()->toString(), 'shop_id' => $shop->id, 'reference' => new OrderReference($ref), 'status' => OrderStatus::VALIDATED->value, 'total' => new Money(5000, new Currency('EUR')), 'employee' => new OrderEmployee(new Matricule('8888002'), 'Paul', 'Martin', 'F', 'S', 'S'), 'delivery_address' => new DeliveryAddress('Shop Name', 'Address', '75000', 'Paris'), 'pickup_day' => Date::now()->toDateString(), ]); $crmCustomer = new CrmCustomer( hashcode: $hashcode->value, email: 'verified_show@example.com', password: 'pwd', firstname: 'Paul', lastname: 'Martin', birthDate: null, phone: '0123456789', address: '10 rue test', address2: null, city: 'Paris', postcode: '75000', 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/commandes/{$ref}"); // THEN expect($response->status())->toBe(200); $response->assertViewIs('fo.customer.orders.show'); $response->assertViewHas('order', fn ($orderData) => $orderData instanceof OrderDto && (string) $orderData->reference === $ref); $response->assertViewHas('mapUrl'); }); });