1
+ import { scientistApiBaseURL } from '../support/e2e'
2
+
1
3
describe ( 'Viewing all requests' , ( ) => {
2
4
describe ( 'as a logged out user' , ( ) => {
3
5
it ( 'should show an error message.' , ( ) => {
@@ -10,7 +12,6 @@ describe('Viewing all requests', () => {
10
12
} )
11
13
12
14
describe ( 'as a logged in user' , ( ) => {
13
- let scientistApiBaseURL = `https://${ Cypress . env ( 'NEXT_PUBLIC_PROVIDER_NAME' ) } .scientist.com/api/v2`
14
15
// declare variables that can be used to change how the response is intercepted.
15
16
let requestList
16
17
let loading
@@ -20,34 +21,23 @@ describe('Viewing all requests', () => {
20
21
// Call the custom cypress command to log in
21
22
cy . login ( Cypress . env ( 'TEST_SCIENTIST_USER' ) , Cypress . env ( 'TEST_SCIENTIST_PW' ) )
22
23
// Intercept the response from the endpoint to view all requests
23
- // TODO(summer-cook): extract out this base url into the config to use as an environment variable. it was not cooperating before
24
- cy . intercept ( 'GET' , `${ scientistApiBaseURL } /quote_groups/mine.json` , ( req ) => {
25
- switch ( true ) {
26
- // reply with an empty response: both data and error will be undefined.
27
- case loading : req . reply ( )
28
- break
29
-
30
- // error will be defined
31
- case error : req . reply ( { statusCode : 500 } )
32
- break
33
-
34
- case requestList : req . reply ( { fixture : 'all-requests/requests.json' } )
35
- break
36
-
37
- // reply with a request body- default status code is 200
38
- case ! requestList : req . reply ( { fixture : 'all-requests/no-requests.json' } )
39
- break
40
- }
24
+ cy . customApiIntercept ( {
25
+ action : 'GET' ,
26
+ alias : 'useAllRequests' ,
27
+ requestURL : `/quote_groups/mine.json` ,
28
+ data : requestList ,
29
+ defaultFixture : 'all-requests/requests.json' ,
30
+ emptyFixture : 'all-requests/no-requests.json' ,
31
+ loading,
32
+ error
41
33
} )
42
34
// Intercept the response from the endpoint that gets the default ware ID
43
- cy . intercept ( 'GET' , `${ scientistApiBaseURL } /wares.json?q=make-a-request` , ( req ) => {
44
- switch ( true ) {
45
- case error : req . reply ( { statusCode : 500 } )
46
- break
47
-
48
- default : req . reply ( { fixture : 'all-requests/make-a-request.json' } )
49
- break
50
- }
35
+ cy . customApiIntercept ( {
36
+ action : 'GET' ,
37
+ alias : 'useDefaultWare' ,
38
+ requestURL : `/wares.json?q=make-a-request` ,
39
+ defaultFixture : 'all-requests/make-a-request.json' ,
40
+ error
51
41
} )
52
42
cy . visit ( '/requests' )
53
43
} )
0 commit comments