trypost/tests/Feature/Ai/Templates/TweetCardTemplateTest.php
Paulo Castellano 9f5bacc03f refactor(ai): introduce GeneratorFormat enum and drop stringly-typed format
Replace the 'single'/'carousel' string format threaded through the AI
generation path with a typed GeneratorFormat enum (PostContentGenerator,
PostContentHumanizer, PostContentStreamer, StreamPostCreation,
RunGenerateNode, deriveFormat).

Remove generatorFormat() from AiContentTemplate and the three templates —
it conflated style and format (returning 'tweet_card'). The tweet-card
check now lives on ContentStyle via isTweetCard(), and the humanizer skip
on ContentStyle::humanizes(), so the style declares its own behaviour
instead of callers comparing magic strings.
2026-06-18 11:11:23 -03:00

46 lines
1.7 KiB
PHP

<?php
declare(strict_types=1);
use App\Ai\Templates\TemplateContext;
use App\Ai\Templates\TweetCardTemplate;
use App\Enums\Ai\ContentStyle;
use App\Models\Workspace;
use Illuminate\JsonSchema\JsonSchemaTypeFactory;
test('tweet card template identity', function () {
$t = new TweetCardTemplate;
$workspace = Workspace::factory()->create();
$singleContext = new TemplateContext($workspace, null, 'x_post', 1, false);
$carouselContext = new TemplateContext($workspace, null, 'instagram_carousel', 2, true);
expect($t->style())->toBe(ContentStyle::TweetCard)
->and($t->key())->toBe('tweet_card')
->and($t->needsAccount())->toBeTrue()
->and($t->style()->isTweetCard())->toBeTrue()
->and($t->promptView($singleContext))->toBe('prompts.post_content.tweet_card')
->and($t->promptView($carouselContext))->toBe('prompts.post_content.tweet_card_carousel');
});
test('tweet card single schema returns tweet_text only', function () {
$t = new TweetCardTemplate;
$workspace = Workspace::factory()->create();
$context = new TemplateContext($workspace, null, 'x_post', 1, false);
$schema = new JsonSchemaTypeFactory;
$result = $t->schema($schema, $context);
expect($result)->toHaveKey('tweet_text')
->and($result)->not->toHaveKey('caption');
});
test('tweet card carousel schema returns caption and slides', function () {
$t = new TweetCardTemplate;
$workspace = Workspace::factory()->create();
$context = new TemplateContext($workspace, null, 'instagram_carousel', 3, true);
$schema = new JsonSchemaTypeFactory;
$result = $t->schema($schema, $context);
expect($result)->toHaveKeys(['caption', 'slides']);
});