@@ -32,12 +32,12 @@ describe('renderer/utils/auth/utils.ts', () => {
3232 jest . clearAllMocks ( ) ;
3333 } ) ;
3434
35- it ( 'should call authGitHub - auth flow' , async ( ) => {
35+ it ( 'should call authGitHub - success auth flow' , async ( ) => {
3636 const mockIpcRendererOn = (
3737 jest . spyOn ( ipcRenderer , 'on' ) as jest . Mock
3838 ) . mockImplementation ( ( event , callback ) => {
39- if ( event === 'gitify:auth-code ' ) {
40- callback ( null , 'auth' , ' 123-456') ;
39+ if ( event === 'gitify:auth-callback ' ) {
40+ callback ( null , 'gitify:// auth?code= 123-456' ) ;
4141 }
4242 } ) ;
4343
@@ -50,20 +50,20 @@ describe('renderer/utils/auth/utils.ts', () => {
5050
5151 expect ( mockIpcRendererOn ) . toHaveBeenCalledTimes ( 1 ) ;
5252 expect ( mockIpcRendererOn ) . toHaveBeenCalledWith (
53- 'gitify:auth-code ' ,
53+ 'gitify:auth-callback ' ,
5454 expect . any ( Function ) ,
5555 ) ;
5656
57- expect ( res . authType ) . toBe ( 'GitHub App' ) ;
57+ expect ( res . authMethod ) . toBe ( 'GitHub App' ) ;
5858 expect ( res . authCode ) . toBe ( '123-456' ) ;
5959 } ) ;
6060
61- it ( 'should call authGitHub - oauth flow' , async ( ) => {
61+ it ( 'should call authGitHub - success oauth flow' , async ( ) => {
6262 const mockIpcRendererOn = (
6363 jest . spyOn ( ipcRenderer , 'on' ) as jest . Mock
6464 ) . mockImplementation ( ( event , callback ) => {
65- if ( event === 'gitify:auth-code ' ) {
66- callback ( null , 'oauth' , ' 123-456') ;
65+ if ( event === 'gitify:auth-callback ' ) {
66+ callback ( null , 'gitify:// oauth?code= 123-456' ) ;
6767 }
6868 } ) ;
6969
@@ -80,13 +80,41 @@ describe('renderer/utils/auth/utils.ts', () => {
8080
8181 expect ( mockIpcRendererOn ) . toHaveBeenCalledTimes ( 1 ) ;
8282 expect ( mockIpcRendererOn ) . toHaveBeenCalledWith (
83- 'gitify:auth-code ' ,
83+ 'gitify:auth-callback ' ,
8484 expect . any ( Function ) ,
8585 ) ;
8686
87- expect ( res . authType ) . toBe ( 'OAuth App' ) ;
87+ expect ( res . authMethod ) . toBe ( 'OAuth App' ) ;
8888 expect ( res . authCode ) . toBe ( '123-456' ) ;
8989 } ) ;
90+
91+ it ( 'should call authGitHub - failure' , async ( ) => {
92+ const mockIpcRendererOn = (
93+ jest . spyOn ( ipcRenderer , 'on' ) as jest . Mock
94+ ) . mockImplementation ( ( event , callback ) => {
95+ if ( event === 'gitify:auth-callback' ) {
96+ callback (
97+ null ,
98+ 'gitify://auth?error=invalid_request&error_description=The+redirect_uri+is+missing+or+invalid.&error_uri=https://docs.github.com/en/developers/apps/troubleshooting-oauth-errors' ,
99+ ) ;
100+ }
101+ } ) ;
102+
103+ await expect ( async ( ) => await auth . authGitHub ( ) ) . rejects . toEqual (
104+ "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" ,
105+ ) ;
106+
107+ expect ( openExternalLinkMock ) . toHaveBeenCalledTimes ( 1 ) ;
108+ expect ( openExternalLinkMock ) . toHaveBeenCalledWith (
109+ 'https://github.com/login/oauth/authorize?client_id=FAKE_CLIENT_ID_123&scope=read%3Auser%2Cnotifications%2Crepo' ,
110+ ) ;
111+
112+ expect ( mockIpcRendererOn ) . toHaveBeenCalledTimes ( 1 ) ;
113+ expect ( mockIpcRendererOn ) . toHaveBeenCalledWith (
114+ 'gitify:auth-callback' ,
115+ expect . any ( Function ) ,
116+ ) ;
117+ } ) ;
90118 } ) ;
91119
92120 describe ( 'getToken' , ( ) => {
0 commit comments