Defer profile world history until needed
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
use App\Models\User;
|
||||
use App\Services\Profile\WorldProfileHistoryService;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Inertia\Testing\AssertableInertia;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
it('omits the world history producer from the default Posts SSR payload', function (): void {
|
||||
$user = User::factory()->create(['username' => 'lazyworlds']);
|
||||
DB::flushQueryLog();
|
||||
DB::enableQueryLog();
|
||||
|
||||
$this->get('/@' . $user->username)
|
||||
->assertOk()
|
||||
->assertInertia(fn (AssertableInertia $page) => $page
|
||||
->where('initialTab', 'posts')
|
||||
->where('worldHistory', null));
|
||||
|
||||
$historyQueries = collect(DB::getQueryLog())->pluck('query')->filter(function (string $query): bool {
|
||||
$query = strtolower($query);
|
||||
|
||||
return str_contains($query, 'world_submissions')
|
||||
|| str_contains($query, 'group_challenge_outcomes')
|
||||
|| str_contains($query, 'world_relations');
|
||||
});
|
||||
|
||||
expect($historyQueries)->toBeEmpty();
|
||||
});
|
||||
|
||||
it('keeps world history in direct Worlds and Achievements SSR payloads', function (string $tab): void {
|
||||
$user = User::factory()->create(['username' => 'ssr' . $tab]);
|
||||
|
||||
$this->get('/@' . $user->username . '/' . $tab)
|
||||
->assertOk()
|
||||
->assertInertia(fn (AssertableInertia $page) => $page
|
||||
->where('initialTab', $tab)
|
||||
->has('worldHistory.summary')
|
||||
->has('worldHistory.entries'));
|
||||
})->with(['worlds', 'achievements']);
|
||||
|
||||
it('returns the exact public service payload without tracking a profile view', function (): void {
|
||||
$user = User::factory()->create(['username' => 'lazyworldapi']);
|
||||
$expected = app(WorldProfileHistoryService::class)->publicPayloadForUser($user);
|
||||
$before = (int) ($user->profile_views_count ?? 0);
|
||||
|
||||
$this->getJson('/api/profile/' . $user->username . '/world-history')
|
||||
->assertOk()
|
||||
->assertJson($expected);
|
||||
|
||||
expect((int) $user->fresh()->profile_views_count)->toBe($before);
|
||||
});
|
||||
|
||||
it('returns owner context only to the profile owner', function (): void {
|
||||
$user = User::factory()->create(['username' => 'ownerworldapi']);
|
||||
$other = User::factory()->create(['username' => 'otherworldapi']);
|
||||
|
||||
$this->actingAs($user)
|
||||
->getJson('/api/profile/' . $user->username . '/world-history')
|
||||
->assertOk()
|
||||
->assertJsonPath('owner_context.pending_submissions', 0);
|
||||
|
||||
$this->actingAs($other)
|
||||
->getJson('/api/profile/' . $user->username . '/world-history')
|
||||
->assertOk()
|
||||
->assertJsonPath('owner_context', null);
|
||||
});
|
||||
|
||||
it('returns not found for an unknown world history profile', function (): void {
|
||||
$this->getJson('/api/profile/missing-world-history/world-history')->assertNotFound();
|
||||
});
|
||||
Reference in New Issue
Block a user