-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathArticleReadTest.php
executable file
·65 lines (55 loc) · 2.25 KB
/
ArticleReadTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
class ArticleReadTest extends TestCase
{
/** @test */
public function it_returns_the_articles_and_correct_total_article_count()
{
$articles = $this->user->articles()->saveMany(factory(\App\Models\Article::class)->times(2)->make());
$response = $this->json('GET', '/api/articles');
$response->assertResponseOk();
$response->seeJsonStructure([
'articles' => [
[
'slug',
'title',
'description',
'body',
'tagList',
'createdAt',
'updatedAt',
'favorited',
'favoritesCount',
'author' => [
'username',
'bio',
'image',
'following',
]
],
[
'slug',
'title',
]
],
'articlesCount'
]);
// $response->seeJsonContains(['articlesCount' => 2]);
$response->seeJsonContains(['slug' => $articles[0]->slug]);
$response->seeJsonContains(['slug' => $articles[1]->slug]);
$response->seeJsonContains(['createdAt' => $articles[1]->created_at->toAtomString()]);
$response->seeJsonContains(['username' => $this->user->username]);
}
/** @test */
public function it_returns_the_article_by_slug_if_valid_and_not_found_error_if_invalid()
{
$article = $this->user->articles()->save(factory(\App\Models\Article::class)->make());
$response = $this->json('GET', '/api/articles');
$response->assertResponseOk();
$response->seeJsonContains(['slug' => $article->slug]);
$response->seeJsonContains(['title' => $article->title]);
$response->seeJsonContains(['createdAt' => $article->created_at->toAtomString()]);
$response->seeJsonContains(['username' => $this->user->username]);
$response = $this->json('GET', '/api/articles/randominvalidslug');
$response->assertResponseStatus(404);
}
}