Skip to content

Commit

Permalink
Changed if the last message is active then update references and msgt…
Browse files Browse the repository at this point in the history
…ype to include previous active message and added unit test to check its there if active
  • Loading branch information
nwycherley authored and teddmason committed Jan 15, 2019
1 parent e9e0d9b commit 550039b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/functions/processMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ module.exports.processMessage = async (event) => {

// If the last message is active then update references and msgtype
if (lastMessage && lastMessage.expires > new Date()) {
xmlResult.alert.references = [lastMessage.references ? lastMessage.references : xmlResult.alert.sender[0] + ',' + lastMessage.identifier + ',' + moment(lastMessage.sent).utc().format('YYYY-MM-DDTHH:mm:ssZ')]
xmlResult.alert.references = [lastMessage.references ? lastMessage.references + ' ' + xmlResult.alert.sender[0] + ',' + xmlResult.alert.identifier + ',' + moment(xmlResult.alert.sent).utc().format('YYYY-MM-DDTHH:mm:ssZ') : xmlResult.alert.sender[0] + ',' + lastMessage.identifier + ',' + moment(lastMessage.sent).utc().format('YYYY-MM-DDTHH:mm:ssZ')]
xmlResult.alert.msgType[0] = xmlResult.alert.msgType[0] === 'Alert' ? 'Update' : xmlResult.alert.msgType[0]
} else {
delete xmlResult.alert.references
Expand Down
37 changes: 37 additions & 0 deletions test/processMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,4 +293,41 @@ lab.experiment('processMessage', () => {
Code.expect(err).to.be.an.error()
}
})

lab.test('Correct data test for processMessage where previous message is active and has reference', async () => {
const config = require('../config/config.json')
config.aws.stage = 'ea'

service.getLastMessage = (id) => {
return new Promise((resolve, reject) => {
resolve({
rows: [{
id: '51',
identifier: '4eb3b7350ab7aa443650fc9351f2',
expires: tomorrow,
sent: yesterday,
references: 'Previous_Active_Message'
}]
})
})
}

service.putMessage = (query) => {
return new Promise((resolve, reject) => {
Code.expect(query.values[2]).to.not.be.empty()
Code.expect(query.values[1]).to.equal('Update')
Code.expect(query.values[2]).to.contain('Previous_Active_Message www.gov.uk/environment-agency')
resolve()
})
}

const ret = await processMessage(capAlert)
Code.expect(ret.statusCode).to.equal(200)
Code.expect(ret.body.identifier).to.equal('4eb3b7350ab7aa443650fc9351f02940E')
Code.expect(ret.body.fwisCode).to.equal('TESTAREA1')
Code.expect(ret.body.sent).to.equal('2017-05-28T11:00:02-00:00')
Code.expect(ret.body.expires).to.equal('2017-05-29T11:00:02-00:00')
Code.expect(ret.body.status).to.not.equal('Test')
Code.expect(ret.body.status).to.equal('Actual')
})
})

0 comments on commit 550039b

Please sign in to comment.