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.

test(mcp): end-to-end media upload flow

Paulo Castellano98b3a9ffb7fc
diff --git a/tests/Feature/Mcp/MediaUploadFlowTest.php b/tests/Feature/Mcp/MediaUploadFlowTest.php
new file mode 100644
index 000000000..65fbbe74e
--- /dev/null
+++ b/tests/Feature/Mcp/MediaUploadFlowTest.php
@@ -0,0 +1,59 @@
+<?php
+
+declare(strict_types=1);
+
+use App\Enums\UserWorkspace\Role;
+use App\Mcp\Servers\TryPostServer;
+use App\Mcp\Tools\Post\AttachMediaFromUploadTool;
+use App\Mcp\Tools\Post\RequestMediaUploadTool;
+use App\Models\Post;
+use App\Models\User;
+use App\Models\Workspace;
+use Illuminate\Http\UploadedFile;
+use Illuminate\Support\Facades\Cache;
+use Illuminate\Support\Facades\Storage;
+use Illuminate\Testing\Fluent\AssertableJson;
+
+beforeEach(function () {
+ Storage::fake();
+ Cache::flush();
+
+ $this->user = User::factory()->create();
+ $this->workspace = Workspace::factory()->create(['user_id' => $this->user->id]);
+ $this->workspace->members()->attach($this->user->id, ['role' => Role::Member->value]);
+ $this->user->update(['current_workspace_id' => $this->workspace->id]);
+
+ $this->post = Post::factory()->create([
+ 'workspace_id' => $this->workspace->id,
+ 'user_id' => $this->user->id,
+ ]);
+});
+
+test('agent can request URL, client uploads, agent attaches to post', function () {
+ $uploadUrl = null;
+ $uploadToken = null;
+
+ TryPostServer::actingAs($this->user)
+ ->tool(RequestMediaUploadTool::class, [])
+ ->assertOk()
+ ->assertStructuredContent(function (AssertableJson $json) use (&$uploadUrl, &$uploadToken) {
+ $json->etc();
+ $uploadUrl = $json->toArray()['upload_url'];
+ $uploadToken = $json->toArray()['upload_token'];
+ });
+
+ expect($uploadUrl)->not->toBeNull();
+ expect($uploadToken)->not->toBeNull();
+
+ $file = UploadedFile::fake()->image('e2e.png', 64, 64);
+ $this->post($uploadUrl, ['media' => $file])->assertCreated();
+
+ TryPostServer::actingAs($this->user)
+ ->tool(AttachMediaFromUploadTool::class, [
+ 'post_id' => $this->post->id,
+ 'upload_token' => $uploadToken,
+ ])
+ ->assertOk();
+
+ expect($this->post->fresh()->media)->toHaveCount(1);
+});