feat: get my meal posts

This commit is contained in:
2026-05-21 10:09:33 +02:00
parent 6d0f1591fa
commit 1a53ae3f05
6 changed files with 116 additions and 8 deletions
+37
View File
@@ -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,
]);
});