@@ -30,41 +30,29 @@ import { scientistApiBaseURL } from './e2e'
30
30
// source: https://github.com/nextauthjs/next-auth/discussions/2053#discussioncomment-1191016
31
31
Cypress . Commands . add ( 'login' , ( username , password ) => {
32
32
cy . session ( [ username , password ] , ( ) => {
33
- cy . intercept ( " /api/auth/session" , { fixture : " session.json" } ) . as ( " session" ) ;
33
+ cy . intercept ( ' /api/auth/session' , { fixture : ' session.json' } ) . as ( ' session' )
34
34
35
- // Set the cookie for cypress.
36
- // It has to be a valid cookie so next-auth can decrypt it and confirm its validity.
37
- // This cookie also may need to be refreshed intermittently if it expires
38
- cy . setCookie ( " next-auth.session-token" , Cypress . env ( 'TEST_SESSION_COOKIE' ) ) ;
35
+ // Set the cookie for cypress.
36
+ // It has to be a valid cookie so next-auth can decrypt it and confirm its validity.
37
+ // This cookie also may need to be refreshed intermittently if it expires
38
+ cy . setCookie ( ' next-auth.session-token' , Cypress . env ( 'TEST_SESSION_COOKIE' ) )
39
39
} )
40
40
} )
41
41
42
42
// intercepts requests and creates potential cases for loading, error, data, and empty data
43
43
// required params are action, defaultFixture, requestURL
44
44
// optional params such as data, loading, and error can be passed depending on the creation of test cases that are related to that specific api call
45
45
Cypress . Commands . add ( 'customApiIntercept' , ( {
46
- action, alias, data, defaultFixture , emptyFixture , error, errorCaseStatusCode , loading, requestURL
46
+ action, alias, data, error, loading, requestURL
47
47
} ) => {
48
48
cy . intercept ( action , `${ scientistApiBaseURL } ${ requestURL } ` , ( req ) => {
49
- switch ( true ) {
50
- // reply with an empty response: both data and error will be undefined.
51
- case loading : req . reply ( { } )
52
- break
53
-
54
- // error will be defined
55
- case error : req . reply ( { statusCode : errorCaseStatusCode || 500 } )
56
- break
57
-
58
- // reply with a request body- default status code is 200
59
- case data : req . reply ( { fixture : defaultFixture } )
60
- break
61
-
62
- // reply with the empty fixture is there is one, and the default as a backup. Allows us to isolate one api call at a time that may potentially respond with empty data.
63
- case ! data : req . reply ( { fixture : emptyFixture || defaultFixture } )
64
- break
65
-
66
- default : req . reply ( { fixture : defaultFixture } )
67
- break
49
+ const response = {
50
+ data : { fixture : data } ,
51
+ error : { ...error } ,
52
+ loading : { } ,
68
53
}
54
+ console . log ( { response } )
55
+
56
+ return req . reply ( response [ data || error || loading ] )
69
57
} ) . as ( alias || 'customIntercept' )
70
58
} )
0 commit comments