2026-09-29 15:10:29 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2026-11-10 14:28:00 +01:00
|
|
|
use App\Cqs\Queries\Pages\GetPageQuery;
|
|
|
|
|
use App\Cqs\Queries\Pages\GetPageQueryInput;
|
2026-09-29 15:10:29 +02:00
|
|
|
use App\Dto\PageDto;
|
|
|
|
|
use App\Models\Page;
|
|
|
|
|
use Domain\Enums\StaticPageSlug;
|
2026-10-02 12:14:48 +02:00
|
|
|
use Domain\Models\ValueObjects\Slug;
|
2026-09-29 15:10:29 +02:00
|
|
|
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
|
|
|
|
|
|
|
|
|
describe('GetPageBySlugQuery', function (): void {
|
|
|
|
|
it('returns a PageDto when page exists by enum slug', function (): void {
|
|
|
|
|
// GIVEN
|
|
|
|
|
$page = new Page();
|
|
|
|
|
$page->slug = StaticPageSlug::LEGALS;
|
|
|
|
|
$page->seo_title = 'Mentions légales SEO';
|
|
|
|
|
$page->seo_description = 'Mentions légales description SEO';
|
|
|
|
|
$page->title = 'Mentions légales';
|
|
|
|
|
$page->content = '<p>Contenu des mentions légales</p>';
|
|
|
|
|
$page->save();
|
|
|
|
|
|
2026-09-29 16:59:07 +02:00
|
|
|
/** @var GetPageQuery $query */
|
|
|
|
|
$query = app(GetPageQuery::class);
|
2026-09-29 15:10:29 +02:00
|
|
|
|
|
|
|
|
// WHEN
|
2026-10-02 12:14:48 +02:00
|
|
|
$dto = $query(new GetPageQueryInput(new Slug(StaticPageSlug::LEGALS->value)));
|
2026-09-29 15:10:29 +02:00
|
|
|
|
|
|
|
|
// THEN
|
|
|
|
|
expect($dto)->toBeInstanceOf(PageDto::class)
|
|
|
|
|
->and($dto->id)->toBe($page->id)
|
|
|
|
|
->and($dto->slug)->toBe(StaticPageSlug::LEGALS)
|
|
|
|
|
->and($dto->seo_title)->toBe('Mentions légales SEO')
|
|
|
|
|
->and($dto->title)->toBe('Mentions légales');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('returns a PageDto when page exists by string slug', function (): void {
|
|
|
|
|
// GIVEN
|
|
|
|
|
$page = new Page();
|
|
|
|
|
$page->slug = StaticPageSlug::TERMS;
|
|
|
|
|
$page->seo_title = 'CGV SEO Title';
|
|
|
|
|
$page->seo_description = 'CGV SEO Description';
|
|
|
|
|
$page->title = 'Conditions Générales de Vente';
|
|
|
|
|
$page->content = '<p>Contenu CGV</p>';
|
|
|
|
|
$page->save();
|
|
|
|
|
|
2026-09-29 16:59:07 +02:00
|
|
|
/** @var GetPageQuery $query */
|
|
|
|
|
$query = app(GetPageQuery::class);
|
2026-09-29 15:10:29 +02:00
|
|
|
|
|
|
|
|
// WHEN
|
2026-10-02 12:14:48 +02:00
|
|
|
$dto = $query(new GetPageQueryInput(new Slug('cgv')));
|
2026-09-29 15:10:29 +02:00
|
|
|
|
|
|
|
|
// THEN
|
|
|
|
|
expect($dto)->toBeInstanceOf(PageDto::class)
|
|
|
|
|
->and($dto->id)->toBe($page->id)
|
|
|
|
|
->and($dto->slug)->toBe(StaticPageSlug::TERMS);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('throws ModelNotFoundException when page does not exist', function (): void {
|
|
|
|
|
// GIVEN
|
2026-09-29 16:59:07 +02:00
|
|
|
/** @var GetPageQuery $query */
|
|
|
|
|
$query = app(GetPageQuery::class);
|
2026-09-29 15:10:29 +02:00
|
|
|
|
|
|
|
|
// WHEN
|
2026-10-02 12:14:48 +02:00
|
|
|
expect(fn () => $query(new GetPageQueryInput(new Slug('non-existent-slug'))))
|
2026-09-29 15:10:29 +02:00
|
|
|
// THEN
|
|
|
|
|
->toThrow(ModelNotFoundException::class);
|
|
|
|
|
});
|
|
|
|
|
});
|