Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

guillaumebriday/laravel-blog

1797 stars
1 code files
View guillaumebriday/laravel-blog on GitHub

tests/Feature/Api/V1/PostLikeTest.php

Open in GitHub
use App\Models\Post;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
 
class PostLikeTest extends TestCase
{
use RefreshDatabase;
 
public function testPostLike()
{
$post = Post::factory()->create();
 
$this->actingAsUser('api')
->json('POST', "/api/v1/posts/{$post->id}/likes")
->assertCreated();
 
$this->assertCount(1, $post->likes);
}
 
public function testPostDislike()
{
$user = $this->user();
$post = Post::factory()->create();
$post->likes()->create(['author_id' => $user->id]);
 
$this->actingAs($user, 'api')
->json('DELETE', "/api/v1/posts/{$post->id}/likes")
->assertOk();
 
$this->assertCount(0, $post->likes);
}
}

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.