69 lines
2.3 KiB
PHP
69 lines
2.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Integration\WithApp\App\Cqs\Queries\Pages;
|
|
|
|
use App\Cqs\Queries\Pages\GetPageQuery;
|
|
use App\Cqs\Queries\Pages\GetPageQueryInput;
|
|
use App\Dto\PageDto;
|
|
use App\Models\Page;
|
|
use Domain\Enums\StaticPageSlug;
|
|
use Domain\Models\ValueObjects\Slug;
|
|
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();
|
|
|
|
$query = new GetPageQuery();
|
|
|
|
// WHEN
|
|
$dto = $query(new GetPageQueryInput(new Slug(StaticPageSlug::LEGALS->value)));
|
|
|
|
// 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();
|
|
|
|
$query = new GetPageQuery();
|
|
|
|
// WHEN
|
|
$dto = $query(new GetPageQueryInput(new Slug('cgv')));
|
|
|
|
// 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
|
|
$query = new GetPageQuery();
|
|
|
|
// WHEN
|
|
expect(fn () => $query(new GetPageQueryInput(new Slug('non-existent-slug'))))
|
|
// THEN
|
|
->toThrow(ModelNotFoundException::class);
|
|
});
|
|
});
|