Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/renderer/stores/useAccountsStore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import type { GetAuthenticatedUserResponse } from '../utils/forges/github/types'
import { getRecommendedScopeNames } from '../utils/auth/scopes';
import * as logger from '../utils/core/logger';
import * as apiClient from '../utils/forges/github/client';
import { getAdapter } from '../utils/forges/registry';
import { DEFAULT_ACCOUNTS_STATE } from './defaults';
import useAccountsStore from './useAccountsStore';

Expand Down Expand Up @@ -264,5 +265,25 @@ describe('renderer/stores/useAccountsStore.ts', () => {
expect(result.current).toMatchObject(DEFAULT_ACCOUNTS_STATE);
expect(result.current.accounts).toEqual([]);
});

test('should drop forge client state for every account', () => {
const onAccountTokenChangeSpy = vi
.spyOn(getAdapter(mockGitHubCloudAccount), 'onAccountTokenChange')
.mockImplementation(vi.fn());

useAccountsStore.setState({
accounts: [mockGitHubCloudAccount, mockGitHubEnterpriseServerAccount],
});

const { result } = renderHook(() => useAccountsStore());

act(() => {
result.current.reset();
});

expect(onAccountTokenChangeSpy).toHaveBeenCalledTimes(2);
expect(onAccountTokenChangeSpy).toHaveBeenCalledWith(mockGitHubCloudAccount);
expect(onAccountTokenChangeSpy).toHaveBeenCalledWith(mockGitHubEnterpriseServerAccount);
});
});
});
6 changes: 6 additions & 0 deletions src/renderer/stores/useAccountsStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,12 @@ const useAccountsStore = create<AccountsStore>()(
},

reset: () => {
// Drop forge-specific HTTP client state (e.g. cached authenticated
// Octokit clients) for every account being wiped.
for (const account of get().accounts) {
getAdapter(account).onAccountTokenChange?.(account);
}

set({ ...DEFAULT_ACCOUNTS_STATE });
},
}),
Expand Down