feat: localize guest endpoints and caching
This commit is contained in:
66
tests/Feature/Api/Event/EventAchievementsLocaleTest.php
Normal file
66
tests/Feature/Api/Event/EventAchievementsLocaleTest.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Api\Event;
|
||||
|
||||
use App\Models\Emotion;
|
||||
use App\Models\Event;
|
||||
use App\Models\Photo;
|
||||
use App\Models\Task;
|
||||
use App\Services\EventJoinTokenService;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class EventAchievementsLocaleTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_achievements_endpoint_returns_locale_specific_payload(): void
|
||||
{
|
||||
config(['app.supported_locales' => ['de', 'en']]);
|
||||
|
||||
$event = Event::factory()->create([
|
||||
'status' => 'published',
|
||||
'default_locale' => 'de',
|
||||
]);
|
||||
|
||||
$token = app(EventJoinTokenService::class)
|
||||
->createToken($event, ['label' => 'achievements'])
|
||||
->plain_token;
|
||||
|
||||
$emotion = Emotion::factory()->create([
|
||||
'name' => ['de' => 'Freude', 'en' => 'Joy'],
|
||||
]);
|
||||
|
||||
$task = Task::factory()->create([
|
||||
'tenant_id' => $event->tenant_id,
|
||||
'title' => ['de' => 'Feuerring', 'en' => 'Fire Ring'],
|
||||
'description' => ['de' => 'DE Beschr', 'en' => 'EN Desc'],
|
||||
'example_text' => ['de' => 'DE Example', 'en' => 'EN Example'],
|
||||
]);
|
||||
|
||||
Photo::factory()->for($event)->create([
|
||||
'tenant_id' => $event->tenant_id,
|
||||
'task_id' => $task->id,
|
||||
'emotion_id' => $emotion->id,
|
||||
'likes_count' => 42,
|
||||
'guest_name' => 'LocaleTester',
|
||||
]);
|
||||
|
||||
$responseEn = $this->withHeaders(['X-Device-Id' => 'LocaleTester'])
|
||||
->getJson("/api/v1/events/{$token}/achievements?locale=en&guest_name=LocaleTester");
|
||||
|
||||
$responseEn->assertOk();
|
||||
$responseEn->assertHeader('X-Content-Locale', 'en');
|
||||
$responseEn->assertJsonPath('highlights.top_photo.task', 'Fire Ring');
|
||||
$responseEn->assertJsonPath('highlights.trending_emotion.name', 'Joy');
|
||||
|
||||
$etag = $responseEn->headers->get('ETag');
|
||||
$this->assertNotEmpty($etag);
|
||||
|
||||
$this->withHeaders([
|
||||
'X-Device-Id' => 'LocaleTester',
|
||||
'If-None-Match' => $etag,
|
||||
])->getJson("/api/v1/events/{$token}/achievements?locale=en&guest_name=LocaleTester")
|
||||
->assertStatus(304);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user