Skip to content

Commit c3ec0b9

Browse files
committed
Test email verification journey
1 parent 4107d49 commit c3ec0b9

File tree

5 files changed

+73
-6
lines changed

5 files changed

+73
-6
lines changed

e2e/fixtures/server.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
const express = require('express')
22
const cors = require('cors')
3+
const morgan = require('morgan')
34

45
const port = parseInt(process.env.MOCK_PORT || '3001')
56

67
const app = express()
78
.use(cors())
89
.use(express.json({ type: '*/*' }))
10+
.use(morgan('dev'))
911

1012
const calls = []
1113

@@ -14,11 +16,9 @@ app.get('/cities', (_, res) => {
1416
})
1517

1618
app.post('/volunteer', (req, res) => {
17-
console.log({
18-
body: req.body,
19-
headers: req.headers
20-
})
2119
calls.push({
20+
method: 'POST',
21+
path: '/volunteer',
2222
body: req.body,
2323
headers: req.headers
2424
})
@@ -34,6 +34,17 @@ app.post('/_reset', (req, res) => {
3434
res.sendStatus(204)
3535
})
3636

37+
app.use((req, res) => {
38+
const call = {
39+
body: req.body,
40+
headers: req.headers,
41+
method: req.method,
42+
path: req.path
43+
}
44+
calls.push(call)
45+
res.sendStatus(200)
46+
})
47+
3748
app.listen(port, () => {
3849
console.log(`Listening on ${port}`)
3950
})

e2e/integration/journey.test.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ it('can submit a minimal form', () => {
4242
cy.findByRole('button', { name: /submit/i }).click()
4343

4444
cy.request(`${mockServerURL}/_calls`).then(response => {
45-
const [{ body: payload }] = response.body
45+
const [{ body: payload, method, path }] = response.body
46+
expect(method).to.equal('POST')
47+
expect(path).to.equal('/volunteer')
4648
expect(payload).to.deep.eq({
4749
...initialData,
4850
agreeToReceiveCommunication: true,

e2e/integration/withCode.test.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const mockServerURL = 'http://localhost:3001'
2+
3+
beforeEach(() => {
4+
cy.request('POST', `${mockServerURL}/_reset`)
5+
})
6+
7+
it('lets you request a reminder email', () => {
8+
const userId = 'whoever'
9+
const code = 'whatever'
10+
const email = '[email protected]'
11+
cy.visit(`/code/${userId}/${code}`)
12+
13+
cy.findByText(/you have been re-directed to fill in this form/i).should(
14+
'exist'
15+
)
16+
// TODO why is this a clickable span?!
17+
cy.findByText('here').click()
18+
// TODO not accessible by label
19+
cy.findByRole('textbox').type(email)
20+
cy.findByRole('button', { name: /submit/i }).click()
21+
cy.request(`${mockServerURL}/_calls`).then(({ body }) => {
22+
expect(body).to.have.length(1)
23+
const [{ body: payload, method, path }] = body
24+
expect(method).to.equal('POST')
25+
expect(path).to.equal('/volunteer/email/verification')
26+
expect(payload).to.deep.equal({ email, userId })
27+
})
28+
})

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
"eslint-plugin-react": "^7.14.3",
7878
"husky": "^3.0.4",
7979
"lint-staged": "^9.2.5",
80+
"morgan": "^1.10.0",
8081
"prettier": "^1.18.2",
8182
"serve": "^13.0.4",
8283
"wait-on": "^3.3.0"

yarn.lock

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2942,6 +2942,13 @@ base@^0.11.1:
29422942
mixin-deep "^1.2.0"
29432943
pascalcase "^0.1.1"
29442944

2945+
basic-auth@~2.0.1:
2946+
version "2.0.1"
2947+
resolved "https://registry.yarnpkg.com/basic-auth/-/basic-auth-2.0.1.tgz#b998279bf47ce38344b4f3cf916d4679bbf51e3a"
2948+
integrity sha512-NF+epuEdnUYVlGuhaxbbq+dvJttwLnGY+YixlXlME5KpQ5W3CnXA5cVTneY3SPbPDRkcjMbifrwmFYcClgOZeg==
2949+
dependencies:
2950+
safe-buffer "5.1.2"
2951+
29452952
29462953
version "0.6.1"
29472954
resolved "https://registry.yarnpkg.com/batch/-/batch-0.6.1.tgz#dc34314f4e679318093fc760272525f94bf25c16"
@@ -4750,7 +4757,7 @@ delegates@^1.0.0:
47504757
resolved "https://registry.yarnpkg.com/delegates/-/delegates-1.0.0.tgz#84c6e159b81904fdca59a0ef44cd870d31250f9a"
47514758
integrity sha512-bd2L678uiWATM6m5Z1VzNCErI3jiGzt6HGY8OVICs40JQq/HALfbyNJmp0UDakEY4pMMaN0Ly5om/B1VI/+xfQ==
47524759

4753-
4760+
[email protected], depd@~2.0.0:
47544761
version "2.0.0"
47554762
resolved "https://registry.yarnpkg.com/depd/-/depd-2.0.0.tgz#b696163cc757560d09cf22cc8fad1571b79e76df"
47564763
integrity sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==
@@ -9605,6 +9612,17 @@ moment@^2.21.0, moment@^2.22.2, moment@^2.23.0:
96059612
resolved "https://registry.yarnpkg.com/moment/-/moment-2.29.4.tgz#3dbe052889fe7c1b2ed966fcb3a77328964ef108"
96069613
integrity sha512-5LC9SOxjSc2HF6vO2CyuTDNivEdoz2IvyJJGj6X8DJ0eFyfszE0QiEd+iXmBvUP3WHxSjFH/vIsA0EN00cgr8w==
96079614

9615+
morgan@^1.10.0:
9616+
version "1.10.0"
9617+
resolved "https://registry.yarnpkg.com/morgan/-/morgan-1.10.0.tgz#091778abc1fc47cd3509824653dae1faab6b17d7"
9618+
integrity sha512-AbegBVI4sh6El+1gNwvD5YIck7nSA36weD7xvIxG4in80j/UoK8AEGaWnnz8v1GxonMCltmlNs5ZKbGvl9b1XQ==
9619+
dependencies:
9620+
basic-auth "~2.0.1"
9621+
debug "2.6.9"
9622+
depd "~2.0.0"
9623+
on-finished "~2.3.0"
9624+
on-headers "~1.0.2"
9625+
96089626
move-concurrently@^1.0.1:
96099627
version "1.0.1"
96109628
resolved "https://registry.yarnpkg.com/move-concurrently/-/move-concurrently-1.0.1.tgz#be2c005fda32e0b29af1f05d7c4b33214c701f92"
@@ -10303,6 +10321,13 @@ [email protected]:
1030310321
dependencies:
1030410322
ee-first "1.1.1"
1030510323

10324+
on-finished@~2.3.0:
10325+
version "2.3.0"
10326+
resolved "https://registry.yarnpkg.com/on-finished/-/on-finished-2.3.0.tgz#20f1336481b083cd75337992a16971aa2d906947"
10327+
integrity sha512-ikqdkGAAyf/X/gPhXGvfgAytDZtDbr+bkNUJ0N9h5MI/dmdgCs3l6hoHrcUv41sRKew3jIwrp4qQDXiK99Utww==
10328+
dependencies:
10329+
ee-first "1.1.1"
10330+
1030610331
on-headers@~1.0.1, on-headers@~1.0.2:
1030710332
version "1.0.2"
1030810333
resolved "https://registry.yarnpkg.com/on-headers/-/on-headers-1.0.2.tgz#772b0ae6aaa525c399e489adfad90c403eb3c28f"

0 commit comments

Comments
 (0)