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();
|
||||
});
|
||||
@@ -95,7 +95,7 @@ it('exposes normalized world history on public profile pages', function (): void
|
||||
'awarded_at' => now()->subHour(),
|
||||
]);
|
||||
|
||||
$this->get(route('profile.show', ['username' => strtolower((string) $creator->username)]))
|
||||
$this->get(route('profile.tab', ['username' => strtolower((string) $creator->username), 'tab' => 'worlds']))
|
||||
->assertOk()
|
||||
->assertInertia(fn (AssertableInertia $page) => $page
|
||||
->component('Profile/ProfileShow')
|
||||
@@ -161,7 +161,7 @@ it('filters stale public world rewards while preserving owner-only context count
|
||||
'status' => WorldSubmission::STATUS_PENDING,
|
||||
]);
|
||||
|
||||
$this->get(route('profile.show', ['username' => strtolower((string) $creator->username)]))
|
||||
$this->get(route('profile.tab', ['username' => strtolower((string) $creator->username), 'tab' => 'worlds']))
|
||||
->assertOk()
|
||||
->assertInertia(fn (AssertableInertia $page) => $page
|
||||
->component('Profile/ProfileShow')
|
||||
@@ -170,7 +170,7 @@ it('filters stale public world rewards while preserving owner-only context count
|
||||
->where('worldHistory.owner_context', null));
|
||||
|
||||
$this->actingAs($creator)
|
||||
->get(route('profile.show', ['username' => strtolower((string) $creator->username)]))
|
||||
->get(route('profile.tab', ['username' => strtolower((string) $creator->username), 'tab' => 'worlds']))
|
||||
->assertOk()
|
||||
->assertInertia(fn (AssertableInertia $page) => $page
|
||||
->component('Profile/ProfileShow')
|
||||
@@ -223,4 +223,4 @@ it('supports the canonical worlds profile tab route', function (): void {
|
||||
->where('profileTabUrls.worlds', url('/@' . strtolower((string) $creator->username) . '/worlds'))
|
||||
->where('worldHistory.summary.available', true)
|
||||
->where('worldHistory.entries.0.primary_recognition.key', 'featured'));
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user