feat: get my meal posts
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
use App\Models\MealPosts;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
it('returns only the authenticated user meal posts', function () {
|
||||
$user = User::factory()->create();
|
||||
$otherUser = User::factory()->create();
|
||||
|
||||
$oldMealPost = MealPosts::factory()->for($user, 'user')->create([
|
||||
'eaten_at' => '2026-05-18 12:00:00',
|
||||
]);
|
||||
$latestMealPost = MealPosts::factory()->for($user, 'user')->create([
|
||||
'eaten_at' => '2026-05-19 12:00:00',
|
||||
]);
|
||||
$otherMealPost = MealPosts::factory()->for($otherUser, 'user')->create([
|
||||
'eaten_at' => '2026-05-20 12:00:00',
|
||||
]);
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$response = $this->getJson('/api/me/meal-posts');
|
||||
|
||||
$response
|
||||
->assertOk()
|
||||
->assertJsonCount(2, 'data')
|
||||
->assertJsonPath('data.0.id', $latestMealPost->id)
|
||||
->assertJsonPath('data.1.id', $oldMealPost->id)
|
||||
->assertJsonMissing([
|
||||
'id' => $otherMealPost->id,
|
||||
]);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user