Skip to content
This repository was archived by the owner on Sep 27, 2022. It is now read-only.

Commit 1ccd9ae

Browse files
author
Sandeesh
committed
Updated model factories to generated unique timestamps for articles and comments.
Updated article and comment tests for better verifying the order of items.
1 parent 1c89c6d commit 1ccd9ae

File tree

5 files changed

+39
-34
lines changed

5 files changed

+39
-34
lines changed

database/factories/ModelFactory.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,27 @@
2424

2525
$factory->define(App\Article::class, function (\Faker\Generator $faker) {
2626

27+
static $reduce = 999;
28+
2729
return [
2830
'title' => $faker->sentence,
2931
'description' => $faker->sentence(10),
3032
'body' => $faker->paragraphs($faker->numberBetween(1, 3), true),
33+
'created_at' => \Carbon\Carbon::now()->subSeconds($reduce--),
3134
];
3235
});
3336

3437
$factory->define(App\Comment::class, function (\Faker\Generator $faker) {
3538

3639
static $users;
40+
static $reduce = 999;
3741

3842
$users = $users ?: \App\User::all();
3943

4044
return [
4145
'body' => $faker->paragraph($faker->numberBetween(1, 5)),
4246
'user_id' => $users->random()->id,
47+
'created_at' => \Carbon\Carbon::now()->subSeconds($reduce--),
4348
];
4449
});
4550

tests/Feature/Api/ArticleFilterTest.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,19 @@ public function it_returns_the_articles_with_the_tag_along_with_correct_total_ar
4848
->assertJson([
4949
'articles' => [
5050
[
51-
'slug' => $articles[0]->slug,
52-
'title' => $articles[0]->title,
53-
'tagList' => $articles[0]->tagList,
51+
'slug' => $articles[2]->slug,
52+
'title' => $articles[2]->title,
53+
'tagList' => $articles[2]->tagList,
5454
],
5555
[
5656
'slug' => $articles[1]->slug,
5757
'title' => $articles[1]->title,
5858
'tagList' => $articles[1]->tagList,
5959
],
6060
[
61-
'slug' => $articles[2]->slug,
62-
'title' => $articles[2]->title,
63-
'tagList' => $articles[2]->tagList,
61+
'slug' => $articles[0]->slug,
62+
'title' => $articles[0]->title,
63+
'tagList' => $articles[0]->tagList,
6464
],
6565
],
6666
'articlesCount' => 3
@@ -99,8 +99,8 @@ public function it_returns_the_articles_by_the_author_along_with_correct_total_a
9999
->assertJson([
100100
'articles' => [
101101
[
102-
'slug' => $articles[0]->slug,
103-
'title' => $articles[0]->title,
102+
'slug' => $articles[2]->slug,
103+
'title' => $articles[2]->title,
104104
'author' => [
105105
'username' => $this->user->username
106106
]
@@ -113,8 +113,8 @@ public function it_returns_the_articles_by_the_author_along_with_correct_total_a
113113
]
114114
],
115115
[
116-
'slug' => $articles[2]->slug,
117-
'title' => $articles[2]->title,
116+
'slug' => $articles[0]->slug,
117+
'title' => $articles[0]->title,
118118
'author' => [
119119
'username' => $this->user->username
120120
]
@@ -158,8 +158,8 @@ public function it_returns_the_articles_favorited_by_the_user_along_with_correct
158158
->assertJson([
159159
'articles' => [
160160
[
161-
'slug' => $articles[0]->slug,
162-
'title' => $articles[0]->title,
161+
'slug' => $articles[4]->slug,
162+
'title' => $articles[4]->title,
163163
'author' => [
164164
'username' => $this->loggedInUser->username
165165
]
@@ -172,8 +172,8 @@ public function it_returns_the_articles_favorited_by_the_user_along_with_correct
172172
]
173173
],
174174
[
175-
'slug' => $articles[4]->slug,
176-
'title' => $articles[4]->title,
175+
'slug' => $articles[0]->slug,
176+
'title' => $articles[0]->title,
177177
'author' => [
178178
'username' => $this->loggedInUser->username
179179
]

tests/Feature/Api/ArticleReadTest.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ public function it_returns_the_articles_and_correct_total_article_count()
3232
->assertJson([
3333
'articles' => [
3434
[
35-
'slug' => $articles[0]->slug,
36-
'title' => $articles[0]->title,
37-
'description' => $articles[0]->description,
38-
'body' => $articles[0]->body,
39-
'tagList' => $articles[0]->tagList,
40-
'createdAt' => $articles[0]->created_at->toAtomString(),
41-
'updatedAt' => $articles[0]->updated_at->toAtomString(),
35+
'slug' => $articles[1]->slug,
36+
'title' => $articles[1]->title,
37+
'description' => $articles[1]->description,
38+
'body' => $articles[1]->body,
39+
'tagList' => $articles[1]->tagList,
40+
'createdAt' => $articles[1]->created_at->toAtomString(),
41+
'updatedAt' => $articles[1]->updated_at->toAtomString(),
4242
'favorited' => false,
4343
'favoritesCount' => 0,
4444
'author' => [
@@ -49,8 +49,8 @@ public function it_returns_the_articles_and_correct_total_article_count()
4949
]
5050
],
5151
[
52-
'slug' => $articles[1]->slug,
53-
'title' => $articles[1]->title,
52+
'slug' => $articles[0]->slug,
53+
'title' => $articles[0]->title,
5454
]
5555
],
5656
'articlesCount' => 2

tests/Feature/Api/CommentTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,13 @@ public function it_returns_all_the_comments_of_the_article()
6767
->assertJson([
6868
'comments' => [
6969
[
70-
'body' => $comments[0]['body'],
70+
'body' => $comments[1]['body'],
7171
'author' => [
7272
'username' => $this->user->username
7373
]
7474
],
7575
[
76-
'body' => $comments[1]['body'],
76+
'body' => $comments[0]['body'],
7777
'author' => [
7878
'username' => $this->user->username
7979
]

tests/Feature/Api/FeedTest.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ public function it_returns_articles_of_users_followed_by_the_logged_in_user()
3434
->assertJson([
3535
'articles' => [
3636
[
37-
'slug' => $articles[0]->slug,
38-
'title' => $articles[0]->title,
39-
'description' => $articles[0]->description,
40-
'body' => $articles[0]->body,
41-
'tagList' => $articles[0]->tagList,
42-
'createdAt' => $articles[0]->created_at->toAtomString(),
43-
'updatedAt' => $articles[0]->updated_at->toAtomString(),
37+
'slug' => $articles[1]->slug,
38+
'title' => $articles[1]->title,
39+
'description' => $articles[1]->description,
40+
'body' => $articles[1]->body,
41+
'tagList' => $articles[1]->tagList,
42+
'createdAt' => $articles[1]->created_at->toAtomString(),
43+
'updatedAt' => $articles[1]->updated_at->toAtomString(),
4444
'favorited' => false,
4545
'favoritesCount' => 0,
4646
'author' => [
@@ -51,8 +51,8 @@ public function it_returns_articles_of_users_followed_by_the_logged_in_user()
5151
]
5252
],
5353
[
54-
'slug' => $articles[1]->slug,
55-
'title' => $articles[1]->title,
54+
'slug' => $articles[0]->slug,
55+
'title' => $articles[0]->title,
5656
]
5757
],
5858
'articlesCount' => 2

0 commit comments

Comments
 (0)