Skip to content

Commit 83b4ae3

Browse files
committed
Resolve laravel-portugal#31 - An authenticated user can post an answer to a question
1 parent 01c5dc0 commit 83b4ae3

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

domains/Discussions/Database/Migrations/2020_10_19_175943_create_questions_answers_table.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
use \Domains\Discussions\Models\Question;
3+
use Domains\Discussions\Models\Question;
44
use Domains\Accounts\Models\User;
55
use Illuminate\Database\Migrations\Migration;
66
use Illuminate\Database\Schema\Blueprint;
@@ -17,8 +17,8 @@ public function up()
1717
{
1818
Schema::create('questions_answers', function (Blueprint $table) {
1919
$table->id();
20-
$table->foreignIdFor(Question::class, 'question_id');
2120
$table->foreignIdFor(User::class, 'author_id');
21+
$table->foreignIdFor(Question::class, 'question_id');
2222
$table->text('content');
2323
$table->timestampsTz();
2424
$table->softDeletesTz();

domains/Discussions/Tests/Feature/AnswersStoreTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function it_forbids_guests_to_store_answer(): void
6060
public function it_fails_to_store_answer_on_validation_errors(): void
6161
{
6262
$this->actingAs($this->user)
63-
->post(route('discussions.questions.answers', $this->question->id))
63+
->post(route('discussions.questions.answers', ['questionId' => $this->question->id]))
6464
->seeJsonStructure([
6565
'content',
6666
]);
@@ -74,7 +74,7 @@ public function it_fails_to_store_answer_on_invalid_question(): void
7474
];
7575

7676
$this->actingAs($this->user)
77-
->post(route('discussions.questions.answers', '2'), $payload)
77+
->post(route('discussions.questions.answers', ['questionId' => 1000]), $payload)
7878
->assertResponseStatus(Response::HTTP_NOT_FOUND);
7979
}
8080
}

0 commit comments

Comments
 (0)