@@ -21,13 +21,18 @@ protected function setUp(): void
21
21
parent ::setUp ();
22
22
23
23
$ this ->user = UserFactory::new ()->create ();
24
- QuestionFactory::times (20 )->create ();
24
+ QuestionFactory::times (10 )->create ();
25
25
}
26
26
27
27
/** @test */
28
- public function it_possible_to_see_a_question (): void
28
+ public function it_list_non_deleted_question (): void
29
29
{
30
- $ response = $ this ->get (route ('discussions.questions.index ' ))
30
+ $ deleteQuestion = QuestionFactory::new ([
31
+ 'deleted_at ' => Carbon::now ()->toDateString (),
32
+ ])
33
+ ->create ();
34
+
35
+ $ this ->json ('GET ' , route ('discussions.questions.index ' ))
31
36
->seeJsonStructure ([
32
37
'data ' => [
33
38
[
@@ -38,16 +43,23 @@ public function it_possible_to_see_a_question(): void
38
43
'author ' ,
39
44
'created_at ' ,
40
45
'updated_at ' ,
41
- 'deleted_at '
46
+ 'deleted_at ' ,
42
47
]
43
- ]
48
+ ],
49
+ 'links ' => [
50
+ 'first ' , 'prev ' , 'next ' , 'last ' ,
51
+ ],
52
+ ])
53
+ ->seeJsonDoesntContains ([
54
+ 'email ' => $ deleteQuestion ->author ->email ,
55
+ ])
56
+ ->seeJsonContains ([
57
+ 'to ' => 10 ,
44
58
]);
45
-
46
- self ::assertEquals (15 , count ($ response ->decodedJsonResponse ()['data ' ]));
47
59
}
48
60
49
61
/** @test */
50
- public function it_blocked_guest_for_many_attempts (): void
62
+ public function it_blocks_guest_for_many_attempts (): void
51
63
{
52
64
for ($ attempt = 0 ; $ attempt < 30 ; ++$ attempt ) {
53
65
$ this ->get (route ('discussions.questions.index ' ))
@@ -59,7 +71,7 @@ public function it_blocked_guest_for_many_attempts(): void
59
71
}
60
72
61
73
/** @test */
62
- public function it_not_blocked_authenticated_user_for_many_attempts (): void
74
+ public function it_not_blocks_authenticated_user_for_many_attempts (): void
63
75
{
64
76
$ this ->actingAs ($ this ->user );
65
77
@@ -72,81 +84,108 @@ public function it_not_blocked_authenticated_user_for_many_attempts(): void
72
84
}
73
85
74
86
/** @test */
75
- public function it_includes_paginate (): void
87
+ public function it_navigates_to_next_page (): void
76
88
{
77
- $ response = $ this ->get (route ('discussions.questions.index ' ))
78
- ->seeJsonStructure ([
79
- 'data ' =>
80
- 'links ' ,
89
+ $ this ->json ('GET ' , route ('discussions.questions.index ' , [
90
+ 'page ' => 2 ,
91
+ ]))
92
+ ->seeJsonContains ([
93
+ 'current_page ' => 2 ,
81
94
]);
82
-
83
- $ response ->assertResponseOk ();
84
95
}
85
96
86
97
/** @test */
87
- public function it_supports_pagination_navigation (): void
88
- {
89
- $ response = $ this ->get (route ('discussions.questions.index ' , ['page ' => 2 ]));
90
- $ response ->assertResponseOk ();
91
-
92
- self ::assertEquals (2 , $ response ->decodedJsonResponse ()['meta ' ]['current_page ' ]);
93
- }
94
-
95
- /** @test */
96
- public function it_searchable_by_author (): void
98
+ public function it_search_by_author (): void
97
99
{
98
100
$ user = UserFactory::new ()->create ();
99
- QuestionFactory::new (['author_id ' => $ user ->id ])->create ();
100
-
101
- $ response = $ this ->get (route ('discussions.questions.index ' , ['author ' => $ user ->id ]));
102
-
103
- self ::assertEquals (1 , count ($ response ->decodedJsonResponse ()['data ' ]));
101
+ QuestionFactory::new ([
102
+ 'author_id ' => $ user ->id ,
103
+ ])
104
+ ->count (3 )
105
+ ->create ();
106
+
107
+ $ this ->json ('GET ' , route ('discussions.questions.index ' , [
108
+ 'author ' => $ user ->id ,
109
+ ]))
110
+ ->seeJsonContains ([
111
+ 'id ' => $ user ->id ,
112
+ ])
113
+ ->seeJsonContains ([
114
+ 'to ' => 3 ,
115
+ ]);
104
116
}
105
117
106
118
/** @test */
107
- public function it_searchable_by_title (): void
119
+ public function it_search_by_title (): void
108
120
{
109
- QuestionFactory::new (['title ' => 'LARAVEL-PT ' ])->create ();
110
- QuestionFactory::new (['title ' => 'laravel-pt ' ])->create ();
111
-
112
- $ response = $ this ->get (route ('discussions.questions.index ' , ['title ' => 'LArAvEL-pt ' ]));
113
-
114
- self ::assertEquals (2 , count ($ response ->decodedJsonResponse ()['data ' ]));
121
+ QuestionFactory::new ([
122
+ 'title ' => 'LARAVEL-PT ' ,
123
+ ])->create ();
124
+ QuestionFactory::new ([
125
+ 'title ' => 'laravel-Pt ' ,
126
+ ])
127
+ ->create ();
128
+
129
+ $ this ->json ('GET ' , route ('discussions.questions.index ' , [
130
+ 'title ' => 'LArAvEL-pT ' ,
131
+ ]))
132
+ ->seeJsonContains ([
133
+ 'to ' => 2 ,
134
+ ]);
115
135
}
116
136
117
137
/** @test */
118
- public function it_searchable_by_created_at (): void
138
+ public function it_search_by_created_date (): void
119
139
{
120
- QuestionFactory::new (['created_at ' => Carbon::now ()->subYears (2 )->toDateString ()])->create ();
121
- QuestionFactory::new (['created_at ' => Carbon::now ()->subYears (3 )->toDateString ()])->create ();
122
-
123
- $ response = $ this ->get (route ('discussions.questions.index ' , [
140
+ QuestionFactory::new ([
141
+ 'created_at ' => Carbon::now ()->subYears (2 )->toDateString (),
142
+ ])
143
+ ->create ();
144
+ QuestionFactory::new ([
145
+ 'created_at ' => Carbon::now ()->subYears (3 )->toDateString (),
146
+ ])
147
+ ->create ();
148
+
149
+ $ this ->json ('GET ' , route ('discussions.questions.index ' , [
124
150
'created[from] ' => Carbon::now ()->subMonth ()->subYears (2 )->toDateString (),
125
151
'created[to] ' => Carbon::now ()->addMonth ()->subYears (2 )->toDateString ()
126
- ]));
127
- self ::assertEquals (1 , count ($ response ->decodedJsonResponse ()['data ' ]));
152
+ ]))
153
+ ->seeJsonContains ([
154
+ 'to ' => 1 ,
155
+ ]);
128
156
129
- $ response = $ this ->get ( route ('discussions.questions.index ' , [
157
+ $ this ->json ( ' GET ' , route ('discussions.questions.index ' , [
130
158
'created[from] ' => Carbon::now ()->subMonth ()->subYears (3 )->toDateString (),
131
159
'created[to] ' => Carbon::now ()->addMonth ()->subYears (2 )->toDateString ()
132
- ]));
133
- self ::assertEquals (2 , count ($ response ->decodedJsonResponse ()['data ' ]));
160
+ ]))
161
+ ->seeJsonContains ([
162
+ 'to ' => 2 ,
163
+ ]);
134
164
}
135
165
136
166
/** @test */
137
- public function it_searchable_by_resolved (): void
167
+ public function it_search_by_resolved (): void
138
168
{
139
- QuestionFactory::new (['resolved_at ' => Carbon::now ()->toDateString ()])->create ();
140
-
141
- $ response = $ this ->get (route ('discussions.questions.index ' , ['resolved ' => true ]));
142
-
143
- self ::assertEquals (1 , count ($ response ->decodedJsonResponse ()['data ' ]));
169
+ QuestionFactory::new ([
170
+ 'resolved_at ' => Carbon::now ()->toDateString (),
171
+ ])
172
+ ->count (5 )
173
+ ->create ();
174
+
175
+ $ this ->json ('GET ' , route ('discussions.questions.index ' , [
176
+ 'resolved ' => true ,
177
+ ]))
178
+ ->seeJsonContains ([
179
+ 'to ' => 5 ,
180
+ ]);
144
181
}
145
182
146
183
/** @test */
147
184
public function it_fails_by_validations (): void
148
185
{
149
- $ this ->get (route ('discussions.questions.index ' , ['author ' => 'author ' ]))
186
+ $ this ->get (route ('discussions.questions.index ' , [
187
+ 'author ' => 'author ' ,
188
+ ]))
150
189
->assertResponseStatus (Response::HTTP_UNPROCESSABLE_ENTITY );
151
190
152
191
$ this ->get (route ('discussions.questions.index ' , ['resolved ' => 12332 ]))
0 commit comments