Skip to content
This repository has been archived by the owner on May 7, 2021. It is now read-only.

show self harm words at the top of intake report #1515

Merged
merged 6 commits into from
Feb 24, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions f2/src/utils/__tests__/formatAnalystEmail.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,14 @@ describe('formatAnalystEmail', () => {
expect(s).toEqual(expect.stringMatching(/ERROR/))
expect(console.error).toHaveBeenCalled()
})

it('flags self harm words prominently if present', () => {
const data = { selfHarmWords: 'agile' }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👀

Copy link
Contributor Author

@sastels sastels Feb 24, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👀

The test uses a fake list of self harm words, as CAFC didn't want us to put the real list in the repo.

console.error = jest.fn()
const s = formatAnalystEmail(data)
expect(s).toEqual(
expect.stringMatching(/^\n\nSELF HARM WORDS FOUND : agile/),
)
expect(console.error).toHaveBeenCalled()
})
})
36 changes: 25 additions & 11 deletions f2/src/utils/formatAnalystEmail.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@
const formatLine = (label, text) => (text !== '' ? label + text + '\n' : '')

const formatReportInfo = data => {
const selfHarmString = data.selfHarmWords.length
? data.selfHarmWords
: 'no self harm words'
const returnString =
let selfHarmString = 'no self harm words'
let returnString = ''

if (data.selfHarmWords.length) {
selfHarmString = data.selfHarmWords
returnString = `\n\nSELF HARM WORDS FOUND : ${selfHarmString}\n\n`
}
returnString +=
'Report information\n\n' +
formatLine('Report number: ', data.reportId) +
formatLine('Date received: ', data.submissionTime) +
formatLine('Report language: ', data.language) +
Expand All @@ -16,9 +21,7 @@ const formatReportInfo = data => {
delete data.submissionTime // so that at the end we can display the rest and ensure that
delete data.language // we didn't miss anything
delete data.selfHarmWords
return (
'Report information\n\n' + (returnString !== '' ? returnString : 'No Data')
)
return returnString
}

const formatVictimDetails = data => {
Expand Down Expand Up @@ -211,13 +214,22 @@ const formatFileAttachments = data => {
}

const formatAnalystEmail = dataOrig => {
let returnString
let returnString = ''
let reportInfoString = ''
let missingFields

let data
try {
data = JSON.parse(JSON.stringify(dataOrig))
reportInfoString = formatReportInfo(data)
} catch (error) {
const errorMessage = `ERROR in formatAnalystEmail (report ${dataOrig.reportId}): ${error}`
console.error(errorMessage)
return errorMessage
}
try {
let data = JSON.parse(JSON.stringify(dataOrig))
returnString =
formatReportInfo(data) +
reportInfoString +
formatVictimDetails(data) +
formatIncidentInformation(data) +
formatNarrative(data) +
Expand All @@ -233,7 +245,9 @@ const formatAnalystEmail = dataOrig => {
? '\n\nExtra Fields:\n' + JSON.stringify(data, null, ' ')
: ''
} catch (error) {
const errorMessage = `ERROR in formatAnalystEmail (report ${dataOrig.reportId}): ${error}`
const errorMessage =
reportInfoString +
`\nERROR in formatAnalystEmail (report ${dataOrig.reportId}): ${error}`
console.error(errorMessage)
return errorMessage
}
Expand Down