59 lines
1.9 KiB
PHP
59 lines
1.9 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Actions\Faqs\UpdateFaqInput;
|
|
use App\Models\Faq;
|
|
|
|
describe('UpdateFaqInput', function (): void {
|
|
it('can be instantiated with valid data', function (): void {
|
|
// GIVEN
|
|
$faq = new Faq();
|
|
$question = 'Nouvelle question mise à jour ?';
|
|
$answer = 'Nouvelle réponse détaillée.';
|
|
|
|
// WHEN
|
|
$input = new UpdateFaqInput(faq: $faq, question: $question, answer: $answer);
|
|
|
|
// THEN
|
|
expect($input->faq)->toBe($faq)
|
|
->and($input->question)->toBe($question)
|
|
->and($input->answer)->toBe($answer);
|
|
});
|
|
});
|
|
|
|
describe('UpdateFaqInput validation rules', function (): void {
|
|
it('throws when question is empty or too short', function (string $invalidQuestion): void {
|
|
// GIVEN
|
|
$faq = new Faq();
|
|
$answer = 'Une réponse valide.';
|
|
|
|
// WHEN
|
|
expect(fn () => new UpdateFaqInput(faq: $faq, question: $invalidQuestion, answer: $answer))
|
|
// THEN
|
|
->toThrow(\InvalidArgumentException::class);
|
|
})->with(['', ' ', 'abc']);
|
|
|
|
it('throws when question exceeds 255 characters', function (): void {
|
|
// GIVEN
|
|
$faq = new Faq();
|
|
$question = str_repeat('a', 256);
|
|
$answer = 'Une réponse valide.';
|
|
|
|
// WHEN
|
|
expect(fn () => new UpdateFaqInput(faq: $faq, question: $question, answer: $answer))
|
|
// THEN
|
|
->toThrow(\InvalidArgumentException::class);
|
|
});
|
|
|
|
it('throws when answer is empty or too short', function (string $invalidAnswer): void {
|
|
// GIVEN
|
|
$faq = new Faq();
|
|
$question = 'Une question valide ?';
|
|
|
|
// WHEN
|
|
expect(fn () => new UpdateFaqInput(faq: $faq, question: $question, answer: $invalidAnswer))
|
|
// THEN
|
|
->toThrow(\InvalidArgumentException::class);
|
|
})->with(['', ' ', 'abc']);
|
|
});
|