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.
PHP ai-agentsblueskyfacebookinstagramlaravellinkedinmastodonmcpmcp-serveropen-sourcerest-apiself-hostedsocial-mediasocial-media-managementsocial-media-schedulerthreadstiktokvuejsxyoutube
test(social): smoke tests for analytics refactored in this PR
Paulo Castellano090cc761dd86
diff --git a/tests/Feature/Services/Social/LinkedInPageAnalyticsTest.php b/tests/Feature/Services/Social/LinkedInPageAnalyticsTest.phpnew file mode 100644index 000000000..0836940d7--- /dev/null+++ b/tests/Feature/Services/Social/LinkedInPageAnalyticsTest.php@@ -0,0 +1,55 @@+<?php++declare(strict_types=1);++use App\Enums\PostPlatform\ContentType;+use App\Enums\SocialAccount\Platform;+use App\Models\Post;+use App\Models\PostPlatform;+use App\Models\SocialAccount;+use App\Models\User;+use App\Models\Workspace;+use App\Services\Social\LinkedInPageAnalytics;+use Illuminate\Support\Facades\Http;++beforeEach(function () {+ $this->user = User::factory()->create();+ $this->workspace = Workspace::factory()->create(['user_id' => $this->user->id]);+ $this->socialAccount = SocialAccount::factory()->linkedinPage()->create([+ 'workspace_id' => $this->workspace->id,+ 'token_expires_at' => now()->subHour(),+ 'refresh_token' => 'old_refresh_token',+ ]);+ $this->post = Post::factory()->create([+ 'workspace_id' => $this->workspace->id,+ 'user_id' => $this->user->id,+ ]);+ $this->postPlatform = PostPlatform::factory()->create([+ 'post_id' => $this->post->id,+ 'social_account_id' => $this->socialAccount->id,+ 'platform' => Platform::LinkedInPage,+ 'content_type' => ContentType::LinkedInPagePost,+ 'platform_post_id' => 'urn:li:share:1234567890',+ ]);+});++test('linkedin page analytics refresh hits the configured oauth host', function () {+ Http::fake([+ 'www.linkedin.com/oauth/v2/accessToken' => Http::response([+ 'access_token' => 'new_token',+ 'refresh_token' => 'new_refresh_token',+ 'expires_in' => 5184000,+ ], 200),+ 'api.linkedin.com/rest/socialActions/*' => Http::response([+ 'likesSummary' => ['totalLikes' => 0],+ 'commentsSummary' => ['aggregatedTotalComments' => 0],+ ], 200),+ ]);++ (new LinkedInPageAnalytics)->fetchPostMetrics($this->postPlatform);++ Http::assertSent(fn ($request) => str_contains(+ $request->url(),+ rtrim((string) config('trypost.platforms.linkedin.oauth_api'), '/').'/oauth/v2/accessToken'+ ));+});diff --git a/tests/Feature/Services/Social/MastodonAnalyticsTest.php b/tests/Feature/Services/Social/MastodonAnalyticsTest.phpnew file mode 100644index 000000000..0a6fe7cc2--- /dev/null+++ b/tests/Feature/Services/Social/MastodonAnalyticsTest.php@@ -0,0 +1,75 @@+<?php++declare(strict_types=1);++use App\Enums\PostPlatform\ContentType;+use App\Enums\SocialAccount\Platform;+use App\Models\Post;+use App\Models\PostPlatform;+use App\Models\SocialAccount;+use App\Models\User;+use App\Models\Workspace;+use App\Services\Social\MastodonAnalytics;+use Illuminate\Support\Facades\Http;++beforeEach(function () {+ $this->user = User::factory()->create();+ $this->workspace = Workspace::factory()->create(['user_id' => $this->user->id]);+ $this->post = Post::factory()->create([+ 'workspace_id' => $this->workspace->id,+ 'user_id' => $this->user->id,+ ]);+});++test('mastodon analytics falls back to configured default instance', function () {+ $defaultInstance = (string) config('trypost.platforms.mastodon.default_instance');++ Http::fake([+ "{$defaultInstance}/api/v1/statuses/*" => Http::response([+ 'favourites_count' => 5,+ 'reblogs_count' => 2,+ 'replies_count' => 1,+ ], 200),+ ]);++ $account = SocialAccount::factory()->mastodon()->create([+ 'workspace_id' => $this->workspace->id,+ 'meta' => [],+ ]);+ $postPlatform = PostPlatform::factory()->create([+ 'post_id' => $this->post->id,+ 'social_account_id' => $account->id,+ 'platform' => Platform::Mastodon,+ 'content_type' => ContentType::MastodonPost,+ 'platform_post_id' => '109876543210',+ ]);++ $metrics = (new MastodonAnalytics)->fetchPostMetrics($postPlatform);++ expect($metrics)->toBeArray();+ Http::assertSent(fn ($request) => str_starts_with($request->url(), $defaultInstance.'/api/v1/statuses/'));+});++test('mastodon analytics honors per-account instance override', function () {+ Http::fake([+ 'techhub.social/api/v1/statuses/*' => Http::response([+ 'favourites_count' => 0, 'reblogs_count' => 0, 'replies_count' => 0,+ ], 200),+ ]);++ $account = SocialAccount::factory()->mastodon()->create([+ 'workspace_id' => $this->workspace->id,+ 'meta' => ['instance' => 'https://techhub.social'],+ ]);+ $postPlatform = PostPlatform::factory()->create([+ 'post_id' => $this->post->id,+ 'social_account_id' => $account->id,+ 'platform' => Platform::Mastodon,+ 'content_type' => ContentType::MastodonPost,+ 'platform_post_id' => '999',+ ]);++ (new MastodonAnalytics)->fetchPostMetrics($postPlatform);++ Http::assertSent(fn ($request) => str_starts_with($request->url(), 'https://techhub.social/api/v1/statuses/'));+});