@@ -20,12 +20,17 @@ import type { AuthMethod } from './types';
2020import * as authUtils from './utils' ;
2121import { getNewOAuthAppURL , getNewTokenURL } from './utils' ;
2222
23- const exchangeWebFlowCodeMock = jest . fn ( ) ;
2423jest . mock ( '@octokit/oauth-methods' , ( ) => ( {
2524 ...jest . requireActual ( '@octokit/oauth-methods' ) ,
26- exchangeWebFlowCode : ( ) => exchangeWebFlowCodeMock ,
25+ exchangeWebFlowCode : jest . fn ( ) ,
2726} ) ) ;
2827
28+ import { exchangeWebFlowCode } from '@octokit/oauth-methods' ;
29+
30+ const exchangeWebFlowCodeMock = exchangeWebFlowCode as jest . MockedFunction <
31+ typeof exchangeWebFlowCode
32+ > ;
33+
2934describe ( 'renderer/utils/auth/utils.ts' , ( ) => {
3035 describe ( 'authGitHub' , ( ) => {
3136 jest . spyOn ( logger , 'rendererLogInfo' ) . mockImplementation ( ) ;
@@ -44,9 +49,7 @@ describe('renderer/utils/auth/utils.ts', () => {
4449 callback ( 'gitify://auth?code=123-456' ) ;
4550 } ) ;
4651
47- const res = await authUtils . performGitHubOAuth (
48- Constants . DEFAULT_AUTH_OPTIONS ,
49- ) ;
52+ const res = await authUtils . performGitHubOAuth ( ) ;
5053
5154 expect ( openExternalLinkSpy ) . toHaveBeenCalledTimes ( 1 ) ;
5255 expect ( openExternalLinkSpy ) . toHaveBeenCalledWith (
@@ -103,8 +106,7 @@ describe('renderer/utils/auth/utils.ts', () => {
103106 } ) ;
104107
105108 await expect (
106- async ( ) =>
107- await authUtils . performGitHubOAuth ( Constants . DEFAULT_AUTH_OPTIONS ) ,
109+ async ( ) => await authUtils . performGitHubOAuth ( ) ,
108110 ) . rejects . toEqual (
109111 new Error (
110112 "Oops! Something went wrong and we couldn't log you in using GitHub. Please try again. Reason: The redirect_uri is missing or invalid. Docs: https://docs.github.com/en/developers/apps/troubleshooting-oauth-errors" ,
@@ -133,15 +135,19 @@ describe('renderer/utils/auth/utils.ts', () => {
133135 authentication : {
134136 token : 'this-is-a-token' ,
135137 } ,
136- } ) ;
138+ } as any ) ;
137139
138- const res = await authUtils . exchangeAuthCodeForAccessToken ( authCode ) ;
140+ const res = await authUtils . exchangeAuthCodeForAccessToken (
141+ authCode ,
142+ Constants . DEFAULT_AUTH_OPTIONS ,
143+ ) ;
139144
140145 expect ( exchangeWebFlowCodeMock ) . toHaveBeenCalledWith ( {
141146 clientType : 'oauth-app' ,
142147 clientId : 'FAKE_CLIENT_ID_123' ,
143148 clientSecret : 'FAKE_CLIENT_SECRET_123' ,
144149 code : '123-456' ,
150+ request : expect . any ( Function ) ,
145151 } ) ;
146152 expect ( res ) . toBe ( 'this-is-a-token' ) ;
147153 } ) ;
0 commit comments