Skip to content

Open-source social media scheduler built for AI agents and the teams behind them. Create, schedule and publish posts to every network through MCP or the REST API, or write them yourself in a composer your team will love.

5.8 KB
Raw Blame
<?php

declare(strict_types=1);

use App\Mcp\Servers\TryPostServer;
use App\Mcp\Tools\Platform\ListContentTypesTool;
use App\Models\User;
use App\Models\Workspace;
use Illuminate\Testing\Fluent\AssertableJson;

beforeEach(function () {
    $this->user = User::factory()->create();
    $this->workspace = Workspace::factory()->create(['user_id' => $this->user->id]);
    $this->workspace->members()->attach($this->user->id, membershipPivot('member'));
    $this->user->update(['current_workspace_id' => $this->workspace->id]);
});

test('list content types returns all platforms with constraints', function () {
    $response = TryPostServer::actingAs($this->user)
        ->tool(ListContentTypesTool::class, []);

    $response->assertOk()
        ->assertStructuredContent(function (AssertableJson $json) {
            $json->has('platforms', fn (AssertableJson $platforms) => $platforms
                ->each(fn (AssertableJson $p) => $p
                    ->hasAll([
                        'platform',
                        'label',
                        'max_content_length',
                        'max_hashtags',
                        'alt_text_max_length',
                        'required_meta',
                        'recommended_content_length',
                        'allowed_media_types',
                        'default_content_type',
                        'content_types',
                    ])
                    ->has('content_types', fn (AssertableJson $types) => $types
                        ->each(fn (AssertableJson $type) => $type
                            ->hasAll([
                                'value',
                                'label',
                                'description',
                                'max_media_count',
                                'min_media_count',
                                'requires_media',
                                'accept_images',
                                'accept_videos',
                                'accept_documents',
                                'accepts_gif',
                                'accepts_mov',
                                'forbids_mixed_media',
                                'max_video_duration_sec',
                                'max_image_bytes',
                                'max_video_bytes',
                                'max_document_bytes',
                                'aspect_ratio_min',
                                'aspect_ratio_max',
                                'video_aspect_ratio_min',
                                'video_aspect_ratio_max',
                                'auto_fits_image',
                                'image_min_width',
                                'image_min_height',
                                'image_max_width',
                                'image_max_height',
                                'supports_alt_text',
                                'supports_video_alt_text',
                                'supports_user_tags',
                                'supports_video_cover',
                                'supports_custom_video_cover',
                                'captionless',
                                'document_must_be_alone',
                                'supports_thread_replies',
                                'max_thread_replies',
                            ])
                        )
                    )
                )
            );
        });
});

test('list content types includes content types per platform', function () {
    $response = TryPostServer::actingAs($this->user)
        ->tool(ListContentTypesTool::class, []);

    $response->assertOk()
        ->assertSee(['linkedin', 'linkedin_post', 'x_post', 'instagram_feed', 'mastodon_post']);
});

test('list content types exposes reel max video durations', function () {
    $response = TryPostServer::actingAs($this->user)
        ->tool(ListContentTypesTool::class, []);

    $response->assertOk()
        ->assertStructuredContent(function (AssertableJson $json) {
            $json->etc();

            $platforms = collect($json->toArray()['platforms']);
            $instagramTypes = collect($platforms->firstWhere('platform', 'instagram')['content_types']);
            $facebookTypes = collect($platforms->firstWhere('platform', 'facebook')['content_types']);
            $pinterestTypes = collect($platforms->firstWhere('platform', 'pinterest')['content_types']);

            expect($instagramTypes->firstWhere('value', 'instagram_reel')['max_video_duration_sec'])->toBe(900);
            expect($instagramTypes->firstWhere('value', 'instagram_reel')['max_video_bytes'])->toBe(300 * 1024 * 1024);
            expect($facebookTypes->firstWhere('value', 'facebook_reel')['max_video_duration_sec'])->toBe(90);
            expect($pinterestTypes->firstWhere('value', 'pinterest_carousel')['min_media_count'])->toBe(2);
        });
});

test('list content types shows each poll without media capabilities', function (string $platform, string $type) {
    TryPostServer::actingAs($this->user)
        ->tool(ListContentTypesTool::class, [])
        ->assertOk()
        ->assertStructuredContent(function (AssertableJson $json) use ($platform, $type) {
            $json->etc();

            $poll = collect(data_get(collect(data_get($json->toArray(), 'platforms'))->firstWhere('platform', $platform), 'content_types'))->firstWhere('value', $type);

            expect($poll)->toMatchArray([
                'max_media_count' => 0,
                'accept_images' => false,
                'accept_videos' => false,
                'accepts_gif' => false,
                'max_image_bytes' => null,
                'max_video_bytes' => null,
                'max_video_duration_sec' => null,
            ]);
        });
})->with([
    'x' => ['x', 'x_poll'],
    'mastodon' => ['mastodon', 'mastodon_poll'],
    'threads' => ['threads', 'threads_poll'],
]);