Skip to content

Commit

Permalink
Feature/flo 3290 (#7)
Browse files Browse the repository at this point in the history
*  CAP XML <references> tag changes

https://eaflood.atlassian.net/browse/FLO-3290

The requirement for change is to show <sender>, <identifier> and <sent> values for all messages from when its originally published to it being removed.

* Changed if the last message is active then update references and msgtype to include previous active message and added unit test to check its there if active

* FLO-3290 Changed concatonated message to now pull in last message instead of current and now pulls the correct date

* FLO-3290 Changed concatonated message to now pull in last message instead of current and now pulls the correct date

* FLO_3290 changed unit tests to check past date is added
  • Loading branch information
nikiwycherley authored and teddmason committed Jan 17, 2019
1 parent 550039b commit cc3da44
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/functions/processMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ 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] + ',' + 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.references = [lastMessage.references ? lastMessage.references + ' ' + xmlResult.alert.sender[0] + ',' + lastMessage.identifier + ',' + moment(lastMessage.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
}

const message = new Message(xmlResult)

console.log('Processing CAP message: ' + message.data.identifier + ' for ' + message.data.fwis_code)
Expand Down
5 changes: 4 additions & 1 deletion test/processMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const lab = exports.lab = Lab.script()
const Code = require('code')
const processMessage = require('../lib/functions/processMessage').processMessage
const service = require('../lib/helpers/service')
const moment = require('moment')
let capAlert
let capUpdate

Expand Down Expand Up @@ -314,9 +315,11 @@ lab.experiment('processMessage', () => {

service.putMessage = (query) => {
return new Promise((resolve, reject) => {
const lastDate = moment(yesterday).utc().format('YYYY-MM-DDTHH:mm:ssZ')
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')
Code.expect(query.values[2]).to.contain(`Previous_Active_Message www.gov.uk/environment-agency,4eb3b7350ab7aa443650fc9351f2,${lastDate}`)
Code.expect(query.values[2]).to.not.contain('00:00+00:00')
resolve()
})
}
Expand Down

0 comments on commit cc3da44

Please sign in to comment.