Skip to content

Commit bf2787c

Browse files
author
John Hill
committed
add route2
1 parent 6f715ec commit bf2787c

File tree

4 files changed

+288
-343
lines changed

4 files changed

+288
-343
lines changed

frameworks/cypress/cypress.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55
"fixturesFolder": false,
66
"screenshotsFolder": "./frameworks/cypress/screenshots",
77
"pluginsFile": false,
8-
"integrationFolder": "./frameworks/cypress/integration/"
8+
"integrationFolder": "./frameworks/cypress/integration/",
9+
"experimentalNetworkStubbing": true
910
}

frameworks/cypress/integration/RWA.spec.js

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ describe('Can find existing user in RWA', () => {
33
//Navigate to RWA
44
cy.visit('http://localhost:3000');
55
});
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', () => {
77

88
//Check Title
99
cy.title().should('eq', 'React App');
@@ -27,9 +27,11 @@ describe('Can find existing user in RWA', () => {
2727
cy.wait('@devonSearch')
2828

2929
cy.get('div#root div.MuiListItemText-root.MuiListItemText-multiline > span').contains('Devon Becker')
30+
31+
cy.server({ enable: false })
3032
})
3133

32-
it.skip('Can Find a Mocked User and Intercept', () => {
34+
it('Can Find a Mocked User and Intercept', () => {
3335
cy.title().should('eq', 'React App');
3436

3537
cy.get('input[name="username"]').type('Katharina_Bernier');
@@ -38,22 +40,61 @@ describe('Can find existing user in RWA', () => {
3840

3941
cy.get('a[href="/transaction/new"]').click();
4042

41-
//Mock a new Network Response and alias
43+
//Mock a new Network Response in totality from the server
4244
cy.server({
4345
method: 'GET',
4446
status: 200,
4547
request: '/users/search?q=Devon+Becker',
4648
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"}]}
4749
})
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');
4952

5053
//Search for John Hill (a nonexistant User)
5154
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')
5292
cy.wait('@devonSearch')
5393

5494
//Verify that John Hill is returned from RWA
5595
cy.get('div#root div.MuiListItemText-root.MuiListItemText-multiline > span').contains('John Hill')
5696

97+
cy.server({ enable: false })
5798
})
5899

59100
})

0 commit comments

Comments
 (0)