From 045078941ca295312f8ffc9135442032baea1400 Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Wed, 29 Jul 2026 14:47:13 +0530 Subject: [PATCH] test(vcs): cover the state a cleared installation is left in Once the pair is cleared the expiry is null, which the refresh treats as nothing to do, so the installation comes back untouched and the provider is not called. GitHub then works from its app credentials. That behaviour now carries the recovery for installations whose refresh token is gone, so it should be pinned down rather than inferred. --- tests/unit/Vcs/InstallationTokensTest.php | 24 +++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/unit/Vcs/InstallationTokensTest.php b/tests/unit/Vcs/InstallationTokensTest.php index d67ad842e2..45e7fda6b6 100644 --- a/tests/unit/Vcs/InstallationTokensTest.php +++ b/tests/unit/Vcs/InstallationTokensTest.php @@ -76,6 +76,30 @@ final class InstallationTokensTest extends TestCase $this->assertSame(0, $oauth2->refreshCalls); } + public function testClearedInstallationIsReturnedWithoutCallingTheProvider(): void + { + // The state clear() leaves behind. GitHub works from here on its app credentials, and the + // providers that need the token fail at the adapter with a definite reason. + $installation = new Document([ + '$id' => 'installation1', + 'personalAccessToken' => '', + 'personalRefreshToken' => '', + 'personalAccessTokenExpiry' => null, + ]); + + $db = $this->createMock(Database::class); + $db->method('getAuthorization')->willReturn(new Authorization()); + $db->expects($this->never())->method('updateDocument'); + $db->expects($this->never())->method('createDocument'); + + $oauth2 = $this->fakeOAuth2(); + + $result = (new InstallationTokens())->refresh($installation, $db, $oauth2); + + $this->assertSame('', $result->getAttribute('personalAccessToken')); + $this->assertSame(0, $oauth2->refreshCalls); + } + public function testExpiredTokenIsRefreshedAndPersisted(): void { $db = $this->createMock(Database::class);