11import type { AxiosResponse } from 'axios' ;
22import axios from 'axios' ;
3- import nock from 'nock' ;
43
54import { mockGitHubCloudAccount } from '../../__mocks__/account-mocks' ;
65import { mockAuth } from '../../__mocks__/state-mocks' ;
@@ -16,12 +15,16 @@ import type {
1615 Token ,
1716} from '../../types' ;
1817import * as comms from '../../utils/comms' ;
18+ import * as apiClient from '../api/client' ;
19+ import type { FetchAuthenticatedUserDetailsQuery } from '../api/graphql/generated/graphql' ;
1920import * as apiRequests from '../api/request' ;
2021import * as logger from '../logger' ;
2122import type { AuthMethod } from './types' ;
2223import * as authUtils from './utils' ;
2324import { getNewOAuthAppURL , getNewTokenURL } from './utils' ;
2425
26+ type UserDetailsResponse = FetchAuthenticatedUserDetailsQuery [ 'viewer' ] ;
27+
2528describe ( 'renderer/utils/auth/utils.ts' , ( ) => {
2629 describe ( 'authGitHub' , ( ) => {
2730 jest . spyOn ( logger , 'rendererLogInfo' ) . mockImplementation ( ) ;
@@ -139,6 +142,10 @@ describe('renderer/utils/auth/utils.ts', () => {
139142
140143 describe ( 'addAccount' , ( ) => {
141144 let mockAuthState : AuthState ;
145+ const fetchAuthenticatedUserDetailsSpy = jest . spyOn (
146+ apiClient ,
147+ 'fetchAuthenticatedUserDetails' ,
148+ ) ;
142149
143150 beforeEach ( ( ) => {
144151 mockAuthState = {
@@ -152,13 +159,17 @@ describe('renderer/utils/auth/utils.ts', () => {
152159
153160 describe ( 'should add GitHub Cloud account' , ( ) => {
154161 beforeEach ( ( ) => {
155- nock ( 'https://api.github.com' )
156- . get ( '/user' )
157- . reply (
158- 200 ,
159- { ...mockGitifyUser , avatar_url : mockGitifyUser . avatar } ,
160- { 'x-oauth-scopes' : Constants . OAUTH_SCOPES . RECOMMENDED } ,
161- ) ;
162+ fetchAuthenticatedUserDetailsSpy . mockResolvedValue ( {
163+ data : {
164+ viewer : {
165+ ...mockGitifyUser ,
166+ avatarUrl : mockGitifyUser . avatar ,
167+ } as UserDetailsResponse ,
168+ } ,
169+ headers : {
170+ 'x-oauth-scopes' : Constants . OAUTH_SCOPES . RECOMMENDED . join ( ', ' ) ,
171+ } ,
172+ } ) ;
162173 } ) ;
163174
164175 it ( 'should add personal access token account' , async ( ) => {
@@ -206,16 +217,18 @@ describe('renderer/utils/auth/utils.ts', () => {
206217
207218 describe ( 'should add GitHub Enterprise Server account' , ( ) => {
208219 beforeEach ( ( ) => {
209- nock ( 'https://github.gitify.io/api/v3' )
210- . get ( '/user' )
211- . reply (
212- 200 ,
213- { ...mockGitifyUser , avatar_url : mockGitifyUser . avatar } ,
214- {
215- 'x-github-enterprise-version' : '3.0.0' ,
216- 'x-oauth-scopes' : Constants . OAUTH_SCOPES . RECOMMENDED ,
217- } ,
218- ) ;
220+ fetchAuthenticatedUserDetailsSpy . mockResolvedValue ( {
221+ data : {
222+ viewer : {
223+ ...mockGitifyUser ,
224+ avatarUrl : mockGitifyUser . avatar ,
225+ } as UserDetailsResponse ,
226+ } ,
227+ headers : {
228+ 'x-github-enterprise-version' : '3.0.0' ,
229+ 'x-oauth-scopes' : Constants . OAUTH_SCOPES . RECOMMENDED . join ( ', ' ) ,
230+ } ,
231+ } ) ;
219232 } ) ;
220233
221234 it ( 'should add personal access token account' , async ( ) => {
0 commit comments