@@ -12,6 +12,7 @@ import type {
1212 AuthCode ,
1313 AuthState ,
1414 ClientID ,
15+ ClientSecret ,
1516 Hostname ,
1617 Token ,
1718} from '../../types' ;
@@ -31,7 +32,7 @@ describe('renderer/utils/auth/utils.ts', () => {
3132 jest . clearAllMocks ( ) ;
3233 } ) ;
3334
34- it ( 'should call authGitHub - success ' , async ( ) => {
35+ it ( 'should call authGitHub - auth flow ' , async ( ) => {
3536 const mockIpcRendererOn = (
3637 jest . spyOn ( ipcRenderer , 'on' ) as jest . Mock
3738 ) . mockImplementation ( ( event , callback ) => {
@@ -56,6 +57,36 @@ describe('renderer/utils/auth/utils.ts', () => {
5657 expect ( res . authType ) . toBe ( 'GitHub App' ) ;
5758 expect ( res . authCode ) . toBe ( '123-456' ) ;
5859 } ) ;
60+
61+ it ( 'should call authGitHub - oauth flow' , async ( ) => {
62+ const mockIpcRendererOn = (
63+ jest . spyOn ( ipcRenderer , 'on' ) as jest . Mock
64+ ) . mockImplementation ( ( event , callback ) => {
65+ if ( event === 'gitify:auth-code' ) {
66+ callback ( null , 'oauth' , '123-456' ) ;
67+ }
68+ } ) ;
69+
70+ const res = await auth . authGitHub ( {
71+ clientId : 'BYO_CLIENT_ID' as ClientID ,
72+ clientSecret : 'BYO_CLIENT_SECRET' as ClientSecret ,
73+ hostname : 'my.git.com' as Hostname ,
74+ } ) ;
75+
76+ expect ( openExternalLinkMock ) . toHaveBeenCalledTimes ( 1 ) ;
77+ expect ( openExternalLinkMock ) . toHaveBeenCalledWith (
78+ 'https://my.git.com/login/oauth/authorize?client_id=BYO_CLIENT_ID&scope=read%3Auser%2Cnotifications%2Crepo' ,
79+ ) ;
80+
81+ expect ( mockIpcRendererOn ) . toHaveBeenCalledTimes ( 1 ) ;
82+ expect ( mockIpcRendererOn ) . toHaveBeenCalledWith (
83+ 'gitify:auth-code' ,
84+ expect . any ( Function ) ,
85+ ) ;
86+
87+ expect ( res . authType ) . toBe ( 'OAuth App' ) ;
88+ expect ( res . authCode ) . toBe ( '123-456' ) ;
89+ } ) ;
5990 } ) ;
6091
6192 describe ( 'getToken' , ( ) => {
0 commit comments