@@ -3,7 +3,7 @@ describe('Can find existing user in RWA', () => {
3
3
//Navigate to RWA
4
4
cy . visit ( 'http://localhost:3000' ) ;
5
5
} ) ;
6
- it ( 'should navigate to Cypress Web App and find Dev Becker' , ( ) => {
6
+ it . only ( 'should navigate to Cypress Web App and find Dev Becker' , ( ) => {
7
7
8
8
//Check Title
9
9
cy . title ( ) . should ( 'eq' , 'React App' ) ;
@@ -27,9 +27,11 @@ describe('Can find existing user in RWA', () => {
27
27
cy . wait ( '@devonSearch' )
28
28
29
29
cy . get ( 'div#root div.MuiListItemText-root.MuiListItemText-multiline > span' ) . contains ( 'Devon Becker' )
30
+
31
+ cy . server ( { enable : false } )
30
32
} )
31
33
32
- it . skip ( 'Can Find a Mocked User and Intercept' , ( ) => {
34
+ it ( 'Can Find a Mocked User and Intercept' , ( ) => {
33
35
cy . title ( ) . should ( 'eq' , 'React App' ) ;
34
36
35
37
cy . get ( 'input[name="username"]' ) . type ( 'Katharina_Bernier' ) ;
@@ -38,22 +40,61 @@ describe('Can find existing user in RWA', () => {
38
40
39
41
cy . get ( 'a[href="/transaction/new"]' ) . click ( ) ;
40
42
41
- //Mock a new Network Response and alias
43
+ //Mock a new Network Response in totality from the server
42
44
cy . server ( {
43
45
method : 'GET' ,
44
46
status : 200 ,
45
47
request : '/users/search?q=Devon+Becker' ,
46
48
response :
{ "results" :
[ { "id" :
"tsHF6_D5oQ" , "uuid" :
"53315353-7ca6-4cd1-8fd6-af9fb5a9dd25" , "firstName" :
"John" , "lastName" :
"Hill" , "username" :
"Jessyca.Kuhic" , "password" :
"$2a$10$5PXHGtcsckWtAprT5/JmluhR13f16BL8SIGhvAKNP.Dhxkt69FfzW" , "email" :
"[email protected] " , "phoneNumber" :
"277-189-3402" , "avatar" :
"https://sdtimes.com/wp-content/uploads/2018/07/lHYLxJV3_400x400.jpg" , "defaultPrivacyLevel" :
"contacts" , "balance" :
75369 , "createdAt" :
"2020-02-11T21:26:46.510Z" , "modifiedAt" :
"2020-05-21T15:15:33.944Z" } ] }
47
49
} )
48
- cy . route ( 'GET' , '/users/search?q=John+Hill' ) . as ( 'devonSearch' ) ;
50
+ //Alias any GET requests for John Hill sent from the browser
51
+ cy . route ( 'GET' , '/users/search?q=John+Hill' ) . as ( 'johnSearch' ) ;
49
52
50
53
//Search for John Hill (a nonexistant User)
51
54
cy . get ( '[data-test=user-list-search-input]' ) . click ( ) . type ( 'John Hill' )
55
+ cy . wait ( '@johnSearch' )
56
+
57
+ //Verify that John Hill is returned from RWA
58
+ cy . get ( 'div#root div.MuiListItemText-root.MuiListItemText-multiline > span' ) . contains ( 'John Hill' )
59
+
60
+
61
+ cy . server ( { enable : false } )
62
+
63
+ } )
64
+
65
+ it ( 'Can Find a Mocked User and Intercept' , ( ) => {
66
+ cy . title ( ) . should ( 'eq' , 'React App' ) ;
67
+
68
+ cy . get ( 'input[name="username"]' ) . type ( 'Katharina_Bernier' ) ;
69
+ cy . get ( 'input[name="password"]' ) . type ( 's3cret' ) ;
70
+ cy . get ( 'button[type="submit"]' ) . click ( ) ;
71
+
72
+ cy . get ( 'a[href="/transaction/new"]' ) . click ( ) ;
73
+ cy . server ( )
74
+ cy . route ( 'GET' , '/users/search?q=Devon+Becker' ) . as ( 'devonSearch' ) ;
75
+
76
+ //Intercept a REAL network request and modify it on the wire
77
+ cy . route2 ( '/users/search?q=Devon+Becker' , ( req ) => {
78
+ req . reply ( ( res ) => {
79
+ expect ( res ) . to . exist
80
+ console . log ( 'original response from the server is %s %o' , typeof res . body , res . body )
81
+ const modified_body = JSON . parse ( res . body )
82
+ modified_body . results [ 0 ] . firstName = "John"
83
+ modified_body . results [ 0 ] . lastName = "Hill"
84
+ //modified_body.modified = "2020-11-09T18:22:12.223143Z"
85
+ console . log ( 'new response from the server is %s %o' , typeof modified_body , modified_body )
86
+ res . send ( modified_body )
87
+ } )
88
+ } )
89
+
90
+ //Search for John Hill (a nonexistant User)
91
+ cy . get ( '[data-test=user-list-search-input]' ) . click ( ) . type ( 'Devon Becker' )
52
92
cy . wait ( '@devonSearch' )
53
93
54
94
//Verify that John Hill is returned from RWA
55
95
cy . get ( 'div#root div.MuiListItemText-root.MuiListItemText-multiline > span' ) . contains ( 'John Hill' )
56
96
97
+ cy . server ( { enable : false } )
57
98
} )
58
99
59
100
} )
0 commit comments