diff --git a/src/renderer/context/App.test.tsx b/src/renderer/context/App.test.tsx index 07dcc1815..52bbb33c2 100644 --- a/src/renderer/context/App.test.tsx +++ b/src/renderer/context/App.test.tsx @@ -201,6 +201,10 @@ describe('renderer/context/App.tsx', () => { }); }); + afterEach(() => { + jest.clearAllMocks(); + }); + it('should call loginWithPersonalAccessToken', async () => { apiRequestAuthMock.mockResolvedValueOnce(null); @@ -230,15 +234,10 @@ describe('renderer/context/App.tsx', () => { expect(fetchNotificationsMock).toHaveBeenCalledTimes(1), ); - expect(apiRequestAuthMock).toHaveBeenCalledTimes(2); + expect(apiRequestAuthMock).toHaveBeenCalledTimes(1); expect(apiRequestAuthMock).toHaveBeenCalledWith( 'https://api.github.com/notifications', 'HEAD', - '123-456', - ); - expect(apiRequestAuthMock).toHaveBeenCalledWith( - 'https://api.github.com/user', - 'GET', 'encrypted', ); }); diff --git a/src/renderer/context/App.tsx b/src/renderer/context/App.tsx index 15d0ac14d..d417dd6e2 100644 --- a/src/renderer/context/App.tsx +++ b/src/renderer/context/App.tsx @@ -225,7 +225,9 @@ export const AppProvider = ({ children }: { children: ReactNode }) => { const loginWithOAuthApp = useCallback( async (data: LoginOAuthAppOptions) => { const { authOptions, authCode } = await authGitHub(data); + const { token, hostname } = await getToken(authCode, authOptions); + const updatedAuth = await addAccount(auth, 'OAuth App', token, hostname); setAuth(updatedAuth); saveState({ auth: updatedAuth, settings }); @@ -235,7 +237,9 @@ export const AppProvider = ({ children }: { children: ReactNode }) => { const loginWithPersonalAccessToken = useCallback( async ({ token, hostname }: LoginPersonalAccessTokenOptions) => { - await headNotifications(hostname, token); + const encryptedToken = (await encryptValue(token)) as Token; + await headNotifications(hostname, encryptedToken); + const updatedAuth = await addAccount( auth, 'Personal Access Token', @@ -250,10 +254,8 @@ export const AppProvider = ({ children }: { children: ReactNode }) => { const logoutFromAccount = useCallback( async (account: Account) => { - // Remove notifications for account removeAccountNotifications(account); - // Remove from auth state const updatedAuth = removeAccount(auth, account); setAuth(updatedAuth); saveState({ auth: updatedAuth, settings });