Optimize academy

This commit is contained in:
2026-06-09 13:16:01 +02:00
parent f89ee937c0
commit 5af95f6533
109 changed files with 6862 additions and 719 deletions

View File

@@ -1654,6 +1654,61 @@ final class AcademyFeatureTest extends TestCase
}
}
public function test_filled_examples_are_visible_only_to_pro_and_staff_users(): void
{
$prompt = AcademyPromptTemplate::query()->create([
'title' => 'Filled Example Prompt',
'slug' => 'filled-example-prompt',
'excerpt' => 'Prompt with pro-only filled examples.',
'prompt' => 'Base prompt body available to free users.',
'difficulty' => 'beginner',
'access_level' => 'free',
'filled_examples' => [[
'title' => 'Mountain lake sunrise',
'description' => 'A filled example for scenic output.',
'placeholder_values' => [
'LOCATION' => 'Lake Bled',
],
'prompt' => 'Create a sunrise landscape of Lake Bled with calm reflections and alpine light.',
'negative_prompt' => 'muddy water, flat light',
]],
'active' => true,
'published_at' => now()->subMinute(),
]);
$this->get(route('academy.prompts.show', ['slug' => $prompt->slug]))
->assertOk()
->assertInertia(fn (AssertableInertia $page) => $page
->where('item.has_filled_examples', true)
->where('item.can_access_filled_examples', false)
->where('item.filled_examples', []));
$creator = User::factory()->create(['role' => 'academy_creator']);
$this->actingAs($creator)
->get(route('academy.prompts.show', ['slug' => $prompt->slug]))
->assertOk()
->assertInertia(fn (AssertableInertia $page) => $page
->where('item.has_filled_examples', true)
->where('item.can_access_filled_examples', false)
->where('item.filled_examples', []));
foreach ([
User::factory()->create(['role' => 'academy_pro']),
User::factory()->create(['role' => 'admin']),
] as $user) {
$this->actingAs($user)
->get(route('academy.prompts.show', ['slug' => $prompt->slug]))
->assertOk()
->assertInertia(fn (AssertableInertia $page) => $page
->where('item.has_filled_examples', true)
->where('item.can_access_filled_examples', true)
->where('item.filled_examples.0.title', 'Mountain lake sunrise')
->where('item.filled_examples.0.placeholder_values.LOCATION', 'Lake Bled')
->where('item.filled_examples.0.prompt', 'Create a sunrise landscape of Lake Bled with calm reflections and alpine light.'));
}
}
public function test_challenge_routes_are_hidden_when_challenges_are_disabled(): void
{
config(['academy.challenges_enabled' => false]);