@@ -6,6 +6,8 @@ const passport = require("passport");
6
6
7
7
const app = require ( "../../server" ) ;
8
8
const cleanDb = require ( "../utils/cleanDb" ) ;
9
+ const { addUserToDBForTest } = require ( "../../utils/users" ) ;
10
+ const userData = require ( "../fixtures/user/user" ) ( ) ;
9
11
10
12
chai . use ( chaiHttp ) ;
11
13
@@ -19,28 +21,38 @@ describe("auth", function () {
19
21
sinon . restore ( ) ;
20
22
} ) ;
21
23
22
- it ( "should redirect the request to the goto page on successful login" , function ( done ) {
24
+ it ( "should redirect the user to new sign up flow if they are have incomplte user details true" , async function ( ) {
25
+ const redirectURL = "https://my.realdevsquad.com/new-signup" ;
26
+ sinon . stub ( passport , "authenticate" ) . callsFake ( ( strategy , options , callback ) => {
27
+ callback ( null , "accessToken" , githubUserInfo [ 0 ] ) ;
28
+ return ( req , res , next ) => { } ;
29
+ } ) ;
30
+
31
+ const res = await chai
32
+ . request ( app )
33
+ . get ( "/auth/github/callback" )
34
+ . query ( { code : "codeReturnedByGithub" } )
35
+ . redirects ( 0 ) ;
36
+ expect ( res ) . to . have . status ( 302 ) ;
37
+ expect ( res . headers . location ) . to . equal ( redirectURL ) ;
38
+ } ) ;
39
+ // same data should be return from github and same data should be added there
40
+ it ( "should redirect the request to the goto page on successful login, if user has incomplete user details false" , async function ( ) {
41
+ await addUserToDBForTest ( userData [ 0 ] ) ;
23
42
const rdsUiUrl = config . get ( "services.rdsUi.baseUrl" ) ;
24
43
25
44
sinon . stub ( passport , "authenticate" ) . callsFake ( ( strategy , options , callback ) => {
26
45
callback ( null , "accessToken" , githubUserInfo [ 0 ] ) ;
27
46
return ( req , res , next ) => { } ;
28
47
} ) ;
29
48
30
- chai
49
+ const res = await chai
31
50
. request ( app )
32
51
. get ( "/auth/github/callback" )
33
52
. query ( { code : "codeReturnedByGithub" , state : rdsUiUrl } )
34
- . redirects ( 0 )
35
- . end ( ( err , res ) => {
36
- if ( err ) {
37
- return done ( err ) ;
38
- }
39
- expect ( res ) . to . have . status ( 302 ) ;
40
- expect ( res . headers . location ) . to . equal ( rdsUiUrl ) ;
41
-
42
- return done ( ) ;
43
- } ) ;
53
+ . redirects ( 0 ) ;
54
+ expect ( res ) . to . have . status ( 302 ) ;
55
+ expect ( res . headers . location ) . to . equal ( rdsUiUrl ) ;
44
56
} ) ;
45
57
46
58
it ( "should send a cookie with JWT in the response" , function ( done ) {
0 commit comments