Defer profile featured artworks
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Artwork;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Inertia\Testing\AssertableInertia;
|
||||
|
||||
function profileFeaturedFixture(): array
|
||||
{
|
||||
$user = User::factory()->create(['username' => 'featuredprofile']);
|
||||
$older = Artwork::factory()->for($user)->create([
|
||||
'title' => 'Older featured artwork',
|
||||
'published_at' => now()->subDays(2),
|
||||
]);
|
||||
$newer = Artwork::factory()->for($user)->create([
|
||||
'title' => 'Newer featured artwork',
|
||||
'published_at' => now()->subDay(),
|
||||
]);
|
||||
|
||||
DB::table('artwork_features')->insert([
|
||||
[
|
||||
'artwork_id' => $older->id,
|
||||
'label' => 'Older',
|
||||
'is_active' => true,
|
||||
'featured_at' => now()->subDay(),
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
],
|
||||
[
|
||||
'artwork_id' => $newer->id,
|
||||
'label' => 'Newer',
|
||||
'is_active' => true,
|
||||
'featured_at' => now(),
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
],
|
||||
]);
|
||||
|
||||
return [$user, $older, $newer];
|
||||
}
|
||||
|
||||
it('does not include featured artworks in the default posts SSR payload', function () {
|
||||
[$user] = profileFeaturedFixture();
|
||||
|
||||
$this->get('/@' . $user->username)
|
||||
->assertOk()
|
||||
->assertInertia(fn (AssertableInertia $page) => $page
|
||||
->component('Profile/ProfileShow')
|
||||
->where('initialTab', 'posts')
|
||||
->where('featuredArtworks', null));
|
||||
});
|
||||
|
||||
it('keeps featured artworks in the direct artworks SSR payload', function () {
|
||||
[$user, $older, $newer] = profileFeaturedFixture();
|
||||
|
||||
$this->get('/@' . $user->username . '/artworks')
|
||||
->assertOk()
|
||||
->assertInertia(fn (AssertableInertia $page) => $page
|
||||
->component('Profile/ProfileShow')
|
||||
->where('initialTab', 'artworks')
|
||||
->where('featuredArtworks.0.id', $newer->id)
|
||||
->where('featuredArtworks.1.id', $older->id));
|
||||
});
|
||||
|
||||
it('returns the same ordered featured collection from the lazy endpoint', function () {
|
||||
[$user, $older, $newer] = profileFeaturedFixture();
|
||||
|
||||
$response = $this->getJson('/api/profile/' . $user->username . '/featured-artworks');
|
||||
|
||||
$response->assertOk()
|
||||
->assertJsonPath('data.0.id', $newer->id)
|
||||
->assertJsonPath('data.1.id', $older->id)
|
||||
->assertJsonPath('data.0.label', 'Newer');
|
||||
});
|
||||
|
||||
it('does not track a profile view for the lazy featured endpoint', function () {
|
||||
[$user] = profileFeaturedFixture();
|
||||
$before = (int) ($user->profile_views_count ?? 0);
|
||||
|
||||
$this->getJson('/api/profile/' . $user->username . '/featured-artworks')->assertOk();
|
||||
|
||||
expect((int) $user->fresh()->profile_views_count)->toBe($before);
|
||||
});
|
||||
|
||||
it('returns not found for an unknown featured-artworks profile', function () {
|
||||
$this->getJson('/api/profile/missing-featured-user/featured-artworks')
|
||||
->assertNotFound();
|
||||
});
|
||||
Reference in New Issue
Block a user