From 550039bbc0438fc27e23b5e60e152a1bd43b97b1 Mon Sep 17 00:00:00 2001 From: nwycherley Date: Fri, 11 Jan 2019 11:21:39 +0000 Subject: [PATCH] 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 --- lib/functions/processMessage.js | 2 +- test/processMessage.js | 37 +++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/lib/functions/processMessage.js b/lib/functions/processMessage.js index caf541c..a0a0fba 100644 --- a/lib/functions/processMessage.js +++ b/lib/functions/processMessage.js @@ -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 diff --git a/test/processMessage.js b/test/processMessage.js index 9ad1da2..a635916 100644 --- a/test/processMessage.js +++ b/test/processMessage.js @@ -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') + }) })