From 6037169aa9639bfed77cc45275ed7fa3dbfe7b84 Mon Sep 17 00:00:00 2001 From: Paulo Castellano Date: Fri, 3 Jul 2026 09:58:26 -0300 Subject: [PATCH] Cover Threads token extension with an explicit test The extend-while-valid path is shared by Instagram and Threads via Platform::extendsAccessTokenOnRefresh(); add the Threads sibling of the Instagram job test so both extension-model platforms are locked down. Refs #126 --- tests/Feature/Jobs/RefreshSocialTokenTest.php | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/Feature/Jobs/RefreshSocialTokenTest.php b/tests/Feature/Jobs/RefreshSocialTokenTest.php index e9e44399..bf9d0269 100644 --- a/tests/Feature/Jobs/RefreshSocialTokenTest.php +++ b/tests/Feature/Jobs/RefreshSocialTokenTest.php @@ -85,6 +85,28 @@ expect($account->fresh()->access_token)->toBe('extended-ig-token'); }); +test('proactive refresh EXTENDS a still-valid Threads token (extension-model platform)', function () { + $account = SocialAccount::factory()->create([ + 'workspace_id' => $this->workspace->id, + 'platform' => Platform::Threads, + 'status' => Status::Connected, + 'access_token' => 'old-threads-token', + 'token_expires_at' => now()->addMinutes(20), + ]); + + Http::fake([ + config('trypost.platforms.threads.auth_api').'/refresh_access_token*' => Http::response([ + 'access_token' => 'extended-threads-token', + 'expires_in' => 5184000, + ], 200), + ]); + + (new RefreshSocialToken($account))->handle(app(ConnectionVerifier::class)); + + Http::assertSent(fn ($request) => str_contains($request->url(), 'refresh_access_token')); + expect($account->fresh()->access_token)->toBe('extended-threads-token'); +}); + test('refresh job marks account as TokenExpired when refresh_token is rejected', function () { Queue::fake();