Add tests for featured thumbnail generation; apply Pint formatting and related edits
This commit is contained in:
@@ -5,13 +5,16 @@ declare(strict_types=1);
|
||||
namespace Tests\Feature\Academy;
|
||||
|
||||
use App\Http\Middleware\ConditionalValidateCsrfToken;
|
||||
use App\Http\Middleware\HandleInertiaRequests;
|
||||
use App\Models\AcademyAiComparisonResult;
|
||||
use App\Models\AcademyChallenge;
|
||||
use App\Models\AcademyChallengeSubmission;
|
||||
use App\Models\AcademyLesson;
|
||||
use App\Models\AcademyLessonBlock;
|
||||
use App\Models\AcademyPromptTemplate;
|
||||
use App\Models\Artwork;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Inertia\Testing\AssertableInertia;
|
||||
use Tests\TestCase;
|
||||
@@ -139,8 +142,8 @@ final class AcademyFeatureTest extends TestCase
|
||||
->where('item.prompt', null)
|
||||
->where('item.negative_prompt', null));
|
||||
|
||||
$version = app(\App\Http\Middleware\HandleInertiaRequests::class)
|
||||
->version(\Illuminate\Http\Request::create(route('academy.prompts.show', ['slug' => $prompt->slug]), 'GET'));
|
||||
$version = app(HandleInertiaRequests::class)
|
||||
->version(Request::create(route('academy.prompts.show', ['slug' => $prompt->slug]), 'GET'));
|
||||
|
||||
$this->withHeaders([
|
||||
'X-Inertia' => 'true',
|
||||
@@ -180,6 +183,96 @@ final class AcademyFeatureTest extends TestCase
|
||||
->where('item.prompt', 'VISIBLE PREMIUM PROMPT'));
|
||||
}
|
||||
|
||||
public function test_public_lesson_payload_includes_active_ai_comparison_block_and_hides_inactive_results(): void
|
||||
{
|
||||
$lesson = AcademyLesson::query()->create([
|
||||
'title' => 'Free Lesson With Comparison',
|
||||
'slug' => 'free-lesson-with-comparison',
|
||||
'excerpt' => 'Visible to guests.',
|
||||
'content' => 'Free lesson content',
|
||||
'difficulty' => 'beginner',
|
||||
'access_level' => 'free',
|
||||
'lesson_type' => 'article',
|
||||
'active' => true,
|
||||
'published_at' => now()->subMinute(),
|
||||
]);
|
||||
$block = AcademyLessonBlock::query()->create([
|
||||
'lesson_id' => $lesson->id,
|
||||
'type' => 'ai_comparison',
|
||||
'title' => 'Same Prompt, Different AI Models',
|
||||
'payload' => [
|
||||
'title' => 'Same Prompt, Different AI Models',
|
||||
'intro' => 'We used the same prompt in multiple tools.',
|
||||
'prompt' => 'A peaceful fantasy forest wallpaper.',
|
||||
'negative_prompt' => 'text, watermark',
|
||||
'aspect_ratio' => '16:9',
|
||||
'criteria' => ['Composition', 'Lighting'],
|
||||
],
|
||||
'sort_order' => 0,
|
||||
'active' => true,
|
||||
]);
|
||||
AcademyAiComparisonResult::query()->create([
|
||||
'lesson_block_id' => $block->id,
|
||||
'provider' => 'OpenAI',
|
||||
'model_name' => 'ChatGPT Images',
|
||||
'image_path' => 'academy/lessons/body/aa/bb/example.webp',
|
||||
'strengths' => 'Strong composition',
|
||||
'score' => 9,
|
||||
'sort_order' => 0,
|
||||
'active' => true,
|
||||
]);
|
||||
AcademyAiComparisonResult::query()->create([
|
||||
'lesson_block_id' => $block->id,
|
||||
'provider' => 'Google',
|
||||
'model_name' => 'Gemini',
|
||||
'image_path' => 'academy/lessons/body/aa/bb/example-2.webp',
|
||||
'score' => 7,
|
||||
'sort_order' => 1,
|
||||
'active' => false,
|
||||
]);
|
||||
|
||||
$this->get(route('academy.lessons.show', ['slug' => $lesson->slug]))
|
||||
->assertOk()
|
||||
->assertInertia(fn (AssertableInertia $page) => $page
|
||||
->component('Academy/Show')
|
||||
->where('item.blocks.0.payload.prompt', 'A peaceful fantasy forest wallpaper.')
|
||||
->has('item.blocks.0.comparison_results', 1)
|
||||
->where('item.blocks.0.comparison_results.0.model_name', 'ChatGPT Images'));
|
||||
}
|
||||
|
||||
public function test_public_lesson_with_sparse_ai_comparison_block_still_renders_payload(): void
|
||||
{
|
||||
$lesson = AcademyLesson::query()->create([
|
||||
'title' => 'Sparse Comparison Lesson',
|
||||
'slug' => 'sparse-comparison-lesson',
|
||||
'excerpt' => 'Sparse block test.',
|
||||
'content' => 'Free lesson content',
|
||||
'difficulty' => 'beginner',
|
||||
'access_level' => 'free',
|
||||
'lesson_type' => 'article',
|
||||
'active' => true,
|
||||
'published_at' => now()->subMinute(),
|
||||
]);
|
||||
AcademyLessonBlock::query()->create([
|
||||
'lesson_id' => $lesson->id,
|
||||
'type' => 'ai_comparison',
|
||||
'title' => 'Prompt only block',
|
||||
'payload' => [
|
||||
'title' => 'Prompt only block',
|
||||
'prompt' => 'A fantasy forest at sunrise.',
|
||||
],
|
||||
'sort_order' => 0,
|
||||
'active' => true,
|
||||
]);
|
||||
|
||||
$this->get(route('academy.lessons.show', ['slug' => $lesson->slug]))
|
||||
->assertOk()
|
||||
->assertInertia(fn (AssertableInertia $page) => $page
|
||||
->has('item.blocks', 1)
|
||||
->where('item.blocks.0.payload.prompt', 'A fantasy forest at sunrise.')
|
||||
->has('item.blocks.0.comparison_results', 0));
|
||||
}
|
||||
|
||||
public function test_logged_in_user_can_mark_lesson_completed(): void
|
||||
{
|
||||
$lesson = AcademyLesson::query()->create([
|
||||
@@ -511,4 +604,4 @@ final class AcademyFeatureTest extends TestCase
|
||||
'workflow_notes' => 'Workflow two',
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user