diff --git a/package-lock.json b/package-lock.json index 75554cf..2befe97 100644 --- a/package-lock.json +++ b/package-lock.json @@ -33,6 +33,7 @@ "@hapi/code": "9.0.3", "@hapi/lab": "26.0.0", "proxyquire": "2.1.3", + "sinon": "21.0.0", "standard": "17.1.2" }, "engines": { @@ -1742,6 +1743,47 @@ "integrity": "sha512-RNiOoTPkptFtSVzQevY/yWtZwf/RxyVnPy/OcA9HBM3MlGDnBEYL5B41H0MTn0Uec8Hi+2qUtTfG2WWZBmMejQ==", "license": "BSD-3-Clause" }, + "node_modules/@sinonjs/commons": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/@sinonjs/commons/-/commons-3.0.1.tgz", + "integrity": "sha512-K3mCHKQ9sVh8o1C9cxkwxaOmXoAMlDxC1mYyHrjqOWEcBjYr76t96zL2zlj5dUGZ3HSw240X1qgH3Mjf1yJWpQ==", + "dev": true, + "license": "BSD-3-Clause", + "dependencies": { + "type-detect": "4.0.8" + } + }, + "node_modules/@sinonjs/fake-timers": { + "version": "13.0.5", + "resolved": "https://registry.npmjs.org/@sinonjs/fake-timers/-/fake-timers-13.0.5.tgz", + "integrity": "sha512-36/hTbH2uaWuGVERyC6da9YwGWnzUZXuPro/F2LfsdOsLnCojz/iSH8MxUt/FD2S5XBSVPhmArFUXcpCQ2Hkiw==", + "dev": true, + "license": "BSD-3-Clause", + "dependencies": { + "@sinonjs/commons": "^3.0.1" + } + }, + "node_modules/@sinonjs/samsam": { + "version": "8.0.3", + "resolved": "https://registry.npmjs.org/@sinonjs/samsam/-/samsam-8.0.3.tgz", + "integrity": "sha512-hw6HbX+GyVZzmaYNh82Ecj1vdGZrqVIn/keDTg63IgAwiQPO+xCz99uG6Woqgb4tM0mUiFENKZ4cqd7IX94AXQ==", + "dev": true, + "license": "BSD-3-Clause", + "dependencies": { + "@sinonjs/commons": "^3.0.1", + "type-detect": "^4.1.0" + } + }, + "node_modules/@sinonjs/samsam/node_modules/type-detect": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/type-detect/-/type-detect-4.1.0.tgz", + "integrity": "sha512-Acylog8/luQ8L7il+geoSxhEkazvkslg7PSNKOX59mbB9cOveP5aq9h74Y7YU8yDpJwetzQQrfIwtf4Wp4LKcw==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=4" + } + }, "node_modules/@standard-schema/spec": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/@standard-schema/spec/-/spec-1.0.0.tgz", @@ -6098,6 +6140,34 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/sinon": { + "version": "21.0.0", + "resolved": "https://registry.npmjs.org/sinon/-/sinon-21.0.0.tgz", + "integrity": "sha512-TOgRcwFPbfGtpqvZw+hyqJDvqfapr1qUlOizROIk4bBLjlsjlB00Pg6wMFXNtJRpu+eCZuVOaLatG7M8105kAw==", + "dev": true, + "license": "BSD-3-Clause", + "dependencies": { + "@sinonjs/commons": "^3.0.1", + "@sinonjs/fake-timers": "^13.0.5", + "@sinonjs/samsam": "^8.0.1", + "diff": "^7.0.0", + "supports-color": "^7.2.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/sinon" + } + }, + "node_modules/sinon/node_modules/diff": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/diff/-/diff-7.0.0.tgz", + "integrity": "sha512-PJWHUb1RFevKCwaFA9RlG5tCd+FO5iRh9A8HEtkmBH2Li03iJriB6m6JIN4rGz3K3JLawI7/veA1xzRKP6ISBw==", + "dev": true, + "license": "BSD-3-Clause", + "engines": { + "node": ">=0.3.1" + } + }, "node_modules/slash": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/slash/-/slash-3.0.0.tgz", @@ -6839,6 +6909,16 @@ "node": ">= 0.8.0" } }, + "node_modules/type-detect": { + "version": "4.0.8", + "resolved": "https://registry.npmjs.org/type-detect/-/type-detect-4.0.8.tgz", + "integrity": "sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=4" + } + }, "node_modules/typed-array-buffer": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/typed-array-buffer/-/typed-array-buffer-1.0.3.tgz", diff --git a/package.json b/package.json index 4d9f6e4..4410cd0 100644 --- a/package.json +++ b/package.json @@ -48,6 +48,7 @@ "@hapi/code": "9.0.3", "@hapi/lab": "26.0.0", "proxyquire": "2.1.3", + "sinon": "21.0.0", "standard": "17.1.2" }, "standard": { diff --git a/readme.md b/readme.md index 8f3c316..35c2a25 100644 --- a/readme.md +++ b/readme.md @@ -11,7 +11,6 @@ This is the FWIS management tool | PORT | Port number | no | 3000 | | | | FWS_API_URL | API url | yes | | | | | FWS_API_KEY | API key | yes | | | | -| FWS_APP_PROXY | Proxy | no | | | | | AD_CLIENT_ID | AD Client Id | yes | | | | | AD_CLIENT_SECRET | AD Client Secret | yes | | | | | AD_TENANT | AD Tenant | yes | | | | diff --git a/server/config.js b/server/config.js index 949dbd1..4cb4226 100644 --- a/server/config.js +++ b/server/config.js @@ -6,7 +6,6 @@ const schema = Joi.object({ env: Joi.string().valid('dev', 'tst', 'pre', 'prd', 'tra').default('dev'), api: Joi.string().uri().required(), apiKey: Joi.string().required(), - proxy: Joi.string().uri().allow(''), adClientId: Joi.string().required(), adClientSecret: Joi.string().required(), adTenant: Joi.string().required(), @@ -28,7 +27,6 @@ const config = { env: process.env.FWS_ENV_NAME, api: process.env.FWS_API_URL, apiKey: process.env.FWS_API_KEY, - proxy: process.env.FWS_APP_PROXY, adClientId: process.env.AD_CLIENT_ID, adClientSecret: process.env.AD_CLIENT_SECRET, adTenant: process.env.AD_TENANT, diff --git a/server/http.js b/server/http.js index 3b7220d..8bcc46f 100644 --- a/server/http.js +++ b/server/http.js @@ -1,5 +1,4 @@ const config = require('./config') -const { HttpsProxyAgent } = require('https-proxy-agent') // Timeout is high to accomodate the use of lambda backend functions const timeout = 30 * 1000 @@ -7,18 +6,10 @@ const timeout = 30 * 1000 const wreck = require('@hapi/wreck').defaults({ timeout }) -let wreckExt -if (config.proxy) { - wreckExt = require('@hapi/wreck').defaults({ - timeout, - agent: new HttpsProxyAgent(config.proxy) - }) -} module.exports = { - getJson: function (url, ext = false) { - const thisWreck = (ext && wreckExt) ? wreckExt : wreck - return thisWreck + getJson: function (url) { + return wreck .get(url, { json: true, headers: { @@ -32,9 +23,8 @@ module.exports = { return response.payload }) }, - postJson: function (url, payload, ext = false) { - const thisWreck = (ext && wreckExt) ? wreckExt : wreck - return thisWreck + postJson: function (url, payload) { + return wreck .post(url, { json: true, payload, diff --git a/test/data/getFloodsPlus.json b/test/data/getFloodsPlus.json index cd4bbe4..93db1f0 100644 --- a/test/data/getFloodsPlus.json +++ b/test/data/getFloodsPlus.json @@ -12,6 +12,9 @@ "taCategory": "Flood Warning", "ownerArea": "Devon, Cornwall and the Isles of Scilly", "createdDate": "2016-03-02T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2016-07-06T00:00:00.000Z", "situationChanged": "2019-09-20T09:52:00.000Z", "severityChanged": "2019-09-20T09:52:00.000Z", @@ -32,6 +35,9 @@ "taCategory": "Flood Alert", "ownerArea": "Cumbria and Lancashire", "createdDate": "2016-11-01T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2017-08-09T00:00:00.000Z", "situationChanged": "2019-09-20T09:52:00.000Z", "severityChanged": "2019-09-20T09:52:00.000Z", @@ -52,6 +58,9 @@ "taCategory": "Flood Warning", "ownerArea": "Cumbria and Lancashire", "createdDate": "2019-07-03T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2019-07-03T00:00:00.000Z", "situationChanged": "2019-09-20T09:52:00.000Z", "severityChanged": "2019-09-20T09:52:00.000Z", @@ -72,6 +81,9 @@ "taCategory": "Flood Warning", "ownerArea": "Cumbria and Lancashire", "createdDate": "2019-03-12T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2019-05-30T00:00:00.000Z", "situationChanged": "2019-09-20T09:52:00.000Z", "severityChanged": "2019-09-20T09:52:00.000Z", @@ -92,6 +104,9 @@ "taCategory": "Flood Warning", "ownerArea": "Cumbria and Lancashire", "createdDate": "2019-03-12T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2019-05-30T00:00:00.000Z", "situationChanged": "2019-09-20T09:52:00.000Z", "severityChanged": "2019-09-20T09:52:00.000Z", @@ -112,6 +127,9 @@ "taCategory": "Flood Alert", "ownerArea": "Devon, Cornwall and the Isles of Scilly", "createdDate": "2015-07-31T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2015-10-21T00:00:00.000Z", "situationChanged": "2019-09-20T09:52:00.000Z", "severityChanged": "2019-09-20T09:52:00.000Z", @@ -132,6 +150,9 @@ "taCategory": "Flood Warning", "ownerArea": "Devon, Cornwall and the Isles of Scilly", "createdDate": "2017-08-14T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2017-10-18T00:00:00.000Z", "situationChanged": "2019-09-20T09:52:00.000Z", "severityChanged": "2019-09-20T09:52:00.000Z", @@ -152,6 +173,9 @@ "taCategory": "Flood Alert", "ownerArea": "East Anglia", "createdDate": "2018-06-26T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2018-08-22T00:00:00.000Z", "situationChanged": "2019-09-20T09:52:00.000Z", "severityChanged": "2019-09-20T09:52:00.000Z", @@ -172,6 +196,9 @@ "taCategory": "Flood Warning", "ownerArea": "East Anglia", "createdDate": "2019-07-17T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2019-07-19T00:00:00.000Z", "situationChanged": "2019-09-20T09:52:00.000Z", "severityChanged": "2019-09-20T09:52:00.000Z", @@ -192,6 +219,9 @@ "taCategory": "Flood Warning", "ownerArea": "East Anglia", "createdDate": "2019-07-17T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2019-07-19T00:00:00.000Z", "situationChanged": "2019-09-20T09:52:00.000Z", "severityChanged": "2019-09-20T09:52:00.000Z", @@ -212,6 +242,9 @@ "taCategory": "Flood Warning", "ownerArea": "East Anglia", "createdDate": "2016-08-02T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2016-10-26T00:00:00.000Z", "situationChanged": "2019-09-20T09:52:00.000Z", "severityChanged": "2019-09-20T09:52:00.000Z", @@ -232,6 +265,9 @@ "taCategory": "Flood Alert", "ownerArea": "East Midlands", "createdDate": "2018-01-09T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2018-02-22T00:00:00.000Z", "situationChanged": "2019-09-20T09:52:00.000Z", "severityChanged": "2019-09-20T09:52:00.000Z", @@ -252,6 +288,9 @@ "taCategory": "Flood Warning", "ownerArea": "East Midlands", "createdDate": "2017-08-22T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2017-10-18T00:00:00.000Z", "situationChanged": "2019-09-20T09:52:00.000Z", "severityChanged": "2019-09-20T09:52:00.000Z", @@ -272,6 +311,9 @@ "taCategory": "Flood Warning", "ownerArea": "East Midlands", "createdDate": "2018-03-07T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2018-08-22T00:00:00.000Z", "situationChanged": "2019-09-20T09:52:00.000Z", "severityChanged": "2019-09-20T09:52:00.000Z", @@ -292,6 +334,9 @@ "taCategory": "Flood Warning", "ownerArea": "East Midlands", "createdDate": "2019-03-25T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2019-05-29T00:00:00.000Z", "situationChanged": "2019-09-20T09:52:00.000Z", "severityChanged": "2019-09-20T09:52:00.000Z", @@ -312,6 +357,9 @@ "taCategory": "Flood Alert", "ownerArea": "Greater Manchester, Merseyside and Cheshire", "createdDate": "2017-10-24T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2017-10-25T00:00:00.000Z", "situationChanged": "2019-09-20T09:52:00.000Z", "severityChanged": "2019-09-20T09:52:00.000Z", @@ -332,6 +380,9 @@ "taCategory": "Flood Warning", "ownerArea": "Greater Manchester, Merseyside and Cheshire", "createdDate": "2019-07-01T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2019-07-01T00:00:00.000Z", "situationChanged": "2019-09-20T09:52:00.000Z", "severityChanged": "2019-09-20T09:52:00.000Z", @@ -352,6 +403,9 @@ "taCategory": "Flood Warning", "ownerArea": "Greater Manchester, Merseyside and Cheshire", "createdDate": "2014-03-24T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2014-03-24T00:00:00.000Z", "situationChanged": "2019-09-20T09:52:00.000Z", "severityChanged": "2019-09-20T09:52:00.000Z", @@ -372,6 +426,9 @@ "taCategory": "Flood Warning", "ownerArea": "Greater Manchester, Merseyside and Cheshire", "createdDate": "2014-03-24T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2014-03-24T00:00:00.000Z", "situationChanged": "2019-09-20T09:52:00.000Z", "severityChanged": "2019-09-20T09:52:00.000Z", @@ -392,6 +449,9 @@ "taCategory": "Flood Alert", "ownerArea": "Hertfordshire and North London", "createdDate": "2018-09-17T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2018-11-28T00:00:00.000Z", "situationChanged": "2019-09-20T09:52:00.000Z", "severityChanged": "2019-09-20T09:52:00.000Z", @@ -412,6 +472,9 @@ "taCategory": "Flood Warning", "ownerArea": "Hertfordshire and North London", "createdDate": "2019-07-03T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2019-07-03T00:00:00.000Z", "situationChanged": "2019-09-20T09:52:00.000Z", "severityChanged": "2019-09-20T09:52:00.000Z", @@ -432,6 +495,9 @@ "taCategory": "Flood Warning", "ownerArea": "Hertfordshire and North London", "createdDate": "2019-07-03T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2019-07-03T00:00:00.000Z", "situationChanged": "2019-09-20T09:52:00.000Z", "severityChanged": "2019-09-20T09:52:00.000Z", @@ -452,6 +518,9 @@ "taCategory": "Flood Warning", "ownerArea": "Hertfordshire and North London", "createdDate": "2018-03-26T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2018-05-23T00:00:00.000Z", "situationChanged": "2019-09-20T09:52:00.000Z", "severityChanged": "2019-09-20T09:52:00.000Z", @@ -472,6 +541,9 @@ "taCategory": "Flood Alert", "ownerArea": "Kent, South London and East Sussex", "createdDate": "2018-09-28T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2018-11-28T00:00:00.000Z", "situationChanged": "2019-09-20T09:52:00.000Z", "severityChanged": "2019-09-20T09:52:00.000Z", @@ -492,6 +564,9 @@ "taCategory": "Flood Warning", "ownerArea": "Kent, South London and East Sussex", "createdDate": "2016-04-04T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2016-07-06T00:00:00.000Z", "situationChanged": "2019-09-20T09:52:00.000Z", "severityChanged": "2019-09-20T09:52:00.000Z", @@ -512,6 +587,9 @@ "taCategory": "Flood Warning", "ownerArea": "Kent, South London and East Sussex", "createdDate": "2018-06-12T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2018-08-22T00:00:00.000Z", "situationChanged": "2019-09-20T09:52:00.000Z", "severityChanged": "2019-09-20T09:52:00.000Z", @@ -532,6 +610,9 @@ "taCategory": "Flood Warning", "ownerArea": "Kent, South London and East Sussex", "createdDate": "2016-04-05T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2016-07-06T00:00:00.000Z", "situationChanged": "2019-09-20T09:52:00.000Z", "severityChanged": "2019-09-20T09:52:00.000Z", @@ -552,6 +633,9 @@ "taCategory": "Flood Alert", "ownerArea": "Lincolnshire and Northamptonshire", "createdDate": "2017-08-17T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2017-10-18T00:00:00.000Z", "situationChanged": "2019-09-20T09:52:00.000Z", "severityChanged": "2019-09-20T09:52:00.000Z", @@ -572,6 +656,9 @@ "taCategory": "Flood Warning", "ownerArea": "Lincolnshire and Northamptonshire", "createdDate": "2010-06-07T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2010-11-30T00:00:00.000Z", "situationChanged": "2019-09-20T09:52:00.000Z", "severityChanged": "2019-09-20T09:52:00.000Z", @@ -592,6 +679,9 @@ "taCategory": "Flood Warning", "ownerArea": "Lincolnshire and Northamptonshire", "createdDate": "2017-11-27T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2018-02-21T00:00:00.000Z", "situationChanged": "2019-09-20T09:52:00.000Z", "severityChanged": "2019-09-20T09:52:00.000Z", @@ -612,6 +702,9 @@ "taCategory": "Flood Warning", "ownerArea": "Lincolnshire and Northamptonshire", "createdDate": "2012-03-19T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2012-06-28T00:00:00.000Z", "situationChanged": "2019-09-20T09:52:00.000Z", "severityChanged": "2019-09-20T09:52:00.000Z", @@ -632,6 +725,9 @@ "taCategory": "Flood Alert", "ownerArea": "North East", "createdDate": "2018-10-04T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2019-02-27T00:00:00.000Z", "situationChanged": "2019-09-20T09:52:00.000Z", "severityChanged": "2019-09-20T09:52:00.000Z", @@ -652,6 +748,9 @@ "taCategory": "Flood Warning", "ownerArea": "North East", "createdDate": "2018-09-21T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2018-11-28T00:00:00.000Z", "situationChanged": "2019-09-20T09:52:00.000Z", "severityChanged": "2019-09-20T09:52:00.000Z", @@ -672,6 +771,9 @@ "taCategory": "Flood Warning", "ownerArea": "North East", "createdDate": "2019-04-04T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2019-05-29T00:00:00.000Z", "situationChanged": "2019-09-20T09:52:00.000Z", "severityChanged": "2019-09-20T09:52:00.000Z", @@ -692,6 +794,9 @@ "taCategory": "Flood Warning", "ownerArea": "North East", "createdDate": "2017-11-22T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2017-11-22T00:00:00.000Z", "situationChanged": "2019-09-20T09:52:00.000Z", "severityChanged": "2019-09-20T09:52:00.000Z", @@ -712,6 +817,9 @@ "taCategory": "Flood Alert", "ownerArea": "Solent and South Downs", "createdDate": "2017-11-06T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2018-02-21T00:00:00.000Z", "situationChanged": "2019-09-20T09:52:00.000Z", "severityChanged": "2019-09-20T09:52:00.000Z", @@ -732,6 +840,9 @@ "taCategory": "Flood Warning", "ownerArea": "Solent and South Downs", "createdDate": "2014-08-05T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2014-10-29T00:00:00.000Z", "situationChanged": "2019-09-20T09:52:00.000Z", "severityChanged": "2019-09-20T09:52:00.000Z", @@ -752,6 +863,9 @@ "taCategory": "Flood Warning", "ownerArea": "Solent and South Downs", "createdDate": "2019-05-31T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2019-05-31T00:00:00.000Z", "situationChanged": "2019-09-20T09:52:00.000Z", "severityChanged": "2019-09-20T09:52:00.000Z", @@ -772,6 +886,9 @@ "taCategory": "Flood Warning", "ownerArea": "Solent and South Downs", "createdDate": "2019-06-04T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2019-07-03T00:00:00.000Z", "situationChanged": "2019-09-20T09:52:00.000Z", "severityChanged": "2019-09-20T09:52:00.000Z", @@ -792,6 +909,9 @@ "taCategory": "Flood Alert", "ownerArea": "Thames", "createdDate": "2017-12-19T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2018-02-21T00:00:00.000Z", "situationChanged": "2019-09-20T09:52:00.000Z", "severityChanged": "2019-09-20T09:52:00.000Z", @@ -812,6 +932,9 @@ "taCategory": "Flood Warning", "ownerArea": "Thames", "createdDate": "2017-05-24T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2017-08-02T00:00:00.000Z", "situationChanged": "2019-09-20T09:52:00.000Z", "severityChanged": "2019-09-20T09:52:00.000Z", @@ -832,6 +955,9 @@ "taCategory": "Flood Warning", "ownerArea": "Thames", "createdDate": "2015-10-27T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2016-02-24T00:00:00.000Z", "situationChanged": "2019-09-20T09:52:00.000Z", "severityChanged": "2019-09-20T09:52:00.000Z", @@ -852,6 +978,9 @@ "taCategory": "Flood Warning", "ownerArea": "Thames", "createdDate": "2017-11-06T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2017-11-06T00:00:00.000Z", "situationChanged": "2019-09-20T09:52:00.000Z", "severityChanged": "2019-09-20T09:52:00.000Z", @@ -872,6 +1001,9 @@ "taCategory": "Flood Alert", "ownerArea": "Wessex", "createdDate": "2018-06-06T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2018-08-22T00:00:00.000Z", "situationChanged": "2019-09-20T09:52:00.000Z", "severityChanged": "2019-09-20T09:52:00.000Z", @@ -892,6 +1024,9 @@ "taCategory": "Flood Warning", "ownerArea": "Wessex", "createdDate": "2018-01-11T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2018-02-21T00:00:00.000Z", "situationChanged": "2019-09-20T09:52:00.000Z", "severityChanged": "2019-09-20T09:52:00.000Z", @@ -912,6 +1047,9 @@ "taCategory": "Flood Warning", "ownerArea": "Wessex", "createdDate": "2015-11-17T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2016-02-24T00:00:00.000Z", "situationChanged": "2019-09-20T09:52:00.000Z", "severityChanged": "2019-09-20T09:52:00.000Z", @@ -932,6 +1070,9 @@ "taCategory": "Flood Warning", "ownerArea": "Wessex", "createdDate": "2018-06-06T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2018-08-22T00:00:00.000Z", "situationChanged": "2019-09-20T09:52:00.000Z", "severityChanged": "2019-09-20T09:52:00.000Z", @@ -952,6 +1093,9 @@ "taCategory": "Flood Alert", "ownerArea": "West Midlands", "createdDate": "2009-10-16T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2010-11-30T00:00:00.000Z", "situationChanged": "2019-09-20T09:52:00.000Z", "severityChanged": "2019-09-20T09:52:00.000Z", @@ -972,6 +1116,9 @@ "taCategory": "Flood Warning", "ownerArea": "West Midlands", "createdDate": "2017-06-09T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2017-06-09T00:00:00.000Z", "situationChanged": "2019-09-20T09:52:00.000Z", "severityChanged": "2019-09-20T09:52:00.000Z", @@ -992,6 +1139,9 @@ "taCategory": "Flood Warning", "ownerArea": "West Midlands", "createdDate": "2011-03-23T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2011-06-22T00:00:00.000Z", "situationChanged": "2019-09-20T09:52:00.000Z", "severityChanged": "2019-09-20T09:52:00.000Z", @@ -1012,6 +1162,9 @@ "taCategory": "Flood Warning", "ownerArea": "West Midlands", "createdDate": "2017-04-11T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2017-04-11T00:00:00.000Z", "situationChanged": "2019-09-20T09:52:00.000Z", "severityChanged": "2019-09-20T09:52:00.000Z", @@ -1032,6 +1185,9 @@ "taCategory": "Flood Alert", "ownerArea": "Yorkshire", "createdDate": "2017-11-23T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2018-02-21T00:00:00.000Z", "situationChanged": "2019-09-20T09:52:00.000Z", "severityChanged": "2019-09-20T09:52:00.000Z", @@ -1052,6 +1208,9 @@ "taCategory": "Flood Alert", "ownerArea": "Yorkshire", "createdDate": "2017-12-14T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2018-02-21T00:00:00.000Z", "situationChanged": "2019-09-20T09:52:00.000Z", "severityChanged": "2019-09-20T09:52:00.000Z", @@ -1072,6 +1231,9 @@ "taCategory": "Flood Warning", "ownerArea": "Yorkshire", "createdDate": "2014-11-20T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2015-02-25T00:00:00.000Z", "situationChanged": "2019-09-20T09:52:00.000Z", "severityChanged": "2019-09-20T09:52:00.000Z", @@ -1092,6 +1254,9 @@ "taCategory": "Flood Warning", "ownerArea": "Yorkshire", "createdDate": "2017-12-19T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2018-02-21T00:00:00.000Z", "situationChanged": "2019-09-20T09:52:00.000Z", "severityChanged": "2019-09-20T09:52:00.000Z", @@ -1112,6 +1277,9 @@ "taCategory": "Flood Alert", "ownerArea": "Yorkshire", "createdDate": "2017-12-19T00:00:00.000Z", + "createdByID": "test-id", + "createdByName": "test-name", + "createdByEmail": "test-email", "lastModifiedDate": "2018-02-21T00:00:00.000Z", "situationChanged": "2019-09-20T09:52:00.000Z", "severityChanged": "2019-09-20T09:52:00.000Z", @@ -1132,6 +1300,9 @@ "taCategory": "Flood Alert", "ownerArea": "Yorkshire", "createdDate": "2017-12-19T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2018-02-21T00:00:00.000Z", "situationChanged": "2019-09-20T09:52:00.000Z", "severityChanged": "2019-09-20T09:52:00.000Z", @@ -1141,4 +1312,4 @@ } } ] -} \ No newline at end of file +} diff --git a/test/data/getHistoricFloods.json b/test/data/getHistoricFloods.json index 88f5228..bf90634 100644 --- a/test/data/getHistoricFloods.json +++ b/test/data/getHistoricFloods.json @@ -12,6 +12,9 @@ "taCategory": "Flood Warning", "ownerArea": "Cumbria and Lancashire", "createdDate": "2014-08-18T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2014-08-18T00:00:00.000Z", "situationChanged": "2019-07-18T13:30:00.000Z", "severityChanged": "2019-07-18T13:30:00.000Z", @@ -32,6 +35,9 @@ "taCategory": "Flood Warning", "ownerArea": "Cumbria and Lancashire", "createdDate": "2014-08-18T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2014-08-18T00:00:00.000Z", "situationChanged": "2019-07-18T13:30:00.000Z", "severityChanged": "2019-07-18T13:30:00.000Z", @@ -52,6 +58,9 @@ "taCategory": "Flood Warning", "ownerArea": "Cumbria and Lancashire", "createdDate": "2014-08-18T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2014-08-18T00:00:00.000Z", "situationChanged": "2019-07-18T13:30:00.000Z", "severityChanged": "2019-07-18T13:30:00.000Z", @@ -72,6 +81,9 @@ "taCategory": "Flood Warning", "ownerArea": "Cumbria and Lancashire", "createdDate": "2014-08-18T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2014-08-18T00:00:00.000Z", "situationChanged": "2019-07-18T13:30:00.000Z", "severityChanged": "2019-07-18T13:30:00.000Z", @@ -92,6 +104,9 @@ "taCategory": "Flood Warning", "ownerArea": "Cumbria and Lancashire", "createdDate": "2014-08-18T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2014-08-18T00:00:00.000Z", "situationChanged": "2019-07-18T13:30:00.000Z", "severityChanged": "2019-07-18T13:30:00.000Z", @@ -112,6 +127,9 @@ "taCategory": "Flood Warning", "ownerArea": "Cumbria and Lancashire", "createdDate": "2014-08-18T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2014-08-18T00:00:00.000Z", "situationChanged": "2019-07-18T13:30:00.000Z", "severityChanged": "2019-07-18T13:30:00.000Z", @@ -132,6 +150,9 @@ "taCategory": "Flood Warning", "ownerArea": "Cumbria and Lancashire", "createdDate": "2014-08-18T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2014-08-18T00:00:00.000Z", "situationChanged": "2019-07-18T13:30:00.000Z", "severityChanged": "2019-07-18T13:30:00.000Z", @@ -152,6 +173,9 @@ "taCategory": "Flood Warning", "ownerArea": "Cumbria and Lancashire", "createdDate": "2014-08-18T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2014-08-18T00:00:00.000Z", "situationChanged": "2019-07-18T13:30:00.000Z", "severityChanged": "2019-07-18T13:30:00.000Z", @@ -172,6 +196,9 @@ "taCategory": "Flood Warning", "ownerArea": "Cumbria and Lancashire", "createdDate": "2014-08-18T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2014-08-18T00:00:00.000Z", "situationChanged": "2019-07-18T13:30:00.000Z", "severityChanged": "2019-07-18T13:30:00.000Z", @@ -192,6 +219,9 @@ "taCategory": "Flood Warning", "ownerArea": "Cumbria and Lancashire", "createdDate": "2014-08-18T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2014-08-18T00:00:00.000Z", "situationChanged": "2019-07-18T13:30:00.000Z", "severityChanged": "2019-07-18T13:30:00.000Z", @@ -212,6 +242,9 @@ "taCategory": "Flood Warning", "ownerArea": "Cumbria and Lancashire", "createdDate": "2014-08-18T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2014-08-18T00:00:00.000Z", "situationChanged": "2019-07-17T13:30:00.000Z", "severityChanged": "2019-07-17T13:30:00.000Z", @@ -232,6 +265,9 @@ "taCategory": "Flood Warning", "ownerArea": "Cumbria and Lancashire", "createdDate": "2014-08-18T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2014-08-18T00:00:00.000Z", "situationChanged": "2019-07-17T13:30:00.000Z", "severityChanged": "2019-07-17T13:30:00.000Z", @@ -252,6 +288,9 @@ "taCategory": "Flood Warning", "ownerArea": "Cumbria and Lancashire", "createdDate": "2014-08-18T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2014-08-18T00:00:00.000Z", "situationChanged": "2019-07-17T13:30:00.000Z", "severityChanged": "2019-07-17T13:30:00.000Z", @@ -272,6 +311,9 @@ "taCategory": "Flood Warning", "ownerArea": "Cumbria and Lancashire", "createdDate": "2014-08-18T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2014-08-18T00:00:00.000Z", "situationChanged": "2019-07-17T13:30:00.000Z", "severityChanged": "2019-07-17T13:30:00.000Z", @@ -292,6 +334,9 @@ "taCategory": "Flood Warning", "ownerArea": "Cumbria and Lancashire", "createdDate": "2014-08-18T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2014-08-18T00:00:00.000Z", "situationChanged": "2019-07-17T13:30:00.000Z", "severityChanged": "2019-07-17T13:30:00.000Z", @@ -312,6 +357,9 @@ "taCategory": "Flood Warning", "ownerArea": "Cumbria and Lancashire", "createdDate": "2014-08-18T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2014-08-18T00:00:00.000Z", "situationChanged": "2019-07-17T13:30:00.000Z", "severityChanged": "2019-07-17T13:30:00.000Z", @@ -332,6 +380,9 @@ "taCategory": "Flood Warning", "ownerArea": "Cumbria and Lancashire", "createdDate": "2014-08-18T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2014-08-18T00:00:00.000Z", "situationChanged": "2019-07-17T13:30:00.000Z", "severityChanged": "2019-07-17T13:30:00.000Z", @@ -352,6 +403,9 @@ "taCategory": "Flood Warning", "ownerArea": "Cumbria and Lancashire", "createdDate": "2014-08-18T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2014-08-18T00:00:00.000Z", "situationChanged": "2019-07-17T13:30:00.000Z", "severityChanged": "2019-07-17T13:30:00.000Z", @@ -372,6 +426,9 @@ "taCategory": "Flood Warning", "ownerArea": "Cumbria and Lancashire", "createdDate": "2014-08-18T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2014-08-18T00:00:00.000Z", "situationChanged": "2019-07-17T13:30:00.000Z", "severityChanged": "2019-07-17T13:30:00.000Z", @@ -392,6 +449,9 @@ "taCategory": "Flood Warning", "ownerArea": "Cumbria and Lancashire", "createdDate": "2014-08-18T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2014-08-18T00:00:00.000Z", "situationChanged": "2019-07-17T13:30:00.000Z", "severityChanged": "2019-07-17T13:30:00.000Z", @@ -412,6 +472,9 @@ "taCategory": "Flood Warning", "ownerArea": "Cumbria and Lancashire", "createdDate": "2014-08-18T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2014-08-18T00:00:00.000Z", "situationChanged": "2019-07-17T13:30:00.000Z", "severityChanged": "2019-07-17T13:30:00.000Z", @@ -432,6 +495,9 @@ "taCategory": "Flood Warning", "ownerArea": "Cumbria and Lancashire", "createdDate": "2014-08-18T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2014-08-18T00:00:00.000Z", "situationChanged": "2019-07-17T13:30:00.000Z", "severityChanged": "2019-07-17T13:30:00.000Z", @@ -452,6 +518,9 @@ "taCategory": "Flood Warning", "ownerArea": "Cumbria and Lancashire", "createdDate": "2014-08-18T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2014-08-18T00:00:00.000Z", "situationChanged": "2019-07-17T13:30:00.000Z", "severityChanged": "2019-07-17T13:30:00.000Z", @@ -472,6 +541,9 @@ "taCategory": "Flood Warning", "ownerArea": "Cumbria and Lancashire", "createdDate": "2014-08-18T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2014-08-18T00:00:00.000Z", "situationChanged": "2019-07-17T13:30:00.000Z", "severityChanged": "2019-07-17T13:30:00.000Z", @@ -492,6 +564,9 @@ "taCategory": "Flood Warning", "ownerArea": "Cumbria and Lancashire", "createdDate": "2014-08-18T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2014-08-18T00:00:00.000Z", "situationChanged": "2019-07-17T13:30:00.000Z", "severityChanged": "2019-07-17T13:30:00.000Z", @@ -512,6 +587,9 @@ "taCategory": "Flood Warning", "ownerArea": "Cumbria and Lancashire", "createdDate": "2014-08-18T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2014-08-18T00:00:00.000Z", "situationChanged": "2019-07-17T13:30:00.000Z", "severityChanged": "2019-07-17T13:30:00.000Z", @@ -532,6 +610,9 @@ "taCategory": "Flood Warning", "ownerArea": "Cumbria and Lancashire", "createdDate": "2014-08-18T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2014-08-18T00:00:00.000Z", "situationChanged": "2019-07-17T13:30:00.000Z", "severityChanged": "2019-07-17T13:30:00.000Z", @@ -552,6 +633,9 @@ "taCategory": "Flood Warning", "ownerArea": "Cumbria and Lancashire", "createdDate": "2014-08-18T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2014-08-18T00:00:00.000Z", "situationChanged": "2019-07-17T13:30:00.000Z", "severityChanged": "2019-07-17T13:30:00.000Z", @@ -572,6 +656,9 @@ "taCategory": "Flood Warning", "ownerArea": "Cumbria and Lancashire", "createdDate": "2014-08-18T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2014-08-18T00:00:00.000Z", "situationChanged": "2019-07-17T13:30:00.000Z", "severityChanged": "2019-07-17T13:30:00.000Z", @@ -592,6 +679,9 @@ "taCategory": "Flood Warning", "ownerArea": "Cumbria and Lancashire", "createdDate": "2014-08-18T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2014-08-18T00:00:00.000Z", "situationChanged": "2019-07-17T13:30:00.000Z", "severityChanged": "2019-07-17T13:30:00.000Z", @@ -612,6 +702,9 @@ "taCategory": "Flood Warning", "ownerArea": "Cumbria and Lancashire", "createdDate": "2014-08-18T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2014-08-18T00:00:00.000Z", "situationChanged": "2019-07-17T13:30:00.000Z", "severityChanged": "2019-07-17T13:30:00.000Z", @@ -632,6 +725,9 @@ "taCategory": "Flood Warning", "ownerArea": "Cumbria and Lancashire", "createdDate": "2014-08-18T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2014-08-18T00:00:00.000Z", "situationChanged": "2019-07-17T13:30:00.000Z", "severityChanged": "2019-07-17T13:30:00.000Z", @@ -652,6 +748,9 @@ "taCategory": "Flood Warning", "ownerArea": "Cumbria and Lancashire", "createdDate": "2014-08-18T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2014-08-18T00:00:00.000Z", "situationChanged": "2019-07-17T13:30:00.000Z", "severityChanged": "2019-07-17T13:30:00.000Z", @@ -672,6 +771,9 @@ "taCategory": "Flood Warning", "ownerArea": "Cumbria and Lancashire", "createdDate": "2014-08-18T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2014-08-18T00:00:00.000Z", "situationChanged": "2019-07-17T13:30:00.000Z", "severityChanged": "2019-07-17T13:30:00.000Z", @@ -692,6 +794,9 @@ "taCategory": "Flood Warning", "ownerArea": "Cumbria and Lancashire", "createdDate": "2014-08-18T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2014-08-18T00:00:00.000Z", "situationChanged": "2019-07-17T13:30:00.000Z", "severityChanged": "2019-07-17T13:30:00.000Z", @@ -712,6 +817,9 @@ "taCategory": "Flood Warning", "ownerArea": "Cumbria and Lancashire", "createdDate": "2014-08-18T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2014-08-18T00:00:00.000Z", "situationChanged": "2019-07-17T13:30:00.000Z", "severityChanged": "2019-07-17T13:30:00.000Z", @@ -732,6 +840,9 @@ "taCategory": "Flood Warning", "ownerArea": "Cumbria and Lancashire", "createdDate": "2014-08-18T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2014-08-18T00:00:00.000Z", "situationChanged": "2019-07-17T13:30:00.000Z", "severityChanged": "2019-07-17T13:30:00.000Z", @@ -752,6 +863,9 @@ "taCategory": "Flood Warning", "ownerArea": "Cumbria and Lancashire", "createdDate": "2014-08-18T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2014-08-18T00:00:00.000Z", "situationChanged": "2019-07-17T13:30:00.000Z", "severityChanged": "2019-07-17T13:30:00.000Z", @@ -772,6 +886,9 @@ "taCategory": "Flood Warning", "ownerArea": "Cumbria and Lancashire", "createdDate": "2014-08-18T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2014-08-18T00:00:00.000Z", "situationChanged": "2019-07-17T13:30:00.000Z", "severityChanged": "2019-07-17T13:30:00.000Z", @@ -792,6 +909,9 @@ "taCategory": "Flood Warning", "ownerArea": "Cumbria and Lancashire", "createdDate": "2014-08-18T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2014-08-18T00:00:00.000Z", "situationChanged": "2019-07-16T13:30:00.000Z", "severityChanged": "2019-07-16T13:30:00.000Z", @@ -812,6 +932,9 @@ "taCategory": "Flood Warning", "ownerArea": "Cumbria and Lancashire", "createdDate": "2014-08-18T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2014-08-18T00:00:00.000Z", "situationChanged": "2019-07-16T13:30:00.000Z", "severityChanged": "2019-07-16T13:30:00.000Z", @@ -832,6 +955,9 @@ "taCategory": "Flood Warning", "ownerArea": "Cumbria and Lancashire", "createdDate": "2014-08-18T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2014-08-18T00:00:00.000Z", "situationChanged": "2019-07-16T13:30:00.000Z", "severityChanged": "2019-07-16T13:30:00.000Z", @@ -852,6 +978,9 @@ "taCategory": "Flood Warning", "ownerArea": "Cumbria and Lancashire", "createdDate": "2014-08-18T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2014-08-18T00:00:00.000Z", "situationChanged": "2019-07-16T13:30:00.000Z", "severityChanged": "2019-07-16T13:30:00.000Z", @@ -872,6 +1001,9 @@ "taCategory": "Flood Warning", "ownerArea": "Cumbria and Lancashire", "createdDate": "2014-08-18T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2014-08-18T00:00:00.000Z", "situationChanged": "2019-07-16T13:30:00.000Z", "severityChanged": "2019-07-16T13:30:00.000Z", @@ -892,6 +1024,9 @@ "taCategory": "Flood Warning", "ownerArea": "Cumbria and Lancashire", "createdDate": "2014-08-18T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2014-08-18T00:00:00.000Z", "situationChanged": "2019-07-16T13:30:00.000Z", "severityChanged": "2019-07-16T13:30:00.000Z", @@ -912,6 +1047,9 @@ "taCategory": "Flood Warning", "ownerArea": "Cumbria and Lancashire", "createdDate": "2014-08-18T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2014-08-18T00:00:00.000Z", "situationChanged": "2019-07-16T13:30:00.000Z", "severityChanged": "2019-07-16T13:30:00.000Z", @@ -932,6 +1070,9 @@ "taCategory": "Flood Warning", "ownerArea": "Cumbria and Lancashire", "createdDate": "2014-08-18T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2014-08-18T00:00:00.000Z", "situationChanged": "2019-07-16T13:30:00.000Z", "severityChanged": "2019-07-16T13:30:00.000Z", @@ -952,6 +1093,9 @@ "taCategory": "Flood Warning", "ownerArea": "Cumbria and Lancashire", "createdDate": "2014-08-18T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2014-08-18T00:00:00.000Z", "situationChanged": "2019-07-16T13:30:00.000Z", "severityChanged": "2019-07-16T13:30:00.000Z", @@ -972,6 +1116,9 @@ "taCategory": "Flood Warning", "ownerArea": "Cumbria and Lancashire", "createdDate": "2014-08-18T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2014-08-18T00:00:00.000Z", "situationChanged": "2019-07-16T13:30:00.000Z", "severityChanged": "2019-07-16T13:30:00.000Z", @@ -992,6 +1139,9 @@ "taCategory": "Flood Warning", "ownerArea": "Cumbria and Lancashire", "createdDate": "2014-08-18T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2014-08-18T00:00:00.000Z", "situationChanged": "2019-07-16T13:30:00.000Z", "severityChanged": "2019-07-16T13:30:00.000Z", @@ -1012,6 +1162,9 @@ "taCategory": "Flood Warning", "ownerArea": "Cumbria and Lancashire", "createdDate": "2014-08-18T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2014-08-18T00:00:00.000Z", "situationChanged": "2019-07-16T13:30:00.000Z", "severityChanged": "2019-07-16T13:30:00.000Z", @@ -1032,6 +1185,9 @@ "taCategory": "Flood Warning", "ownerArea": "Cumbria and Lancashire", "createdDate": "2014-08-18T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2014-08-18T00:00:00.000Z", "situationChanged": "2019-07-16T13:30:00.000Z", "severityChanged": "2019-07-16T13:30:00.000Z", @@ -1052,6 +1208,9 @@ "taCategory": "Flood Warning", "ownerArea": "Cumbria and Lancashire", "createdDate": "2014-08-18T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2014-08-18T00:00:00.000Z", "situationChanged": "2019-07-16T13:30:00.000Z", "severityChanged": "2019-07-14T13:30:00.000Z", @@ -1072,6 +1231,9 @@ "taCategory": "Flood Warning", "ownerArea": "Cumbria and Lancashire", "createdDate": "2014-08-18T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2014-08-18T00:00:00.000Z", "situationChanged": "2019-07-16T13:30:00.000Z", "severityChanged": "2019-07-16T13:30:00.000Z", @@ -1092,6 +1254,9 @@ "taCategory": "Flood Warning", "ownerArea": "Cumbria and Lancashire", "createdDate": "2014-08-18T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2014-08-18T00:00:00.000Z", "situationChanged": "2019-07-16T13:30:00.000Z", "severityChanged": "2019-07-16T13:30:00.000Z", @@ -1112,6 +1277,9 @@ "taCategory": "Flood Warning", "ownerArea": "Cumbria and Lancashire", "createdDate": "2014-08-18T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2014-08-18T00:00:00.000Z", "situationChanged": "2019-07-16T13:30:00.000Z", "severityChanged": "2019-07-16T13:30:00.000Z", @@ -1132,6 +1300,9 @@ "taCategory": "Flood Warning", "ownerArea": "Cumbria and Lancashire", "createdDate": "2014-08-18T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2014-08-18T00:00:00.000Z", "situationChanged": "2019-07-16T13:30:00.000Z", "severityChanged": "2019-07-16T13:30:00.000Z", @@ -1152,6 +1323,9 @@ "taCategory": "Flood Warning", "ownerArea": "Cumbria and Lancashire", "createdDate": "2014-08-18T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2014-08-18T00:00:00.000Z", "situationChanged": "2019-07-16T13:30:00.000Z", "severityChanged": "2019-07-16T13:30:00.000Z", @@ -1172,6 +1346,9 @@ "taCategory": "Flood Warning", "ownerArea": "Cumbria and Lancashire", "createdDate": "2014-08-18T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2014-08-18T00:00:00.000Z", "situationChanged": "2019-07-16T13:30:00.000Z", "severityChanged": "2019-07-16T13:30:00.000Z", @@ -1192,6 +1369,9 @@ "taCategory": "Flood Warning", "ownerArea": "Cumbria and Lancashire", "createdDate": "2014-08-18T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2014-08-18T00:00:00.000Z", "situationChanged": "2019-07-16T13:30:00.000Z", "severityChanged": "2019-07-16T13:30:00.000Z", @@ -1212,6 +1392,9 @@ "taCategory": "Flood Warning", "ownerArea": "Cumbria and Lancashire", "createdDate": "2014-08-18T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2014-08-18T00:00:00.000Z", "situationChanged": "2019-07-16T13:30:00.000Z", "severityChanged": "2019-07-16T13:30:00.000Z", @@ -1232,6 +1415,9 @@ "taCategory": "Flood Warning", "ownerArea": "Cumbria and Lancashire", "createdDate": "2014-08-18T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2014-08-18T00:00:00.000Z", "situationChanged": "2019-07-16T13:30:00.000Z", "severityChanged": "2019-07-16T13:30:00.000Z", @@ -1252,6 +1438,9 @@ "taCategory": "Flood Warning", "ownerArea": "Cumbria and Lancashire", "createdDate": "2014-08-18T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2014-08-18T00:00:00.000Z", "situationChanged": "2019-07-15T13:30:00.000Z", "severityChanged": "2019-07-17T13:30:00.000Z", @@ -1272,6 +1461,9 @@ "taCategory": "Flood Warning", "ownerArea": "Cumbria and Lancashire", "createdDate": "2014-08-18T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2014-08-18T00:00:00.000Z", "situationChanged": "2019-07-14T13:30:00.000Z", "severityChanged": "2019-07-14T13:30:00.000Z", @@ -1292,6 +1484,9 @@ "taCategory": "Flood Warning", "ownerArea": "Cumbria and Lancashire", "createdDate": "2014-08-18T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2014-08-18T00:00:00.000Z", "situationChanged": "2019-04-24T13:30:00.000Z", "severityChanged": "2019-04-24T13:30:00.000Z", @@ -1312,6 +1507,9 @@ "taCategory": "Flood Warning", "ownerArea": "Cumbria and Lancashire", "createdDate": "2014-08-18T00:00:00.000Z", + "createdByID": "", + "createdByName": "", + "createdByEmail": "", "lastModifiedDate": "2014-08-18T00:00:00.000Z", "situationChanged": "2019-04-24T13:30:00.000Z", "severityChanged": "2019-04-24T13:30:00.000Z", @@ -1332,6 +1530,9 @@ "taCategory": "Flood Warning", "ownerArea": "Cumbria and Lancashire", "createdDate": "2014-08-18T00:00:00.000Z", + "createdByID": "test-id", + "createdByName": "test-name", + "createdByEmail": "test-email", "lastModifiedDate": "2014-08-18T00:00:00.000Z", "situationChanged": "2019-04-24T13:30:00.000Z", "severityChanged": "2019-04-24T13:30:00.000Z", @@ -1341,4 +1542,4 @@ } } ] -} \ No newline at end of file +} diff --git a/test/http.js b/test/http.js new file mode 100644 index 0000000..9fb6ab3 --- /dev/null +++ b/test/http.js @@ -0,0 +1,435 @@ +const Lab = require('@hapi/lab') +const lab = exports.lab = Lab.script() +const Code = require('@hapi/code') +const proxyquire = require('proxyquire').noCallThru() + +lab.experiment('HTTP (with proxyquire)', () => { + lab.experiment('getJson', () => { + lab.test('should successfully fetch JSON data with 200 status', async () => { + const testUrl = 'https://api.example.com/test' + const expectedPayload = { warnings: [], data: 'test' } + + const wreckStub = { + defaults: () => ({ + get: () => Promise.resolve({ + res: { statusCode: 200 }, + payload: expectedPayload + }), + post: () => Promise.resolve({ res: { statusCode: 200 }, payload: {} }) + }) + } + + const http = proxyquire('../server/http', { + '@hapi/wreck': wreckStub + }) + + const result = await http.getJson(testUrl) + + Code.expect(result).to.equal(expectedPayload) + }) + + lab.test('should include x-api-key header in request', async () => { + const testUrl = 'https://api.example.com/test' + const config = require('../server/config') + let capturedOptions = null + + const wreckStub = { + defaults: () => ({ + get: (url, options) => { + capturedOptions = options + return Promise.resolve({ + res: { statusCode: 200 }, + payload: {} + }) + }, + post: () => Promise.resolve({ res: { statusCode: 200 }, payload: {} }) + }) + } + + const http = proxyquire('../server/http', { + '@hapi/wreck': wreckStub + }) + + await http.getJson(testUrl) + + Code.expect(capturedOptions).to.exist() + Code.expect(capturedOptions.headers).to.exist() + Code.expect(capturedOptions.headers['x-api-key']).to.equal(config.apiKey) + Code.expect(capturedOptions.json).to.be.true() + }) + + lab.test('should throw error when status code is not 200', async () => { + const testUrl = 'https://api.example.com/test' + + const wreckStub = { + defaults: () => ({ + get: () => Promise.resolve({ + res: { statusCode: 404 }, + payload: { error: 'Not Found' } + }), + post: () => Promise.resolve({ res: { statusCode: 200 }, payload: {} }) + }) + } + + const http = proxyquire('../server/http', { + '@hapi/wreck': wreckStub + }) + + await Code.expect(http.getJson(testUrl)) + .to.reject(Error, 'Requested resource returned a non 200 status code') + }) + + lab.test('should throw error when status code is 500', async () => { + const testUrl = 'https://api.example.com/test' + + const wreckStub = { + defaults: () => ({ + get: () => Promise.resolve({ + res: { statusCode: 500 }, + payload: { error: 'Internal Server Error' } + }), + post: () => Promise.resolve({ res: { statusCode: 200 }, payload: {} }) + }) + } + + const http = proxyquire('../server/http', { + '@hapi/wreck': wreckStub + }) + + await Code.expect(http.getJson(testUrl)) + .to.reject(Error, 'Requested resource returned a non 200 status code') + }) + + lab.test('should throw error when status code is 401', async () => { + const testUrl = 'https://api.example.com/test' + + const wreckStub = { + defaults: () => ({ + get: () => Promise.resolve({ + res: { statusCode: 401 }, + payload: { error: 'Unauthorized' } + }), + post: () => Promise.resolve({ res: { statusCode: 200 }, payload: {} }) + }) + } + + const http = proxyquire('../server/http', { + '@hapi/wreck': wreckStub + }) + + await Code.expect(http.getJson(testUrl)) + .to.reject(Error, 'Requested resource returned a non 200 status code') + }) + + lab.test('should handle network errors', async () => { + const testUrl = 'https://api.example.com/test' + const networkError = new Error('Network timeout') + + const wreckStub = { + defaults: () => ({ + get: () => Promise.reject(networkError), + post: () => Promise.resolve({ res: { statusCode: 200 }, payload: {} }) + }) + } + + const http = proxyquire('../server/http', { + '@hapi/wreck': wreckStub + }) + + await Code.expect(http.getJson(testUrl)) + .to.reject(Error, 'Network timeout') + }) + + lab.test('should handle timeout errors', async () => { + const testUrl = 'https://api.example.com/test' + const timeoutError = new Error('Request timeout') + timeoutError.code = 'ETIMEDOUT' + + const wreckStub = { + defaults: () => ({ + get: () => Promise.reject(timeoutError), + post: () => Promise.resolve({ res: { statusCode: 200 }, payload: {} }) + }) + } + + const http = proxyquire('../server/http', { + '@hapi/wreck': wreckStub + }) + + await Code.expect(http.getJson(testUrl)) + .to.reject(Error, 'Request timeout') + }) + + lab.test('should handle connection refused errors', async () => { + const testUrl = 'https://api.example.com/test' + const connError = new Error('connect ECONNREFUSED') + connError.code = 'ECONNREFUSED' + + const wreckStub = { + defaults: () => ({ + get: () => Promise.reject(connError), + post: () => Promise.resolve({ res: { statusCode: 200 }, payload: {} }) + }) + } + + const http = proxyquire('../server/http', { + '@hapi/wreck': wreckStub + }) + + await Code.expect(http.getJson(testUrl)) + .to.reject(Error, 'connect ECONNREFUSED') + }) + }) + + lab.experiment('postJson', () => { + lab.test('should successfully post JSON data with 200 status', async () => { + const testUrl = 'https://api.example.com/test' + const testPayload = { action: 'update', value: 'test' } + const expectedResponse = { success: true, id: '123' } + + const wreckStub = { + defaults: () => ({ + get: () => Promise.resolve({ res: { statusCode: 200 }, payload: {} }), + post: () => Promise.resolve({ + res: { statusCode: 200 }, + payload: expectedResponse + }) + }) + } + + const http = proxyquire('../server/http', { + '@hapi/wreck': wreckStub + }) + + const result = await http.postJson(testUrl, testPayload) + + Code.expect(result).to.equal(expectedResponse) + }) + + lab.test('should include x-api-key header and payload in request', async () => { + const testUrl = 'https://api.example.com/test' + const testPayload = { action: 'update', value: 'test' } + const config = require('../server/config') + let capturedOptions = null + + const wreckStub = { + defaults: () => ({ + get: () => Promise.resolve({ res: { statusCode: 200 }, payload: {} }), + post: (url, options) => { + capturedOptions = options + return Promise.resolve({ + res: { statusCode: 200 }, + payload: {} + }) + } + }) + } + + const http = proxyquire('../server/http', { + '@hapi/wreck': wreckStub + }) + + await http.postJson(testUrl, testPayload) + + Code.expect(capturedOptions).to.exist() + Code.expect(capturedOptions.headers).to.exist() + Code.expect(capturedOptions.headers['x-api-key']).to.equal(config.apiKey) + Code.expect(capturedOptions.json).to.be.true() + Code.expect(capturedOptions.payload).to.equal(testPayload) + }) + + lab.test('should handle empty payload', async () => { + const testUrl = 'https://api.example.com/test' + const emptyPayload = {} + let capturedOptions = null + + const wreckStub = { + defaults: () => ({ + get: () => Promise.resolve({ res: { statusCode: 200 }, payload: {} }), + post: (url, options) => { + capturedOptions = options + return Promise.resolve({ + res: { statusCode: 200 }, + payload: { success: true } + }) + } + }) + } + + const http = proxyquire('../server/http', { + '@hapi/wreck': wreckStub + }) + + await http.postJson(testUrl, emptyPayload) + + Code.expect(capturedOptions.payload).to.equal(emptyPayload) + }) + + lab.test('should throw error when status code is not 200', async () => { + const testUrl = 'https://api.example.com/test' + const testPayload = { action: 'update' } + + const wreckStub = { + defaults: () => ({ + get: () => Promise.resolve({ res: { statusCode: 200 }, payload: {} }), + post: () => Promise.resolve({ + res: { statusCode: 400 }, + payload: { error: 'Bad Request' } + }) + }) + } + + const http = proxyquire('../server/http', { + '@hapi/wreck': wreckStub + }) + + await Code.expect(http.postJson(testUrl, testPayload)) + .to.reject(Error, 'Requested resource returned a non 200 status code') + }) + + lab.test('should throw error when status code is 500', async () => { + const testUrl = 'https://api.example.com/test' + const testPayload = { action: 'update' } + + const wreckStub = { + defaults: () => ({ + get: () => Promise.resolve({ res: { statusCode: 200 }, payload: {} }), + post: () => Promise.resolve({ + res: { statusCode: 500 }, + payload: { error: 'Internal Server Error' } + }) + }) + } + + const http = proxyquire('../server/http', { + '@hapi/wreck': wreckStub + }) + + await Code.expect(http.postJson(testUrl, testPayload)) + .to.reject(Error, 'Requested resource returned a non 200 status code') + }) + + lab.test('should throw error when status code is 403', async () => { + const testUrl = 'https://api.example.com/test' + const testPayload = { action: 'update' } + + const wreckStub = { + defaults: () => ({ + get: () => Promise.resolve({ res: { statusCode: 200 }, payload: {} }), + post: () => Promise.resolve({ + res: { statusCode: 403 }, + payload: { error: 'Forbidden' } + }) + }) + } + + const http = proxyquire('../server/http', { + '@hapi/wreck': wreckStub + }) + + await Code.expect(http.postJson(testUrl, testPayload)) + .to.reject(Error, 'Requested resource returned a non 200 status code') + }) + + lab.test('should handle network errors', async () => { + const testUrl = 'https://api.example.com/test' + const testPayload = { action: 'update' } + const networkError = new Error('Network failure') + + const wreckStub = { + defaults: () => ({ + get: () => Promise.resolve({ res: { statusCode: 200 }, payload: {} }), + post: () => Promise.reject(networkError) + }) + } + + const http = proxyquire('../server/http', { + '@hapi/wreck': wreckStub + }) + + await Code.expect(http.postJson(testUrl, testPayload)) + .to.reject(Error, 'Network failure') + }) + + lab.test('should handle timeout errors', async () => { + const testUrl = 'https://api.example.com/test' + const testPayload = { action: 'update' } + const timeoutError = new Error('Request timeout') + timeoutError.code = 'ETIMEDOUT' + + const wreckStub = { + defaults: () => ({ + get: () => Promise.resolve({ res: { statusCode: 200 }, payload: {} }), + post: () => Promise.reject(timeoutError) + }) + } + + const http = proxyquire('../server/http', { + '@hapi/wreck': wreckStub + }) + + await Code.expect(http.postJson(testUrl, testPayload)) + .to.reject(Error, 'Request timeout') + }) + + lab.test('should handle connection refused errors', async () => { + const testUrl = 'https://api.example.com/test' + const testPayload = { action: 'update' } + const connError = new Error('connect ECONNREFUSED') + connError.code = 'ECONNREFUSED' + + const wreckStub = { + defaults: () => ({ + get: () => Promise.resolve({ res: { statusCode: 200 }, payload: {} }), + post: () => Promise.reject(connError) + }) + } + + const http = proxyquire('../server/http', { + '@hapi/wreck': wreckStub + }) + + await Code.expect(http.postJson(testUrl, testPayload)) + .to.reject(Error, 'connect ECONNREFUSED') + }) + + lab.test('should handle complex payloads', async () => { + const testUrl = 'https://api.example.com/test' + const complexPayload = { + warning: { + id: '123', + severity: 'high', + message: 'Test warning', + coordinates: [1.23, 4.56], + metadata: { + source: 'test', + timestamp: new Date().toISOString() + } + } + } + + let capturedOptions = null + + const wreckStub = { + defaults: () => ({ + get: () => Promise.resolve({ res: { statusCode: 200 }, payload: {} }), + post: (url, options) => { + capturedOptions = options + return Promise.resolve({ + res: { statusCode: 200 }, + payload: { success: true } + }) + } + }) + } + + const http = proxyquire('../server/http', { + '@hapi/wreck': wreckStub + }) + + await http.postJson(testUrl, complexPayload) + + Code.expect(capturedOptions.payload).to.equal(complexPayload) + }) + }) +}) diff --git a/test/mock.js b/test/mock.js deleted file mode 100644 index fea89e0..0000000 --- a/test/mock.js +++ /dev/null @@ -1,21 +0,0 @@ -module.exports = { - replace: function replace (obj, name, fn) { - // Store the original function - const original = obj[name] - - // Override the function - obj[name] = fn - - // Return a handy cleanup function - return { - revert: function () { - obj[name] = original - } - } - }, - makePromise: function makePromise (...args) { - return function () { - return args[0] ? Promise.reject(args[0]) : Promise.resolve(args[1]) - } - } -} diff --git a/test/routes/index-happy.js b/test/routes/index-happy.js index cafbec3..0cb8479 100644 --- a/test/routes/index-happy.js +++ b/test/routes/index-happy.js @@ -141,7 +141,8 @@ lab.experiment(('All basic routes'), () => { text: [ 'Appleby, Holme and Chapel Street and Cherry Row (011FWFNC1D)', '
There are no warnings currently in force for Appleby, Holme and Chapel Street and Cherry Row
', - 'Login' + 'Login', + 'test-name' ] }, { url: '/target-area/011WACN6', @@ -162,6 +163,12 @@ lab.experiment(('All basic routes'), () => { strategy: 'azure-legacy', credentials: postLoginCredentials } + }, { + url: '/target-area/012WACLS', + code: 200, + text: [ + 'test-name' + ] }, { url: '/target-area/sdfdsf', code: 404, @@ -260,6 +267,55 @@ lab.experiment(('All basic routes'), () => { strategy: 'azure-legacy', credentials: postLoginCredentials } + }, { + method: 'POST', + url: '/target-area/011FWFNC1D/edit', + code: 302, + payload: { + severity: 2, + situation: 'Valid test situation' + }, + auth: { + strategy: 'azure-legacy', + credentials: postLoginCredentials + } + }, { + method: 'POST', + url: '/target-area//edit', + code: 404, + payload: { + severity: 1, + situation: 'Test situation' + }, + auth: { + strategy: 'azure-legacy', + credentials: postLoginCredentials + } + }, { + method: 'POST', + url: '/target-area/011WACN6/edit', + code: 302, + payload: { + severity: 1, + situation: 'FWIS management console test data' + }, + auth: { + strategy: 'azure-legacy', + credentials: postLoginCredentials + } + }, { + method: 'POST', + url: '/target-area/011WACN6/edit', + code: 200, + payload: { + severity: 2, + situation: 'FWIS management console test data' + }, + auth: { + strategy: 'azure-legacy', + credentials: postLoginCredentials + }, + text: ['Situation must be updated when severity is updated'] }, { url: '/severity-view', code: 200, diff --git a/test/routes/index-sad.js b/test/routes/index-sad.js index 3cc8b50..201958e 100644 --- a/test/routes/index-sad.js +++ b/test/routes/index-sad.js @@ -100,6 +100,42 @@ lab.experiment(('All basic routes'), () => { } } } + }, { + method: 'GET', + url: '/target-area/011FWFNC1D/edit', + code: 403, + auth: { + strategy: 'azure-legacy', + credentials: { + scope: [''], + isAdmin: false, + profile: { + id: 'test', + displayName: 'Smith, John', + email: 'john.smith@defra.net' + } + } + } + }, { + method: 'POST', + url: '/target-area/011FWFNC1D/edit', + code: 403, + payload: { + severity: 1, + situation: 'Test situation' + }, + auth: { + strategy: 'azure-legacy', + credentials: { + scope: [''], + isAdmin: false, + profile: { + id: 'test', + displayName: 'Smith, John', + email: 'john.smith@defra.net' + } + } + } }] urls.forEach(item => { diff --git a/test/server.js b/test/server.js index d349da5..4f127d8 100644 --- a/test/server.js +++ b/test/server.js @@ -3,38 +3,14 @@ // can be used to connect to a containerised Redis instance. process.env.LOCAL_CACHE = true -const mock = require('./mock') -const mocks = {} +const sinon = require('sinon') const data = require('./data') let composeServer = require('../server') -let services = require('../server/services') - -const setMocks = () => { - console.log('Mocking server') - mocks.getFloods = mock.replace(services, 'getFloods', mock.makePromise(null, data.getFloods)) - mocks.getFloodPlus = mock.replace(services, 'getFloodsPlus', mock.makePromise(null, data.getFloodsPlus)) - mocks.getHistoricFloods = mock.replace(services, 'getHistoricFloods', mock.makePromise(null, data.getHistoricFloods)) - mocks.getAllAreas = mock.replace(services, 'getAllAreas', mock.makePromise(null, data.getAllAreas)) - mocks.updateWarning = mock.replace(services, 'updateWarning', mock.makePromise()) -} - -const setErrorMocks = async () => { - console.log('Mocking server with errors') - mocks.getFloods = mock.replace(services, 'getFloods', mock.makePromise(new Error('Failed to get floods'))) - mocks.getFloodsPlus = mock.replace(services, 'getFloodsPlus', mock.makePromise(new Error('Failed to get floods plus'))) - mocks.getHistoricFloods = mock.replace(services, 'getHistoricFloods', mock.makePromise(new Error('Failed to get historic floods'))) - mocks.getAllAreas = mock.replace(services, 'getAllAreas', mock.makePromise(new Error('Failed to get all areas'))) - mocks.updateWarning = mock.replace(services, 'updateWarning', mock.makePromise(new Error('Failed to update warning'))) -} - -const clearMocks = () => { - Object.keys(mocks).forEach((key) => { - mocks[key].revert() - }) -} +const services = require('../server/services') let server +let stubs = [] module.exports = { initRedisCache: () => { @@ -46,7 +22,6 @@ module.exports = { // that they use the current value of // process.env.LOCAL_CACHE. composeServer = require('../server') - services = require('../server/services') }, start: async (err = false, useMocks = true) => { console.log('Starting server') @@ -55,15 +30,32 @@ module.exports = { // override the mocks in the server method configuration test // files. if (useMocks) { - err ? setErrorMocks() : setMocks() + if (err) { + console.log('Mocking server with errors') + stubs.push(sinon.stub(services, 'getFloods').rejects(new Error('Failed to get floods'))) + stubs.push(sinon.stub(services, 'getFloodsPlus').rejects(new Error('Failed to get floods plus'))) + stubs.push(sinon.stub(services, 'getHistoricFloods').rejects(new Error('Failed to get historic floods'))) + stubs.push(sinon.stub(services, 'getAllAreas').rejects(new Error('Failed to get all areas'))) + stubs.push(sinon.stub(services, 'updateWarning').rejects(new Error('Failed to update warning'))) + } else { + console.log('Mocking server') + stubs.push(sinon.stub(services, 'getFloods').resolves(data.getFloods)) + stubs.push(sinon.stub(services, 'getFloodsPlus').resolves(data.getFloodsPlus)) + stubs.push(sinon.stub(services, 'getHistoricFloods').resolves(data.getHistoricFloods)) + stubs.push(sinon.stub(services, 'getAllAreas').resolves(data.getAllAreas)) + stubs.push(sinon.stub(services, 'updateWarning').resolves()) + } } + server = await composeServer() await server.initialize() return server }, stop: () => { console.log('Stopping server') - clearMocks() + stubs.forEach(stub => stub.restore()) + stubs = [] return server.stop() - } + }, + getStubs: () => stubs } diff --git a/test/services-with-redis-cache.js b/test/services-with-redis-cache.js index 50b83a7..e6db8e1 100644 --- a/test/services-with-redis-cache.js +++ b/test/services-with-redis-cache.js @@ -1,11 +1,9 @@ const Lab = require('@hapi/lab') const lab = exports.lab = Lab.script() const Code = require('@hapi/code') +const sinon = require('sinon') const data = require('./data') -const mock = require('./mock') -const mocks = {} - const ORIGINAL_CONFIG_CACHE = require.cache[require.resolve('../server/config')] const ORIGINAL_HTTP_CACHE = require.cache[require.resolve('../server/http')] const ORIGINAL_METHODS_CACHE = require.cache[require.resolve('../server/services/methods')] @@ -15,6 +13,7 @@ const ORIGINAL_SERVICES_CACHE = require.cache[require.resolve('../server/service let http let composeServer let services +let httpStubs = [] lab.experiment('Services', () => { lab.before(async () => { @@ -40,36 +39,31 @@ lab.experiment('Services', () => { require.cache[require.resolve('../server/services')] = ORIGINAL_SERVICES_CACHE }) - lab.beforeEach(async () => { - // mocks.getJson = mock.replace(http, 'getJson', mock.makePromise(null, {})) - // mocks.postJson = mock.replace(http, 'postJson', mock.makePromise(null, {})) - }) lab.afterEach(() => { - Object.keys(mocks).forEach((key) => { - mocks[key].revert() - }) + httpStubs.forEach(stub => stub.restore()) + httpStubs = [] }) lab.test('Services: getFloods', async () => { - mocks.getJson = mock.replace(http, 'getJson', mock.makePromise(null, data.getFloods)) + httpStubs.push(sinon.stub(http, 'getJson').resolves(data.getFloods)) const floods = await services.getFloods() Code.expect(floods.warnings.length).to.equal(57) }) lab.test('Services: getFloodsPlus', async () => { - mocks.getJson = mock.replace(http, 'getJson', mock.makePromise(null, data.getFloodsPlus)) + httpStubs.push(sinon.stub(http, 'getJson').resolves(data.getFloodsPlus)) const floods = await services.getFloodsPlus() Code.expect(floods.warnings.length).to.equal(57) }) lab.test('Services: getHistoricFloods', async () => { - mocks.getJson = mock.replace(http, 'getJson', mock.makePromise(null, data.getHistoricFloods)) + httpStubs.push(sinon.stub(http, 'getJson').resolves(data.getHistoricFloods)) const historicFloods = await services.getHistoricFloods() Code.expect(historicFloods.warnings.length).to.equal(67) }) lab.test('Services: getAllAreas', async () => { - mocks.getJson = mock.replace(http, 'getJson', mock.makePromise(null, data.targetAreas)) + httpStubs.push(sinon.stub(http, 'getJson').resolves(data.targetAreas)) const areas = await services.getAllAreas() Code.expect(areas.areas.length).to.equal(14) Code.expect(areas.areas[0].name).to.equal('Cumbria and Lancashire') @@ -80,17 +74,15 @@ lab.experiment('Services', () => { }) lab.test('Services: updateWarning', async () => { - mocks.postJson = mock.replace(http, 'postJson', (url, payload, ext) => { + httpStubs.push(sinon.stub(http, 'postJson').callsFake((url, payload, ext) => { Code.expect(payload.bodyXml).to.include('