Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cpx ldn #40

Open
wants to merge 9 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
npm test
3 changes: 3 additions & 0 deletions config/cap.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"bodyXml": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<alert xmlns=\"urn:oasis:names:tc:emergency:cap:1.2\">\r\n <identifier>4eb3b7350ab7aa443650fc9351f02940E</identifier>\r\n <sender>www.gov.uk/environment-agency</sender>\r\n <sent>2024-09-17:07:02-00:00</sent>\r\n <status>Actual</status>\r\n <msgType>Alert</msgType>\r\n <source>Flood warning service</source>\r\n <scope>Public</scope>\r\n <info>\r\n <language>en-GB</language>\r\n <category>Met</category>\r\n <event><![CDATA[TEST TEST TEST 064 Issue Flood Alert EA]]></event>\r\n <urgency>Immediate</urgency><expires>2024-09-20T12:00:02-00:00</expires><area><geocode><valueName>TargetAreaCode</valueName><value><![CDATA[TESTAREA1]]></value></geocode></area></info></alert>"
}
4,568 changes: 2,746 additions & 1,822 deletions package-lock.json

Large diffs are not rendered by default.

14 changes: 8 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,24 @@
"unit-test": "lab test -v -c --coverage-exclude lib/helpers -r console -o stdout -r lcov -o coverage/lcov.info -m 5000",
"test-config": "bin/create-test-config",
"test": "npm run lint && npm run unit-test",
"validate-config": "node ./config/index.js"
"validate-config": "node ./config/index.js",
"prepare": "husky"
},
"author": "The Environment Agency",
"license": "OGL",
"dependencies": {
"feed": "4.2.2",
"joi": "^17.11.0",
"moment": "^2.29.4",
"pg": "8.11.3",
"joi": "^17.13.3",
"moment": "^2.30.1",
"pg": "8.13.0",
"sql": "0.78.0",
"xml2js": "0.6.2"
},
"devDependencies": {
"@hapi/code": "^9.0.3",
"@hapi/lab": "^25.1.3",
"@hapi/lab": "^25.3.1",
"husky": "^9.1.6",
"serverless": "^3.35.2",
"standard": "17.1.0"
"standard": "17.1.2"
}
}
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![Build Status](https://travis-ci.org/DEFRA/cap-xml.svg?branch=master)](https://travis-ci.org/DEFRA/cap-xml)[![Maintainability](https://api.codeclimate.com/v1/badges/e6e726f97cd31b8569fa/maintainability)](https://codeclimate.com/github/DEFRA/cap-xml/maintainability)[![Test Coverage](https://api.codeclimate.com/v1/badges/e6e726f97cd31b8569fa/test_coverage)](https://codeclimate.com/github/DEFRA/cap-xml/test_coverage)
![Build status](https://github.com/DEFRA/cap-xml/actions/workflows/ci.yml/badge.svg)[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=DEFRA_cap-xml&metric=alert_status)](https://sonarcloud.io/dashboard?id=DEFRA_cap-xml)[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=DEFRA_cap-xml&metric=coverage)](https://sonarcloud.io/dashboard?id=DEFRA_cap-xml)

# CAP-XML Services

Expand Down
5 changes: 5 additions & 0 deletions serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ provider:
subnetIds:
- ${env:SLS_SUBNET_1}
- ${env:SLS_SUBNET_2}

package:
exclude:
- test
Expand All @@ -31,3 +32,7 @@ functions:
archiveMessages:
handler: lib/functions/archiveMessages.archiveMessages
timeout: 240
events:
- schedule:
rate: cron(0 2 * * ? *)
enabled: true
29 changes: 29 additions & 0 deletions test/schemas.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const Lab = require('@hapi/lab')
const lab = exports.lab = Lab.script()
const Code = require('@hapi/code')
const configSchema = require('../config/schema')
const schemas = require('../lib/helpers/schemas')
const { getMessageEventSchema, processMessageEventSchema } = require('../lib/helpers/schemas')

lab.experiment('schemas', () => {
Expand Down Expand Up @@ -55,4 +56,32 @@ lab.experiment('schemas', () => {

Code.expect(validationResult.error).to.not.be.null()
})
lab.test('module exports the schemas correctly and validate their behavior', () => {
Code.expect(schemas).to.be.an.object()
Code.expect(schemas).to.include(['getMessageEventSchema', 'processMessageEventSchema'])

// Test valid data for getMessageEventSchema
const validGetMessageData = { pathParameters: { id: 'a1b2c3d4' } }
const getMessageValidationResult = schemas.getMessageEventSchema.validate(validGetMessageData)
Code.expect(getMessageValidationResult.error).to.not.exist()
Code.expect(getMessageValidationResult.value).to.equal(validGetMessageData)

// Test invalid data for getMessageEventSchema
const invalidGetMessageData = { pathParameters: { id: 'invalid' } }
const invalidGetMessageResult = schemas.getMessageEventSchema.validate(invalidGetMessageData)
Code.expect(invalidGetMessageResult.error).to.not.be.null()
Code.expect(invalidGetMessageResult.error.details[0].message).to.contain('must only contain hexadecimal characters')

// Test valid data for processMessageEventSchema
const validProcessMessageData = { bodyXml: '<xml />' }
const processMessageValidationResult = schemas.processMessageEventSchema.validate(validProcessMessageData)
Code.expect(processMessageValidationResult.error).to.not.exist()
Code.expect(processMessageValidationResult.value).to.equal(validProcessMessageData)

// Test invalid data for processMessageEventSchema
const invalidProcessMessageData = { bodyXml: 123 }
const invalidProcessMessageResult = schemas.processMessageEventSchema.validate(invalidProcessMessageData)
Code.expect(invalidProcessMessageResult.error).to.not.be.null()
Code.expect(invalidProcessMessageResult.error.details[0].message).to.contain('must be a string')
})
})
Loading