Add tag-by-slug posts endpoint for real tag pages
Deploy Backend / deploy (push) Successful in 2m43s
Deploy Backend / deploy (push) Successful in 2m43s
This commit is contained in:
1 parent
d4f41b9c2e
commit
21fa37af1f
3 files changed
+89
No files matched your search
@@ -2,7 +2,10 @@
|
||||
|
||||
namespace Tests\Feature\Blog;
|
||||
|
||||
use App\Models\Blog\Category;
|
||||
use App\Models\Blog\Post;
|
||||
use App\Models\Blog\Tag;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
@@ -52,4 +55,28 @@ class TagTest extends TestCase
|
||||
$response->assertStatus(200);
|
||||
$this->assertDatabaseMissing('tags', ['id' => $tag->id]);
|
||||
}
|
||||
|
||||
public function test_can_get_tag_with_posts_by_slug()
|
||||
{
|
||||
$category = Category::factory()->create();
|
||||
$user = User::factory()->create();
|
||||
$tag = Tag::factory()->create();
|
||||
$posts = Post::factory()->count(2)->create([
|
||||
'category_id' => $category->id,
|
||||
'author_id' => $user->id,
|
||||
]);
|
||||
|
||||
$tag->posts()->attach($posts->pluck('id'));
|
||||
|
||||
$response = $this->getJson("/api/blog/tags/by-slug/{$tag->slug}/posts");
|
||||
|
||||
$response
|
||||
->assertStatus(200)
|
||||
->assertJsonPath('tag.slug', $tag->slug)
|
||||
->assertJsonCount(2, 'posts')
|
||||
->assertJsonPath('meta.total', 2);
|
||||
|
||||
$this->getJson('/api/blog/tags/by-slug/does-not-exist/posts')
|
||||
->assertStatus(404);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user