File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed
Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change 66use Illuminate \Foundation \Testing \WithFaker ;
77use Illuminate \Foundation \Testing \RefreshDatabase ;
88use App \BlogPost ;
9+ use App \Comment ;
910
1011class ApiPostCommentsTest extends TestCase
1112{
@@ -23,4 +24,40 @@ public function testNewBlogPostDoesNotHaveComments()
2324 ->assertJsonStructure (['data ' , 'links ' , 'meta ' ])
2425 ->assertJsonCount (0 , 'data ' );
2526 }
27+
28+ public function testBlogPostHas10Comments ()
29+ {
30+ factory (BlogPost::class)->create ([
31+ 'user_id ' => $ this ->user ()->id
32+ ])->each (function (BlogPost $ post ) {
33+ $ post ->comments ()->saveMany (
34+ factory (Comment::class, 10 )->make ([
35+ 'user_id ' => $ this ->user ()->id
36+ ])
37+ );
38+ });
39+
40+ $ response = $ this ->json ('GET ' , 'api/v1/posts/2/comments ' );
41+
42+ $ response ->assertStatus (200 )
43+ ->assertJsonStructure (
44+ [
45+ 'data ' => [
46+ '* ' => [
47+ 'id ' ,
48+ 'contnt ' ,
49+ 'created_at ' ,
50+ 'updated_at ' ,
51+ 'user ' => [
52+ 'id ' ,
53+ 'name '
54+ ]
55+ ]
56+ ],
57+ 'links ' ,
58+ 'meta '
59+ ]
60+ )
61+ ->assertJsonCount (10 , 'data ' );
62+ }
2663}
You can’t perform that action at this time.
0 commit comments