diff --git a/tests/Controller/AccountControllerTest.php b/tests/Controller/AccountControllerTest.php index 646428b..d07a408 100644 --- a/tests/Controller/AccountControllerTest.php +++ b/tests/Controller/AccountControllerTest.php @@ -38,6 +38,49 @@ class AccountControllerTest extends WebTestCase self::assertResponseIsSuccessful(); } + public function testAccountTicketsTabWithTickets(): void + { + $client = static::createClient(); + $em = static::getContainer()->get(EntityManagerInterface::class); + $user = $this->createUser(['ROLE_ORGANIZER'], true); + + $event = $this->createEvent($em, $user); + $category = $this->createCategory($em, $event); + $billet = $this->createBillet($em, $category); + + $order = new \App\Entity\BilletBuyer(); + $order->setEvent($event); + $order->setUser($user); + $order->setFirstName($user->getFirstName()); + $order->setLastName($user->getLastName()); + $order->setEmail($user->getEmail()); + $order->setOrderNumber('2026-03-21-999'); + $order->setTotalHT(1000); + $order->setStatus(\App\Entity\BilletBuyer::STATUS_PAID); + + $item = new \App\Entity\BilletBuyerItem(); + $item->setBillet($billet); + $item->setBilletName('Test Billet'); + $item->setQuantity(1); + $item->setUnitPriceHT(1000); + $order->addItem($item); + $em->persist($order); + $em->flush(); + + $ticket = new \App\Entity\BilletOrder(); + $ticket->setBilletBuyer($order); + $ticket->setBillet($billet); + $ticket->setBilletName('Test Billet'); + $ticket->setUnitPriceHT(1000); + $em->persist($ticket); + $em->flush(); + + $client->loginUser($user); + $client->request('GET', '/mon-compte?tab=tickets'); + + self::assertResponseIsSuccessful(); + } + public function testAccountPurchasesTab(): void { $client = static::createClient(); diff --git a/tests/Service/OrderIndexServiceTest.php b/tests/Service/OrderIndexServiceTest.php new file mode 100644 index 0000000..3af4fac --- /dev/null +++ b/tests/Service/OrderIndexServiceTest.php @@ -0,0 +1,149 @@ +createMock(MeilisearchService::class); + $em = $this->createMock(EntityManagerInterface::class); + + return [$meilisearch, $em, new OrderIndexService($meilisearch, $em)]; + } + + private function createOrder(): BilletBuyer + { + $user = new User(); + $user->setEmail('orga@test.fr'); + $user->setFirstName('Test'); + $user->setLastName('Orga'); + $user->setPassword('hashed'); + + $event = new Event(); + $event->setAccount($user); + $event->setTitle('Test Event'); + $event->setStartAt(new \DateTimeImmutable()); + $event->setEndAt(new \DateTimeImmutable('+1 day')); + $event->setAddress('1 rue'); + $event->setZipcode('75001'); + $event->setCity('Paris'); + + $order = new BilletBuyer(); + $order->setEvent($event); + $order->setFirstName('Jean'); + $order->setLastName('Dupont'); + $order->setEmail('jean@test.fr'); + $order->setOrderNumber('2026-03-21-1'); + $order->setTotalHT(1500); + + $item = new BilletBuyerItem(); + $item->setBilletName('Entree VIP'); + $item->setQuantity(2); + $order->addItem($item); + + return $order; + } + + public function testSearchOrdersReturnsEmptyOnEmptyQuery(): void + { + [$meilisearch, $em, $service] = $this->createMocks(); + + $meilisearch->expects(self::never())->method('search'); + + $result = $service->searchOrders(1, ''); + + self::assertSame([], $result); + } + + public function testSearchOrdersReturnResultsFromMeilisearch(): void + { + [$meilisearch, $em, $service] = $this->createMocks(); + + $order = $this->createOrder(); + + $meilisearch->expects(self::once()) + ->method('search') + ->with('order_event_1', 'dupont') + ->willReturn(['hits' => [['id' => 42]]]); + + $repo = $this->createMock(BilletBuyerRepository::class); + $repo->expects(self::once()) + ->method('findBy') + ->with(['id' => [42]]) + ->willReturn([$order]); + + $em->expects(self::once()) + ->method('getRepository') + ->with(BilletBuyer::class) + ->willReturn($repo); + + $result = $service->searchOrders(1, 'dupont'); + + self::assertCount(1, $result); + } + + public function testSearchOrdersReturnsEmptyOnNoHits(): void + { + [$meilisearch, $em, $service] = $this->createMocks(); + + $meilisearch->expects(self::once()) + ->method('search') + ->willReturn(['hits' => []]); + + $result = $service->searchOrders(1, 'inexistant'); + + self::assertSame([], $result); + } + + public function testSearchOrdersReturnsEmptyOnException(): void + { + [$meilisearch, $em, $service] = $this->createMocks(); + + $meilisearch->expects(self::once()) + ->method('search') + ->willThrowException(new \RuntimeException('Meilisearch down')); + + $result = $service->searchOrders(1, 'test'); + + self::assertSame([], $result); + } + + public function testIndexOrder(): void + { + [$meilisearch, $em, $service] = $this->createMocks(); + + $order = $this->createOrder(); + + $meilisearch->expects(self::once())->method('createIndexIfNotExists'); + $meilisearch->expects(self::once())->method('addDocuments'); + + $service->indexOrder($order); + } + + public function testIndexOrderHandlesException(): void + { + [$meilisearch, $em, $service] = $this->createMocks(); + + $order = $this->createOrder(); + + $meilisearch->expects(self::once()) + ->method('createIndexIfNotExists') + ->willThrowException(new \RuntimeException('Meilisearch down')); + + $service->indexOrder($order); + + // No exception thrown + self::assertTrue(true); + } +}