Skip to content

Commit

Permalink
SIR-948 other information
Browse files Browse the repository at this point in the history
  • Loading branch information
teddmason committed Sep 20, 2024
1 parent a00a095 commit d422246
Show file tree
Hide file tree
Showing 9 changed files with 238 additions and 154 deletions.
181 changes: 66 additions & 115 deletions server/__mock-data__/session-smell.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,58 @@ import moment from 'moment'

const yesterday = moment().seconds(0).milliseconds(0).subtract(1, 'days')
const today = moment().seconds(0).milliseconds(0)
const enterTheAddress = 'Enter the address'

const session = JSON.parse(`{
"home": {
"reporterName": "John Smith",
"reporterPhoneNumber": "012345678910",
"reporterEmailAddress": "[email protected]",
"reporterAccessCode": "password"
},
"smell/location-option": [
"smell/source": [
{
"questionId": 1200,
"questionAsked": "Where can you notice the smell?",
"questionId": 1600,
"questionAsked": "Where is the smell coming from?",
"questionResponse": true,
"answerId": 1601
}
],
"smell/source-details": [
{
"questionId": 32000,
"questionAsked": "Can you give details about where the smell is coming from?",
"questionResponse": true,
"answerId": 32002,
"otherDetails": "test"
},
{
"questionId": 32000,
"questionAsked": "Can you give details about where the smell is coming from?",
"questionResponse": true,
"answerId": 32003,
"otherDetails": "test"
},
{
"questionId": 32000,
"questionAsked": "Can you give details about where the smell is coming from?",
"questionResponse": true,
"answerId": 1201
"answerId": 32004,
"otherDetails": "test"
},
{
"questionId": 32000,
"questionAsked": "Can you give details about where the smell is coming from?",
"questionResponse": true,
"answerId": 32005,
"otherDetails": "m11mm"
}
],
"smell/location-home": [
{
"questionId": 3100,
"questionAsked": "Is the smell affecting you at home?",
"questionResponse": true,
"answerId": 30001
}
],
"smell/location-address": [
Expand All @@ -25,21 +63,21 @@ const session = JSON.parse(`{
"questionAsked": "Enter the address",
"questionResponse": true,
"answerId": 1401,
"otherDetails": "Test address 1"
"otherDetails": "address 1"
},
{
"questionId": 1400,
"questionAsked": "Enter the address",
"questionResponse": true,
"answerId": 1402,
"otherDetails": "test address 2"
"otherDetails": "address 2"
},
{
"questionId": 1400,
"questionAsked": "Enter the address",
"questionResponse": true,
"answerId": 1403,
"otherDetails": "city"
"otherDetails": "town"
},
{
"questionId": 1400,
Expand All @@ -53,70 +91,18 @@ const session = JSON.parse(`{
"questionAsked": "Enter the address",
"questionResponse": true,
"answerId": 1405,
"otherDetails": "M6 7PW"
},
{
"questionId": 1400,
"questionAsked": "Enter the address",
"questionResponse": true,
"answerId": 1406
}
],
"smell/smell-source": [
{
"questionId": 1600,
"questionAsked": "Do you know where the smell is coming from?",
"questionResponse": true,
"answerId": 1601
},
{
"questionId": 1600,
"questionAsked": "Do you know where the smell is coming from?",
"questionResponse": true,
"answerId": 1603,
"otherDetails": "test"
}
],
"smell/smell-description": [
{
"questionId": 1700,
"questionAsked": "How would you describe the smell?",
"questionResponse": true,
"answerId": 1701
},
{
"questionId": 1700,
"questionAsked": "How would you describe the smell?",
"questionResponse": true,
"answerId": 1703
}
],
"smell/previously-reported": [
{
"questionId": 1800,
"questionAsked": "Have you reported the smell before?",
"questionResponse": true,
"answerId": 1802
"otherDetails": "m11mm"
}
],
"smell/recurring-problem": [
"smell/previous": [
{
"questionId": 1900,
"questionAsked": "Has the same smell caused you a problem before?",
"questionAsked": "Has this smell caused you problems before?",
"questionResponse": true,
"answerId": 1901
}
],
"smell/past": [
{
"questionId": 2000,
"questionAsked": "How long has the smell been causing problems?",
"questionResponse": true,
"answerId": 2001,
"otherDetails": "test"
}
],
"smell/ongoing": [
"smell/current": [
{
"questionId": 2100,
"questionAsked": "Is the smell still there?",
Expand All @@ -129,73 +115,38 @@ const session = JSON.parse(`{
"questionId": 2200,
"questionAsked": "How strong is the smell?",
"questionResponse": true,
"answerId": 2201
"answerId": 2203
}
],
"smell/effect-on-activity": [
"smell/indoors": [
{
"questionId": 2300,
"questionAsked": "Has the smell stopped you from doing any of the following?",
"questionId": 3000,
"questionAsked": "Is the smell noticeable indoors?",
"questionResponse": true,
"answerId": 2301
"answerId": 30001
}
],
"smell/effect-on-daily-life": [
"smell/contact": [
{
"questionId": 2400,
"questionAsked": "Have any of the following happened?",
"questionId": 1,
"questionAsked": "Can we contact you for more information if needed?",
"questionResponse": true,
"answerId": 2401
"answerId": 2
}
],
"smell/effect-on-health": [
"smell/images-or-video": [
{
"questionId": 2500,
"questionAsked": "Did the smell cause any of the following?",
"questionId": 1,
"questionAsked": "Do you want to send us any images or videos of the problem?",
"questionResponse": true,
"answerId": 2501
"answerId": 2
}
],
"smell/other-information": "test",
"smell/date-time": "${yesterday.toISOString()}",
"smell/other-information": "This is a description of the odour",
"smell/start-date-time": "${yesterday.toISOString()}",
"submission-timestamp": "${today.toISOString()}"
}`)

const payload =
{
reportingAnEnvironmentalProblem: {
sessionGuid: 'fbeaf5ba-11bc-4478-942a-939fe0dc1e52',
reportType: 200,
datetimeObserved: yesterday.toISOString(),
datetimeReported: today.toISOString(),
reporterName: 'John Smith',
reporterPhoneNumber: '012345678910',
reporterAccessCode: 'password',
otherDetails: 'test',
questionSetId: 200,
data: [{ questionId: 1400, questionAsked: enterTheAddress, questionResponse: true, answerId: 1401, otherDetails: 'Test address 1' },
{ questionId: 1400, questionAsked: enterTheAddress, questionResponse: true, answerId: 1402, otherDetails: 'test address 2' },
{ questionId: 1400, questionAsked: enterTheAddress, questionResponse: true, answerId: 1403, otherDetails: 'city' },
{ questionId: 1400, questionAsked: enterTheAddress, questionResponse: true, answerId: 1404, otherDetails: 'county' },
{ questionId: 1400, questionAsked: enterTheAddress, questionResponse: true, answerId: 1405, otherDetails: 'M6 7PW' },
{ questionId: 1400, questionAsked: enterTheAddress, questionResponse: true, answerId: 1406 },
{ questionId: 1600, questionAsked: 'Do you know where the smell is coming from?', questionResponse: true, answerId: 1601 },
{ questionId: 1600, questionAsked: 'Do you know where the smell is coming from?', questionResponse: true, answerId: 1603, otherDetails: 'test' },
{ questionId: 1700, questionAsked: 'How would you describe the smell?', questionResponse: true, answerId: 1701 },
{ questionId: 1700, questionAsked: 'How would you describe the smell?', questionResponse: true, answerId: 1703 },
{ questionId: 1800, questionAsked: 'Have you reported the smell before?', questionResponse: true, answerId: 1802 },
{ questionId: 1900, questionAsked: 'Has the same smell caused you a problem before?', questionResponse: true, answerId: 1901 },
{ questionId: 2000, questionAsked: 'How long has the smell been causing problems?', questionResponse: true, answerId: 2001, otherDetails: 'test' },
{ questionId: 2100, questionAsked: 'Is the smell still there?', questionResponse: true, answerId: 2101 },
{ questionId: 2200, questionAsked: 'How strong is the smell?', questionResponse: true, answerId: 2201 },
{ questionId: 2300, questionAsked: 'Has the smell stopped you from doing any of the following?', questionResponse: true, answerId: 2301 },
{ questionId: 2400, questionAsked: 'Have any of the following happened?', questionResponse: true, answerId: 2401 },
{ questionId: 2500, questionAsked: 'Did the smell cause any of the following?', questionResponse: true, answerId: 2501 }
]
}
}

export {
session,
payload
session
}
8 changes: 4 additions & 4 deletions server/routes/__tests__/old-smell/other-information.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ describe(url, () => {

describe('POST', () => {
it('Should accept and store a description', async () => {
const otherDetails = 'This is a description of the odour'
const otherInfo = 'This is a description of the odour'
const options = {
url,
payload: {
otherDetails
otherInfo
}
}
const response = await submitPostRequest(options, 302, session)
Expand All @@ -32,7 +32,7 @@ describe(url, () => {
reporterName: 'John Smith',
reporterPhoneNumber: '012345678910',
reporterAccessCode: 'password',
otherDetails,
otherDetails: otherInfo,
questionSetId: 200,
data: expect.arrayContaining([
expect.objectContaining({ questionId: 1400, questionAsked: enterTheAddress, questionResponse: true, answerId: 1401, otherDetails: 'Test address 1' }),
Expand All @@ -58,7 +58,7 @@ describe(url, () => {
])
})
}))
expect(response.request.yar.get(constants.redisKeys.SMELL_OTHER_INFORMATION)).toEqual(otherDetails)
expect(response.request.yar.get(constants.redisKeys.SMELL_OTHER_INFORMATION)).toEqual(otherInfo)
expect(new Date(response.request.yar.get(constants.redisKeys.SUBMISSION_TIMESTAMP))).toBeInstanceOf(Date)
})
it('Should error if validatePayload fails', async () => {
Expand Down
79 changes: 79 additions & 0 deletions server/routes/__tests__/smell/other-information.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import { submitGetRequest, submitPostRequest } from '../../../__test-helpers__/server.js'
import constants from '../../../utils/constants.js'
import { sendMessage } from '../../../services/service-bus.js'
import { session } from '../../../__mock-data__/session-smell.js'
jest.mock('../../../services/service-bus.js')

const url = constants.routes.SMELL_OTHER_INFORMATION
const header = 'Is there anything else you\'d like to add (optional)?'

describe(url, () => {
describe('GET', () => {
it(`Should return success response and correct view for ${url}`, async () => {
await submitGetRequest({ url }, header)
})
})

describe('POST', () => {
it('Should accept and store a description', async () => {
const otherInfo = 'This is a description of the odour'
const options = {
url,
payload: {
otherInfo
}
}
const response = await submitPostRequest(options, 302, session)
expect(sendMessage).toHaveBeenCalledTimes(1)
expect(sendMessage).toHaveBeenCalledWith(expect.objectContaining({
reportingAnEnvironmentalProblem: expect.objectContaining({
reportType: 200,
reporterName: 'John Smith',
reporterPhoneNumber: '012345678910',
reporterAccessCode: 'password',
reporterEmailAddress: '[email protected]',
otherDetails: otherInfo,
questionSetId: 200,
data: expect.arrayContaining([
expect.objectContaining({ questionId: 1600, questionAsked: 'Where is the smell coming from?', questionResponse: true, answerId: 1601 }),
expect.objectContaining({ questionId: 32000, questionAsked: 'Can you give details about where the smell is coming from?', questionResponse: true, answerId: 32002, otherDetails: 'test' }),
expect.objectContaining({ questionId: 32000, questionAsked: 'Can you give details about where the smell is coming from?', questionResponse: true, answerId: 32003, otherDetails: 'test' }),
expect.objectContaining({ questionId: 32000, questionAsked: 'Can you give details about where the smell is coming from?', questionResponse: true, answerId: 32004, otherDetails: 'test' }),
expect.objectContaining({ questionId: 32000, questionAsked: 'Can you give details about where the smell is coming from?', questionResponse: true, answerId: 32005, otherDetails: 'm11mm' }),
expect.objectContaining({ questionId: 3100, questionAsked: 'Is the smell affecting you at home?', questionResponse: true, answerId: 30001 }),
expect.objectContaining({ questionId: 1400, questionAsked: 'Enter the address', questionResponse: true, answerId: 1401, otherDetails: 'address 1' }),
expect.objectContaining({ questionId: 1400, questionAsked: 'Enter the address', questionResponse: true, answerId: 1402, otherDetails: 'address 2' }),
expect.objectContaining({ questionId: 1400, questionAsked: 'Enter the address', questionResponse: true, answerId: 1403, otherDetails: 'town' }),
expect.objectContaining({ questionId: 1400, questionAsked: 'Enter the address', questionResponse: true, answerId: 1404, otherDetails: 'county' }),
expect.objectContaining({ questionId: 1400, questionAsked: 'Enter the address', questionResponse: true, answerId: 1405, otherDetails: 'm11mm' }),
expect.objectContaining({ questionId: 1900, questionAsked: 'Has this smell caused you problems before?', questionResponse: true, answerId: 1901 }),
expect.objectContaining({ questionId: 2100, questionAsked: 'Is the smell still there?', questionResponse: true, answerId: 2101 }),
expect.objectContaining({ questionId: 2200, questionAsked: 'How strong is the smell?', questionResponse: true, answerId: 2203 }),
expect.objectContaining({ questionId: 3000, questionAsked: 'Is the smell noticeable indoors?', questionResponse: true, answerId: 30001 }),
expect.objectContaining({ questionId: 1, questionAsked: 'Can we contact you for more information if needed?', questionResponse: true, answerId: 2 }),
expect.objectContaining({ questionId: 1, questionAsked: 'Do you want to send us any images or videos of the problem?', questionResponse: true, answerId: 2 })
])
})
}))
expect(response.request.yar.get(constants.redisKeys.SMELL_OTHER_INFORMATION)).toEqual(otherInfo)
expect(new Date(response.request.yar.get(constants.redisKeys.SUBMISSION_TIMESTAMP))).toBeInstanceOf(Date)
expect(response.headers.location).toEqual(constants.routes.REPORT_SENT)
})
it('Should error if validatePayload fails', async () => {
const { submitPostRequest } = await import('../../../__test-helpers__/server.js')
const helpers = await import('../../../utils/helpers.js')
helpers.validatePayload = jest.fn().mockImplementation(() => {
return false
})

const otherInfo = 'This is a description of the odour'
const options = {
url,
payload: {
otherInfo
}
}
await submitPostRequest(options, 500)
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ describe(url, () => {
}))
expect(response.request.yar.get(constants.redisKeys.WATER_POLLUTION_OTHER_INFORMATION)).toEqual(otherInfo)
expect(new Date(response.request.yar.get(constants.redisKeys.SUBMISSION_TIMESTAMP))).toBeInstanceOf(Date)
expect(response.headers.location).toEqual(constants.routes.REPORT_SENT)
})
it('Should error if validatePayload fails', async () => {
const { submitPostRequest } = await import('../../../__test-helpers__/server.js')
Expand Down
Loading

0 comments on commit d422246

Please sign in to comment.