diff --git a/app/Http/Controllers/QuestionController.php b/app/Http/Controllers/QuestionController.php index 221f25e..d3918b4 100644 --- a/app/Http/Controllers/QuestionController.php +++ b/app/Http/Controllers/QuestionController.php @@ -11,7 +11,15 @@ public function store(Request $request): RedirectResponse { $atributes = request()->validate([ - 'question' => ['required', 'min:10'], + 'question' => [ + 'required', + 'min:10', + function (string $atribute, mixed $value, callable $fail) { + if ($value[strlen($value) - 1] !== '?') { + $fail('Are you sure it is a question? It should end with a question mark in the end.'); + } + }, + ], ]); Question::query()->create($atributes); diff --git a/tests/Feature/CreateAQuestionTest.php b/tests/Feature/CreateAQuestionTest.php index da34752..a658992 100644 --- a/tests/Feature/CreateAQuestionTest.php +++ b/tests/Feature/CreateAQuestionTest.php @@ -24,6 +24,19 @@ it('shold check if ends with question mark?', function () { + //Arrange::preparar + $user = User::factory()->create(); + actingAs($user); + + //Act::agir + $request = post(route('questions.store'), [ + 'question' => str_repeat('#', 10), + ]); + + //Assert::verificar + $request->assertSessionHasErrors(['question' => 'Are you sure it is a question? It should end with a question mark in the end.']); + assertDatabaseCount('questions', 0); + }); it('should have at least 10 characters', function () {