Skip to content
Merged
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
11 changes: 5 additions & 6 deletions src/renderer/context/App.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,10 @@ describe('renderer/context/App.tsx', () => {
});
});

afterEach(() => {
jest.clearAllMocks();
});

it('should call loginWithPersonalAccessToken', async () => {
apiRequestAuthMock.mockResolvedValueOnce(null);

Expand Down Expand Up @@ -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',
);
});
Expand Down
8 changes: 5 additions & 3 deletions src/renderer/context/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand All @@ -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',
Expand All @@ -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 });
Expand Down
Loading