- Homepage: hero, how it works (buyer/organizer), features, CTA
- Tarifs: 3 plans (Gratuit, Basique 10€, Sur-mesure), JSON-LD Product
- Legal pages: mentions legales, CGU (tabs buyer/organizer), CGV, RGPD, cookies, hosting
- Navbar: neubrutalism style, logo liip, mobile menu, SEO attributes
- Footer: contact, description, legal links, tarifs
- Sitemap: add /tarifs and /sitemap-orgas-{page}.xml
- Liip Imagine: remove S3, webp format on all filters
- Tests: full coverage for all controllers, services, repositories
- Fix CSP: replace inline onclick with data-tab JS
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
177 lines
6.4 KiB
PHP
177 lines
6.4 KiB
PHP
<?php
|
|
|
|
namespace App\Tests\Service;
|
|
|
|
use App\Message\MeilisearchMessage;
|
|
use App\Service\MeilisearchService;
|
|
use PHPUnit\Framework\TestCase;
|
|
use Symfony\Component\Messenger\Envelope;
|
|
use Symfony\Component\Messenger\MessageBusInterface;
|
|
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
|
use Symfony\Contracts\HttpClient\ResponseInterface;
|
|
|
|
class MeilisearchServiceTest extends TestCase
|
|
{
|
|
private HttpClientInterface $httpClient;
|
|
private MessageBusInterface $bus;
|
|
private MeilisearchService $service;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
$this->httpClient = $this->createMock(HttpClientInterface::class);
|
|
$this->bus = $this->createMock(MessageBusInterface::class);
|
|
$this->service = new MeilisearchService(
|
|
$this->httpClient,
|
|
$this->bus,
|
|
'http://meilisearch:7700',
|
|
'test-key',
|
|
);
|
|
}
|
|
|
|
public function testIndexExistsReturnsTrue(): void
|
|
{
|
|
$response = $this->createMock(ResponseInterface::class);
|
|
$response->method('getStatusCode')->willReturn(200);
|
|
$this->httpClient->method('request')->willReturn($response);
|
|
|
|
self::assertTrue($this->service->indexExists('events'));
|
|
}
|
|
|
|
public function testIndexExistsReturnsFalseOnException(): void
|
|
{
|
|
$this->httpClient->method('request')->willThrowException(new \RuntimeException('fail'));
|
|
|
|
self::assertFalse($this->service->indexExists('events'));
|
|
}
|
|
|
|
public function testCreateIndexIfNotExistsCreatesWhenMissing(): void
|
|
{
|
|
$this->httpClient->method('request')->willThrowException(new \RuntimeException('not found'));
|
|
$this->bus->expects(self::once())
|
|
->method('dispatch')
|
|
->with(self::callback(fn (MeilisearchMessage $m) => 'createIndex' === $m->action))
|
|
->willReturn(new Envelope(new \stdClass()));
|
|
|
|
$this->service->createIndexIfNotExists('events');
|
|
}
|
|
|
|
public function testCreateIndexIfNotExistsSkipsWhenExists(): void
|
|
{
|
|
$response = $this->createMock(ResponseInterface::class);
|
|
$response->method('getStatusCode')->willReturn(200);
|
|
$this->httpClient->method('request')->willReturn($response);
|
|
$this->bus->expects(self::never())->method('dispatch');
|
|
|
|
$this->service->createIndexIfNotExists('events');
|
|
}
|
|
|
|
public function testCreateIndexDispatchesMessage(): void
|
|
{
|
|
$this->bus->expects(self::once())
|
|
->method('dispatch')
|
|
->with(self::callback(fn (MeilisearchMessage $m) => 'createIndex' === $m->action && 'events' === $m->index))
|
|
->willReturn(new Envelope(new \stdClass()));
|
|
|
|
$this->service->createIndex('events');
|
|
}
|
|
|
|
public function testDeleteIndexDispatchesMessage(): void
|
|
{
|
|
$this->bus->expects(self::once())
|
|
->method('dispatch')
|
|
->with(self::callback(fn (MeilisearchMessage $m) => 'deleteIndex' === $m->action))
|
|
->willReturn(new Envelope(new \stdClass()));
|
|
|
|
$this->service->deleteIndex('events');
|
|
}
|
|
|
|
public function testAddDocumentsDispatchesMessage(): void
|
|
{
|
|
$docs = [['id' => 1, 'title' => 'Test']];
|
|
$this->bus->expects(self::once())
|
|
->method('dispatch')
|
|
->with(self::callback(fn (MeilisearchMessage $m) => 'addDocuments' === $m->action && $m->payload['documents'] === $docs))
|
|
->willReturn(new Envelope(new \stdClass()));
|
|
|
|
$this->service->addDocuments('events', $docs);
|
|
}
|
|
|
|
public function testUpdateDocumentsDispatchesMessage(): void
|
|
{
|
|
$docs = [['id' => 1, 'title' => 'Updated']];
|
|
$this->bus->expects(self::once())
|
|
->method('dispatch')
|
|
->with(self::callback(fn (MeilisearchMessage $m) => 'updateDocuments' === $m->action && $m->payload['documents'] === $docs))
|
|
->willReturn(new Envelope(new \stdClass()));
|
|
|
|
$this->service->updateDocuments('events', $docs);
|
|
}
|
|
|
|
public function testDeleteDocumentDispatchesMessage(): void
|
|
{
|
|
$this->bus->expects(self::once())
|
|
->method('dispatch')
|
|
->with(self::callback(fn (MeilisearchMessage $m) => 'deleteDocument' === $m->action && 42 === $m->payload['documentId']))
|
|
->willReturn(new Envelope(new \stdClass()));
|
|
|
|
$this->service->deleteDocument('events', 42);
|
|
}
|
|
|
|
public function testDeleteDocumentsDispatchesMessage(): void
|
|
{
|
|
$ids = [1, 2, 3];
|
|
$this->bus->expects(self::once())
|
|
->method('dispatch')
|
|
->with(self::callback(fn (MeilisearchMessage $m) => 'deleteDocuments' === $m->action && $m->payload['ids'] === $ids))
|
|
->willReturn(new Envelope(new \stdClass()));
|
|
|
|
$this->service->deleteDocuments('events', $ids);
|
|
}
|
|
|
|
public function testUpdateSettingsDispatchesMessage(): void
|
|
{
|
|
$settings = ['filterableAttributes' => ['status']];
|
|
$this->bus->expects(self::once())
|
|
->method('dispatch')
|
|
->with(self::callback(fn (MeilisearchMessage $m) => 'updateSettings' === $m->action && $m->payload['settings'] === $settings))
|
|
->willReturn(new Envelope(new \stdClass()));
|
|
|
|
$this->service->updateSettings('events', $settings);
|
|
}
|
|
|
|
public function testSearchMakesPostRequest(): void
|
|
{
|
|
$response = $this->createMock(ResponseInterface::class);
|
|
$response->method('getStatusCode')->willReturn(200);
|
|
$response->method('toArray')->willReturn(['hits' => []]);
|
|
$this->httpClient->method('request')->willReturn($response);
|
|
|
|
$result = $this->service->search('events', 'test');
|
|
|
|
self::assertArrayHasKey('hits', $result);
|
|
}
|
|
|
|
public function testGetDocumentReturnsArray(): void
|
|
{
|
|
$response = $this->createMock(ResponseInterface::class);
|
|
$response->method('getStatusCode')->willReturn(200);
|
|
$response->method('toArray')->willReturn(['id' => 1, 'title' => 'Event']);
|
|
$this->httpClient->method('request')->willReturn($response);
|
|
|
|
$result = $this->service->getDocument('events', 1);
|
|
|
|
self::assertSame(1, $result['id']);
|
|
}
|
|
|
|
public function testRequestReturnsEmptyArrayOn204(): void
|
|
{
|
|
$response = $this->createMock(ResponseInterface::class);
|
|
$response->method('getStatusCode')->willReturn(204);
|
|
$this->httpClient->method('request')->willReturn($response);
|
|
|
|
$result = $this->service->request('DELETE', '/indexes/events');
|
|
|
|
self::assertSame([], $result);
|
|
}
|
|
}
|