Skip to content
This repository was archived by the owner on Jun 29, 2021. It is now read-only.

Commit ab99eb4

Browse files
committed
Resolve conflicts + test tweaks
1 parent 5bcf0a1 commit ab99eb4

File tree

2 files changed

+28
-12
lines changed

2 files changed

+28
-12
lines changed

domains/Discussions/Controllers/QuestionsUpdateController.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,21 @@
66
use Domains\Discussions\Models\Question;
77
use Illuminate\Http\Request;
88
use Illuminate\Http\Response;
9-
use Illuminate\Support\Facades\Auth;
109

1110
class QuestionsUpdateController extends Controller
1211
{
12+
private Question $questions;
13+
14+
public function __construct(Question $questions)
15+
{
16+
$this->questions = $questions;
17+
}
18+
1319
public function __invoke(int $questionId, Request $request): Response
1420
{
15-
$question = Question::findOrFail($questionId);
21+
$question = $this->questions->newModelQuery()->findOrFail($questionId);
1622

17-
if (Auth::user()->cannot('update', $question)) {
23+
if ($request->user()->cannot('update', $question)) {
1824
abort(Response::HTTP_FORBIDDEN);
1925
}
2026

domains/Discussions/Tests/Feature/QuestionsUpdateTest.php

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@ public function it_updates_questions(): void
4040
];
4141

4242
$this->actingAs($this->user);
43-
$response = $this->call('PATCH', '/questions/' . $this->question->id, $payload);
43+
$response = $this->call(
44+
'PATCH',
45+
route('discussions.questions.update', ['questionId' => $this->question->id]),
46+
$payload
47+
);
4448
self::assertTrue($response->isEmpty());
4549

4650
$this->seeInDatabase('questions', [
@@ -56,7 +60,7 @@ public function it_updates_questions(): void
5660
public function it_fails_to_update_if_title_is_missing(): void
5761
{
5862
$this->actingAs($this->user);
59-
$this->patch('/questions/' . $this->question->id)
63+
$this->patch(route('discussions.questions.update', ['questionId' => $this->question->id]))
6064
->seeJsonStructure([
6165
'title',
6266
]);
@@ -66,9 +70,13 @@ public function it_fails_to_update_if_title_is_missing(): void
6670
public function it_keeps_previous_description_if_none_is_sent(): void
6771
{
6872
$this->actingAs($this->user);
69-
$response = $this->call('PATCH', '/questions/' . $this->question->id, [
70-
'title' => $this->faker->title,
71-
]);
73+
$response = $this->call(
74+
'PATCH',
75+
route('discussions.questions.update', ['questionId' => $this->question->id]),
76+
[
77+
'title' => $this->faker->title,
78+
]
79+
);
7280

7381
self::assertTrue($response->isEmpty());
7482
self::assertEquals($this->question->description, $this->question->refresh()->description);
@@ -78,9 +86,11 @@ public function it_keeps_previous_description_if_none_is_sent(): void
7886
public function it_forbids_non_owner_to_update_questions(): void
7987
{
8088
$this->actingAs(UserFactory::new()->make()); // make another user
81-
$this->patch('/questions/' . $this->question->id, [
82-
'title' => $this->faker->title,
83-
])
84-
->assertResponseStatus(Response::HTTP_FORBIDDEN);
89+
$this->patch(
90+
route('discussions.questions.update', ['questionId' => $this->question->id]),
91+
[
92+
'title' => $this->faker->title,
93+
]
94+
)->assertResponseStatus(Response::HTTP_FORBIDDEN);
8595
}
8696
}

0 commit comments

Comments
 (0)