-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathreport-sent.spec.js
More file actions
169 lines (151 loc) · 5.4 KB
/
report-sent.spec.js
File metadata and controls
169 lines (151 loc) · 5.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
import { submitGetRequest } from '../../__test-helpers__/server.js'
import constants from '../../utils/constants.js'
import { questionSets } from '../../utils/question-sets.js'
import config from '../../utils/config.js'
import reportSentRoutes from '../report-sent.js'
const url = constants.routes.REPORT_SENT
const header = 'Report sent'
const submissionTimestamp = '2026-04-09T09:00:00.000Z'
const sessionId = 'test-session-id'
const expectedMediaUploadLink = `${config.mediaUploadUrl}/upload-photo?sirid=${sessionId}`
const journeySessionData = {
100: {
contactDetails: {
reporterEmailAddress: 'water@test.com'
},
imagesOrVideo: [{
answerId: questionSets.WATER_POLLUTION.questions.WATER_POLLUTION_IMAGES_OR_VIDEO.answers.yes.answerId
}]
},
200: {
contactDetails: {
reporterEmailAddress: 'smell@test.com'
},
imagesOrVideo: [{
answerId: questionSets.SMELL.questions.SMELL_IMAGES_OR_VIDEO.answers.yes.answerId
}]
},
300: {
contactDetails: {
reporterEmailAddress: 'blockage@test.com'
},
imagesOrVideo: [{
answerId: questionSets.BLOCKAGE.questions.BLOCKAGE_IMAGES_OR_VIDEO.answers.yes.answerId
}]
},
1800: {
contactDetails: {
reporterEmailAddress: 'fishing@test.com'
},
imagesOrVideo: [{
answerId: questionSets.ILLEGAL_FISHING.questions.ILLEGAL_FISHING_IMAGES_OR_VIDEO.answers.yes.answerId
}]
}
}
const handler = async (questionSetID, overrides = {}) => {
const set = jest.fn()
const view = jest.fn()
const defaultJourneyData = journeySessionData[questionSetID] || {
contactDetails: { reporterEmailAddress: '' },
imagesOrVideo: []
}
const contactDetails = overrides.contactDetails !== undefined
? overrides.contactDetails
: defaultJourneyData.contactDetails
const imagesOrVideo = overrides.imagesOrVideo !== undefined
? overrides.imagesOrVideo
: defaultJourneyData.imagesOrVideo
const keyMap = {
100: {
contactDetailsKey: constants.redisKeys.WATER_POLLUTION_CONTACT_DETAILS,
imagesOrVideoKey: constants.redisKeys.WATER_POLLUTION_IMAGES_OR_VIDEO
},
200: {
contactDetailsKey: constants.redisKeys.SMELL_CONTACT_DETAILS,
imagesOrVideoKey: constants.redisKeys.SMELL_IMAGES_OR_VIDEO
},
300: {
contactDetailsKey: constants.redisKeys.BLOCKAGE_CONTACT_DETAILS,
imagesOrVideoKey: constants.redisKeys.BLOCKAGE_IMAGES_OR_VIDEO
},
1800: {
contactDetailsKey: constants.redisKeys.ILLEGAL_FISHING_CONTACT_DETAILS,
imagesOrVideoKey: constants.redisKeys.ILLEGAL_FISHING_IMAGES_OR_VIDEO
}
}
const journeyKeys = keyMap[questionSetID] || {}
await reportSentRoutes[0].handler({
yar: {
get: jest.fn(key => ({
[constants.redisKeys.QUESTION_SET_ID]: questionSetID,
[constants.redisKeys.SUBMISSION_TIMESTAMP]: submissionTimestamp,
[journeyKeys.contactDetailsKey]: contactDetails,
[journeyKeys.imagesOrVideoKey]: imagesOrVideo
}[key])),
id: sessionId,
reset: jest.fn()
},
server: {
app: {
mediaUploadCache: { set }
}
}
}, { view })
return { set, view }
}
describe(url, () => {
describe('GET', () => {
it(`Should return success response and correct view for ${url}`, async () => {
await submitGetRequest({ url }, header)
})
it.each([
{ questionSetID: 100, expectedJourney: 'water pollution' },
{ questionSetID: 200, expectedJourney: 'smell' },
{ questionSetID: 300, expectedJourney: 'blockage' },
{ questionSetID: 1800, expectedJourney: 'illegal fishing' }
])('should cache journey "$expectedJourney" for questionSetID $questionSetID', async ({ questionSetID, expectedJourney }) => {
const { set } = await handler(questionSetID)
expect(set).toHaveBeenCalledWith(sessionId, {
journey: expectedJourney,
dateTime: submissionTimestamp
})
})
it('should pass mediaUploadLink in photoUploadDetails', async () => {
const { view } = await handler(100)
expect(view).toHaveBeenCalledWith(constants.views.REPORT_SENT, expect.objectContaining({
photoUploadDetails: expect.objectContaining({
mediaUploadLink: expectedMediaUploadLink
// mediaUploadLink: config.mediaUploadUrl
})
}))
})
it.each([
{ questionSetID: 100, email: 'water@test.com' },
{ questionSetID: 200, email: 'smell@test.com' },
{ questionSetID: 300, email: 'blockage@test.com' },
{ questionSetID: 1800, email: 'fishing@test.com' }
])('should pass photo upload details for questionSetID $questionSetID', async ({ questionSetID, email }) => {
const { view } = await handler(questionSetID)
expect(view).toHaveBeenCalledWith(constants.views.REPORT_SENT, expect.objectContaining({
photoUploadDetails: {
mediaUploadLink: expectedMediaUploadLink,
reportersEmail: email,
userAgreedForImages: true
}
}))
})
it('should default photo upload details when contact details and image answer are missing', async () => {
const { view } = await handler(100, {
contactDetails: null,
imagesOrVideo: null
})
expect(view).toHaveBeenCalledWith(constants.views.REPORT_SENT, expect.objectContaining({
photoUploadDetails: {
mediaUploadLink: expectedMediaUploadLink,
reportersEmail: '',
userAgreedForImages: false
}
}))
})
})
})