Skip to content

Commit 35fc585

Browse files
authored
Merge pull request #247 from scientist-softserv/239-requests-page-tests
refactor to use switch case & fix error test
2 parents 625df93 + 2cc35c1 commit 35fc585

File tree

1 file changed

+34
-22
lines changed

1 file changed

+34
-22
lines changed

cypress/e2e/requests.cy.js

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,33 @@ describe('Viewing all requests', () => {
2222
// Intercept the response from the endpoint to view all requests
2323
// TODO(summer-cook): extract out this base url into the config to use as an environment variable. it was not cooperating before
2424
cy.intercept('GET', `${scientistApiBaseURL}/quote_groups/mine.json`, (req) => {
25-
if ((requestList === undefined) && (loading === true)) {
25+
switch (true) {
2626
// reply with an empty response: both data and error will be undefined.
27-
req.reply()
28-
} else if ((requestList === undefined) && (loading === false) && (error === true)) {
27+
case loading: req.reply()
28+
break
29+
2930
// error will be defined
30-
req.reply({ statusCode: 500 })
31-
} else if (requestList === true) {
31+
case error: req.reply({ statusCode: 500 })
32+
break
33+
34+
case requestList: req.reply({ fixture: 'all-requests/requests.json' })
35+
break
36+
3237
// reply with a request body- default status code is 200
33-
req.reply({ fixture: 'all-requests/requests.json' })
34-
} else if (requestList === false) {
35-
req.reply({ fixture: 'all-requests/no-requests.json' })
38+
case !requestList: req.reply({ fixture: 'all-requests/no-requests.json' })
39+
break
3640
}
3741
})
3842
// Intercept the response from the endpoint that gets the default ware ID
39-
cy.intercept('GET', `${scientistApiBaseURL}/wares.json?q=make-a-request`, { fixture: 'all-requests/make-a-request.json' })
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+
}
51+
})
4052
cy.visit('/requests')
4153
})
4254

@@ -52,24 +64,24 @@ describe('Viewing all requests', () => {
5264
})
5365
})
5466

55-
// TODO: uncomment this and try to make the page it not get an undefined error
56-
// context('error while making a request to the api', () => {
57-
// before(() => {
58-
// requestList = undefined
59-
// loading = false
60-
// error = true
61-
// })
62-
// it('should show an error message.', () => {
63-
// cy.get("div[role='alert']").should('be.visible').then(() => {
64-
// cy.log('Successfully hits an error.')
65-
// })
66-
// })
67-
// })
67+
context('error while making a request to the api', () => {
68+
before(() => {
69+
requestList = undefined
70+
loading = false
71+
error = true
72+
})
73+
it('should show an error message.', () => {
74+
cy.get("div[role='alert']").should('be.visible').then(() => {
75+
cy.log('Successfully hits an error.')
76+
})
77+
})
78+
})
6879

6980
describe('request components are loading successfully, &', () => {
7081
context('the user has requests', () => {
7182
before(() => {
7283
requestList = true
84+
error = false
7385
})
7486
it("should show the user's request list.", () => {
7587
cy.get('article.request-item').should('exist').then(() => {

0 commit comments

Comments
 (0)