@@ -63,6 +63,17 @@ const nockAuthLimitExceeded = () => {
6363 . reply ( 200 , getSingleRepo . repo )
6464}
6565
66+ const nockAuthInvalidCode = ( ) => {
67+ nock ( 'https://github.com' )
68+ . persist ( )
69+ . post ( '/login/oauth/access_token/' , { code : 'eb518274e906c68580f7' } )
70+ . basicAuth ( { user : secrets . github . id , pass : secrets . github . secret } )
71+ . reply ( 200 , {
72+ error : 'bad_verification_code' ,
73+ error_description : 'The code passed is incorrect or expired.'
74+ } )
75+ }
76+
6677describe ( 'Task CRUD' , ( ) => {
6778 const createTask = async ( authorizationHeader : string , params ?: any ) => {
6879 const res = await agent
@@ -236,16 +247,20 @@ describe('Task CRUD', () => {
236247 expect ( mailSpySuccess ) . to . have . been . called ( )
237248 } )
238249
239- xit ( 'should receive code on the platform from github auth to the redirected url for private tasks but invalid code' , async ( ) => {
250+ it ( 'should redirect to profile with an error when private task auth returns an invalid code' , async ( ) => {
251+ nockAuthInvalidCode ( )
240252 const res = await agent
241253 . get (
242254 '/callback/github/private/?userId=1&url=https%3A%2F%2Fgithub.com%2Falexanmtz%2Ffestifica%2Fissues%2F1&code=eb518274e906c68580f7'
243255 )
244- . expect ( 401 )
256+ . expect ( 302 )
245257
246- expect ( res . statusCode ) . to . equal ( 401 )
247- expect ( res . body . error ) . to . equal ( 'bad_verification_code' )
248- expect ( res . body ) . to . exist
258+ expect ( res . statusCode ) . to . equal ( 302 )
259+ expect ( res . headers . location ) . to . equal (
260+ `${ process . env . FRONTEND_HOST } /#/profile?createTaskError=true&message=${ encodeURIComponent (
261+ 'The code passed is incorrect or expired.'
262+ ) } `
263+ )
249264 } )
250265
251266 it ( 'should receive code on the platform from github auth to the redirected url for private tasks with a valid code' , async ( ) => {
0 commit comments