diff --git a/scripts/__test__/parse_dependency_updates.test.js b/scripts/__test__/parse_dependency_updates.test.js index c067345a..04e2a3b2 100644 --- a/scripts/__test__/parse_dependency_updates.test.js +++ b/scripts/__test__/parse_dependency_updates.test.js @@ -2,32 +2,32 @@ import { extractDependencyUpdatesFromList, isUpdate, fromString, - getAllUpdates, + getAllUpdates } from '../parse-dependency-updates'; const multipleUpdatesRequired = [ '/usr/local/Cellar/node/13.10.1/bin/node', '/Users/someone/git/prm-deductions-component-template/check_for_updates.js', '/Users/someone/git/prm-deductions-component-template:uuid@3.4.0:uuid@7.0.2:uuid@7.0.2', - '/Users/someone/git/prm-deductions-component-template:ppc@3.4.0:ppc@5.0.2:ppc@7.0.2', + '/Users/someone/git/prm-deductions-component-template:ppc@3.4.0:ppc@5.0.2:ppc@7.0.2' ]; const testData = [ '/usr/local/Cellar/node/13.10.1/bin/node', '/Users/someone/git/prm-deductions-component-template/check_for_updates.js', - '/Users/someone/git/prm-deductions-component-template:uuid@3.4.0:uuid@7.0.2:uuid@7.0.2', + '/Users/someone/git/prm-deductions-component-template:uuid@3.4.0:uuid@7.0.2:uuid@7.0.2' ]; const noUpdatesRequired = [ '/usr/local/Cellar/node/13.10.1/bin/node', - '/Users/someone/git/prm-deductions-component-template/check_for_updates.js', + '/Users/someone/git/prm-deductions-component-template/check_for_updates.js' ]; describe('parse_dependency_updates.js', () => { describe('extractDependencyUpdatesFromList', () => { it('should filter the list to just dependency updates', () => { expect(extractDependencyUpdatesFromList(testData)).toEqual([ - '/Users/someone/git/prm-deductions-component-template:uuid@3.4.0:uuid@7.0.2:uuid@7.0.2', + '/Users/someone/git/prm-deductions-component-template:uuid@3.4.0:uuid@7.0.2:uuid@7.0.2' ]); }); @@ -60,7 +60,7 @@ describe('parse_dependency_updates.js', () => { package: 'uuid', currentVersion: '3.4.0', wantedVersion: '7.0.2', - latestVersion: '7.0.2', + latestVersion: '7.0.2' }); }); }); @@ -72,14 +72,14 @@ describe('parse_dependency_updates.js', () => { package: 'uuid', currentVersion: '3.4.0', wantedVersion: '7.0.2', - latestVersion: '7.0.2', + latestVersion: '7.0.2' }, { package: 'ppc', currentVersion: '3.4.0', wantedVersion: '5.0.2', - latestVersion: '7.0.2', - }, + latestVersion: '7.0.2' + } ]); }); }); diff --git a/scripts/parse-dependency-updates.js b/scripts/parse-dependency-updates.js index 4e6610b3..b67f14ac 100644 --- a/scripts/parse-dependency-updates.js +++ b/scripts/parse-dependency-updates.js @@ -14,7 +14,7 @@ const fromString = (updateString) => { package: matcher[1], wantedVersion: matcher[2], currentVersion: matcher[3], - latestVersion: matcher[4], + latestVersion: matcher[4] }; }; @@ -36,7 +36,7 @@ module.exports = { isUpdate, fromString, getAllUpdates, - getAllUpdatesText, + getAllUpdatesText }; console.log(getAllUpdates(process.argv)); diff --git a/scripts/wait-for-localstack.js b/scripts/wait-for-localstack.js index c72f4419..938c526e 100644 --- a/scripts/wait-for-localstack.js +++ b/scripts/wait-for-localstack.js @@ -8,12 +8,12 @@ const isConnected = () => { accessKeyId: 'test-access-key', secretAccessKey: 'test-secret-key', endpoint: new Endpoint(process.env.LOCALSTACK_URL), - s3ForcePathStyle: true, + s3ForcePathStyle: true }); s3.headBucket( { - Bucket: process.env.S3_BUCKET_NAME, + Bucket: process.env.S3_BUCKET_NAME }, (err) => { if (err) resolve(false); diff --git a/src/__builders__/logging-helper.js b/src/__builders__/logging-helper.js index fdbab4ad..7fcef83c 100644 --- a/src/__builders__/logging-helper.js +++ b/src/__builders__/logging-helper.js @@ -1,6 +1,6 @@ export const transportSpy = { log: jest.fn(), - on: jest.fn(), + on: jest.fn() }; export const expectStructuredLogToContain = (spy, expectedStructure) => { diff --git a/src/__tests__/app.integration.test.js b/src/__tests__/app.integration.test.js index ab712726..fb86856d 100644 --- a/src/__tests__/app.integration.test.js +++ b/src/__tests__/app.integration.test.js @@ -9,7 +9,7 @@ import { getCoreByKey } from '../services/database/ehr-core-repository'; import { cleanupRecordsForTest, cleanupRecordsForTestByNhsNumber, - createConversationForTest, + createConversationForTest } from '../utilities/integration-test-utilities'; import { getConversationById } from '../services/database/ehr-conversation-repository'; import { ConversationStatus, MessageType, RecordType } from '../models/enums'; @@ -31,9 +31,9 @@ describe('app', () => { conversationId, messageType: MessageType.EHR_EXTRACT, nhsNumber, - fragmentMessageIds, - }, - }, + fragmentMessageIds + } + } }); const createReqBodyForFragment = (messageId, conversationId, fragmentMessageIds = []) => ({ @@ -43,9 +43,9 @@ describe('app', () => { attributes: { conversationId, messageType: MessageType.FRAGMENT, - fragmentMessageIds: fragmentMessageIds, - }, - }, + fragmentMessageIds: fragmentMessageIds + } + } }); beforeEach(() => { @@ -74,7 +74,7 @@ describe('app', () => { expectStructuredLogToContain(transportSpy, { messageId, conversationId, - traceId: expect.anything(), + traceId: expect.anything() }); }); }); @@ -97,9 +97,9 @@ describe('app', () => { conversationId, messageType: MessageType.EHR_EXTRACT, nhsNumber, - fragmentMessageIds: [fragmentMessageId], - }, - }, + fragmentMessageIds: [fragmentMessageId] + } + } }) .set('Authorization', authorizationKeys); @@ -115,9 +115,9 @@ describe('app', () => { conversationId, messageType: MessageType.FRAGMENT, nhsNumber: '', - fragmentMessageIds: [], - }, - }, + fragmentMessageIds: [] + } + } }) .set('Authorization', authorizationKeys); @@ -136,7 +136,7 @@ describe('app', () => { expectStructuredLogToContain(transportSpy, { messageId: fragmentMessageId, conversationId, - traceId: expect.anything(), + traceId: expect.anything() }); }); @@ -172,9 +172,9 @@ describe('app', () => { conversationId, messageType: MessageType.EHR_EXTRACT, nhsNumber, - fragmentMessageIds: [], - }, - }, + fragmentMessageIds: [] + } + } }) .set('Authorization', authorizationKeys); @@ -207,9 +207,9 @@ describe('app', () => { conversationId, messageType: MessageType.EHR_EXTRACT, nhsNumber, - fragmentMessageIds: [fragmentId], - }, - }, + fragmentMessageIds: [fragmentId] + } + } }) .set('Authorization', authorizationKeys); @@ -259,7 +259,7 @@ describe('app', () => { // mimic the record at Conversation Layer, which should in actual case should be already created by ehr-transfer-service await createConversationForTest(inboundConversationId, nhsNumber, { - TransferStatus: ConversationStatus.STARTED, + TransferStatus: ConversationStatus.STARTED }); const messageResponse = await request(app) @@ -272,9 +272,9 @@ describe('app', () => { conversationId: inboundConversationId, messageType: MessageType.EHR_EXTRACT, nhsNumber, - fragmentMessageIds: [fragmentId], - }, - }, + fragmentMessageIds: [fragmentId] + } + } }) .set('Authorization', authorizationKeys); expect(messageResponse.status).toEqual(201); @@ -288,9 +288,9 @@ describe('app', () => { attributes: { conversationId: inboundConversationId, messageType: MessageType.FRAGMENT, - fragmentMessageIds: [nestedFragmentId], - }, - }, + fragmentMessageIds: [nestedFragmentId] + } + } }) .set('Authorization', authorizationKeys); @@ -305,9 +305,9 @@ describe('app', () => { attributes: { conversationId: inboundConversationId, messageType: MessageType.FRAGMENT, - fragmentMessageIds: [], - }, - }, + fragmentMessageIds: [] + } + } }) .set('Authorization', authorizationKeys); @@ -332,7 +332,7 @@ describe('app', () => { expect(patientRes.body.conversationIdFromEhrIn).toEqual(inboundConversationId); expectStructuredLogToContain(transportSpy, { conversationId: outboundConversationId, - traceId: expect.anything(), + traceId: expect.anything() }); }); @@ -350,7 +350,7 @@ describe('app', () => { // then expectStructuredLogToContain(transportSpy, { conversationId: outboundConversationId, - traceId: expect.anything(), + traceId: expect.anything() }); }); @@ -364,7 +364,7 @@ describe('app', () => { // mimic the record at Conversation Layer, which should in actual case should be already created by ehr-transfer-service await createConversationForTest(inboundConversationId, nhsNumber, { - TransferStatus: ConversationStatus.STARTED, + TransferStatus: ConversationStatus.STARTED }); const messageResponse = await request(app) @@ -377,9 +377,9 @@ describe('app', () => { conversationId: inboundConversationId, messageType: MessageType.EHR_EXTRACT, nhsNumber, - fragmentMessageIds: [fragmentId], - }, - }, + fragmentMessageIds: [fragmentId] + } + } }) .set('Authorization', authorizationKeys); @@ -405,7 +405,7 @@ describe('app', () => { messageId = uuid(); conversationId = uuid(); createConversationForTest(conversationId, nhsNumber, { - TransferStatus: ConversationStatus.STARTED, + TransferStatus: ConversationStatus.STARTED }); }); @@ -435,7 +435,7 @@ describe('app', () => { expectStructuredLogToContain(transportSpy, { messageId, conversationId, - traceId: expect.anything(), + traceId: expect.anything() }); }); @@ -461,7 +461,7 @@ describe('app', () => { expectStructuredLogToContain(transportSpy, { messageId, conversationId, - traceId: expect.anything(), + traceId: expect.anything() }); }); @@ -493,7 +493,7 @@ describe('app', () => { expectStructuredLogToContain(transportSpy, { messageId: fragmentMessageId, conversationId, - traceId: expect.anything(), + traceId: expect.anything() }); }); @@ -522,7 +522,7 @@ describe('app', () => { expectStructuredLogToContain(transportSpy, { messageId: fragmentMessageId, conversationId, - traceId: expect.anything(), + traceId: expect.anything() }); }); @@ -553,7 +553,7 @@ describe('app', () => { expectStructuredLogToContain(transportSpy, { messageId: nestedFragmentId, conversationId, - traceId: expect.anything(), + traceId: expect.anything() }); }); @@ -565,7 +565,7 @@ describe('app', () => { .set('traceid', 'our trace ID'); expectStructuredLogToContain(transportSpy, { - traceId: 'our trace ID', + traceId: 'our trace ID' }); }); }); @@ -581,7 +581,7 @@ describe('app', () => { fragmentMessageIds = [] ) => { await createConversationForTest(conversationId, nhsNumber, { - TransferStatus: ConversationStatus.STARTED, + TransferStatus: ConversationStatus.STARTED }); await request(app) .post(`/messages`) @@ -621,7 +621,7 @@ describe('app', () => { expect(getPatientResponse.status).toBe(200); expect(getPatientResponse.body).toMatchObject({ conversationIdFromEhrIn: inboundConversationId, - fragmentMessageIds: expect.arrayContaining(fragmentMessageIds), + fragmentMessageIds: expect.arrayContaining(fragmentMessageIds) }); const timestampBeforeDelete = getEpochTimeInSecond(moment().add(8, 'week')); @@ -634,7 +634,7 @@ describe('app', () => { expect(deleteResponse.status).toBe(200); expect(deleteResponse.body.data).toMatchObject({ conversationIds: [inboundConversationId], - id: nhsNumber, + id: nhsNumber }); const getPatientResponseAfterDeletion = await callGetPatient(nhsNumber); @@ -652,7 +652,7 @@ describe('app', () => { for (const item of softDeletedRecords) { expect(item).toMatchObject({ InboundConversationId: inboundConversationId, - DeletedAt: expect.any(Number), + DeletedAt: expect.any(Number) }); expect(item.DeletedAt).toBeGreaterThanOrEqual(timestampBeforeDelete); expect(item.DeletedAt).toBeLessThanOrEqual(timestampAfterDelete); @@ -675,7 +675,7 @@ describe('app', () => { expect(getPatientResponse.status).toBe(200); expect(getPatientResponse.body).toMatchObject({ conversationIdFromEhrIn: inboundConversationId2, - fragmentMessageIds: [], + fragmentMessageIds: [] }); // when @@ -687,7 +687,7 @@ describe('app', () => { expect(deleteResponse.status).toBe(200); expect(deleteResponse.body.data).toMatchObject({ conversationIds: expect.arrayContaining([inboundConversationId1, inboundConversationId2]), - id: nhsNumber, + id: nhsNumber }); const getPatientResponseAfterDeletion = await callGetPatient(nhsNumber); diff --git a/src/api/fragments/__tests__/get-fragment-controller.test.js b/src/api/fragments/__tests__/get-fragment-controller.test.js index be512454..e35f2b7b 100644 --- a/src/api/fragments/__tests__/get-fragment-controller.test.js +++ b/src/api/fragments/__tests__/get-fragment-controller.test.js @@ -10,12 +10,12 @@ jest.mock('../../../services/storage'); jest.mock('../../../services/database/ehr-fragment-repository'); jest.mock('../../../middleware/logging'); jest.mock('../../../config', () => ({ - initializeConfig: jest.fn().mockReturnValue({}), + initializeConfig: jest.fn().mockReturnValue({}) })); describe('getFragmentController', () => { initializeConfig.mockReturnValue({ - consumerApiKeys: { TEST_USER: 'correct-key' }, + consumerApiKeys: { TEST_USER: 'correct-key' } }); const authorizationKeys = 'correct-key'; @@ -96,7 +96,7 @@ describe('getFragmentController', () => { // then expect(response.status).toBe(422); expect(response.body).toEqual({ - errors: expectedErrorMessage, + errors: expectedErrorMessage }); }); @@ -114,7 +114,7 @@ describe('getFragmentController', () => { // then expect(response.status).toBe(422); expect(response.body).toEqual({ - errors: errorMessage, + errors: errorMessage }); }); }); diff --git a/src/api/fragments/get-fragment-controller.js b/src/api/fragments/get-fragment-controller.js index b39c9a55..b9fa8b43 100644 --- a/src/api/fragments/get-fragment-controller.js +++ b/src/api/fragments/get-fragment-controller.js @@ -6,7 +6,7 @@ import { fragmentAlreadyReceived } from '../../services/database/ehr-fragment-re export const getFragmentControllerValidation = [ param('conversationId').isUUID().withMessage("'conversationId' provided is not a UUID"), - param('messageId').isUUID().withMessage("'messageId' provided is not a UUID"), + param('messageId').isUUID().withMessage("'messageId' provided is not a UUID") ]; export const getFragmentController = async (req, res) => { diff --git a/src/api/health-check/__tests__/health-check.test.js b/src/api/health-check/__tests__/health-check.test.js index 26583af2..2c060df8 100644 --- a/src/api/health-check/__tests__/health-check.test.js +++ b/src/api/health-check/__tests__/health-check.test.js @@ -172,12 +172,12 @@ describe('GET /health', () => { const expectedS3Base = (isWritable, isConnected) => { const s3Base = { available: isConnected, - writable: isWritable, + writable: isWritable }; return !isWritable ? { ...s3Base, - error: mockErrorResponse, + error: mockErrorResponse } : s3Base; }; @@ -190,20 +190,20 @@ const expectedHealthCheckBase = ( ) => ({ details: { filestore: expectedS3Base(s3_writable, s3_connected), - database: getExpectedDatabase(db_writable, db_connected), - }, + database: getExpectedDatabase(db_writable, db_connected) + } }); const getExpectedDatabase = (isWritable, isConnected) => { const baseConf = { connection: isConnected, - writable: isWritable, + writable: isWritable }; return !isWritable ? { ...baseConf, - error: mockErrorResponse, + error: mockErrorResponse } : baseConf; }; diff --git a/src/api/health-check/health-check.js b/src/api/health-check/health-check.js index 2d7cd6a3..825e9993 100644 --- a/src/api/health-check/health-check.js +++ b/src/api/health-check/health-check.js @@ -7,10 +7,7 @@ export const healthCheck = express.Router(); healthCheck.get('/', (req, res, next) => { getHealthCheck() .then((status) => { - if ( - status.details.filestore.writable && - status.details.filestore.available - ) { + if (status.details.filestore.writable && status.details.filestore.available) { logInfo('Health check successful'); res.status(200).json(status); } else { diff --git a/src/api/messages/__tests__/message-location-controller.test.js b/src/api/messages/__tests__/message-location-controller.test.js index 38d5ce51..33ac3557 100644 --- a/src/api/messages/__tests__/message-location-controller.test.js +++ b/src/api/messages/__tests__/message-location-controller.test.js @@ -10,12 +10,12 @@ jest.mock('../../../services/storage'); jest.mock('../../../services/database/ehr-fragment-repository'); jest.mock('../../../middleware/logging'); jest.mock('../../../config', () => ({ - initializeConfig: jest.fn().mockReturnValue({}), + initializeConfig: jest.fn().mockReturnValue({}) })); describe('messageLocationController', () => { initializeConfig.mockReturnValue({ - consumerApiKeys: { TEST_USER: 'correct-key' }, + consumerApiKeys: { TEST_USER: 'correct-key' } }); const authorizationKeys = 'correct-key'; @@ -86,7 +86,7 @@ describe('messageLocationController', () => { expect(res.status).toBe(422); expect(res.body).toEqual({ - errors: errorMessage, + errors: errorMessage }); }); @@ -101,7 +101,7 @@ describe('messageLocationController', () => { expect(res.status).toBe(422); expect(res.body).toEqual({ - errors: errorMessage, + errors: errorMessage }); }); }); diff --git a/src/api/messages/__tests__/store-message-controller.test.js b/src/api/messages/__tests__/store-message-controller.test.js index 60b573ea..e77170f0 100644 --- a/src/api/messages/__tests__/store-message-controller.test.js +++ b/src/api/messages/__tests__/store-message-controller.test.js @@ -6,12 +6,12 @@ import { logError } from '../../../middleware/logging'; import { MessageType } from '../../../models/enums'; import { getConversationStatus, - updateConversationCompleteness, + updateConversationCompleteness } from '../../../services/database/ehr-conversation-repository'; import { createCore } from '../../../services/database/ehr-core-repository'; import { fragmentExistsInRecord, - markFragmentAsReceivedAndCreateItsParts, + markFragmentAsReceivedAndCreateItsParts } from '../../../services/database/ehr-fragment-repository'; jest.mock('../../../services/database/ehr-conversation-repository'); @@ -19,12 +19,12 @@ jest.mock('../../../services/database/ehr-core-repository'); jest.mock('../../../services/database/ehr-fragment-repository'); jest.mock('../../../middleware/logging'); jest.mock('../../../config', () => ({ - initializeConfig: jest.fn().mockReturnValue({}), + initializeConfig: jest.fn().mockReturnValue({}) })); describe('storeMessageController', () => { initializeConfig.mockReturnValue({ - consumerApiKeys: { TEST_USER: 'correct-key' }, + consumerApiKeys: { TEST_USER: 'correct-key' } }); const authorizationKeys = 'correct-key'; @@ -45,9 +45,9 @@ describe('storeMessageController', () => { conversationId, messageType: MessageType.EHR_EXTRACT, nhsNumber, - fragmentMessageIds, - }, - }, + fragmentMessageIds + } + } }; }); @@ -71,7 +71,7 @@ describe('storeMessageController', () => { requestBody.data.attributes = { messageType: MessageType.FRAGMENT, conversationId, - fragmentMessageIds: [nestedFragmentId], + fragmentMessageIds: [nestedFragmentId] }; fragmentExistsInRecord.mockResolvedValueOnce(true); @@ -97,7 +97,7 @@ describe('storeMessageController', () => { requestBody.data.attributes = { messageType: MessageType.FRAGMENT, conversationId, - fragmentMessageIds: [], + fragmentMessageIds: [] }; fragmentExistsInRecord.mockResolvedValueOnce(false); @@ -127,9 +127,9 @@ describe('storeMessageController', () => { conversationId, messageType: MessageType.EHR_EXTRACT, nhsNumber, - fragmentMessageIds, - }, - }, + fragmentMessageIds + } + } }; it('should return a 503 when message cannot be stored in the database', async () => { createCore.mockRejectedValueOnce({ error: 'db is down' }); @@ -151,12 +151,12 @@ describe('storeMessageController', () => { const requestBody = { data: { attributes: { - conversationId: 'not-a-uuid', - }, - }, + conversationId: 'not-a-uuid' + } + } }; const errorMessage = { - 'data.attributes.conversationId': "'conversationId' provided is not a UUID", + 'data.attributes.conversationId': "'conversationId' provided is not a UUID" }; const res = await request(app) @@ -171,8 +171,8 @@ describe('storeMessageController', () => { it('should return 422 and an error message when messageId is not a UUID', async () => { const requestBody = { data: { - id: 'not-a-uuid', - }, + id: 'not-a-uuid' + } }; const errorMessage = { 'data.id': "'id' provided is not a UUID" }; @@ -188,8 +188,8 @@ describe('storeMessageController', () => { it('should return 422 and an error message when type is not messages', async () => { const requestBody = { data: { - type: 'not-messages', - }, + type: 'not-messages' + } }; const errorMessage = { 'data.type': 'Invalid value' }; @@ -210,9 +210,9 @@ describe('storeMessageController', () => { attributes: { conversationId: uuid(), nhsNumber: 'not-an-nhs-number', - messageType: 'ehrExtract', - }, - }, + messageType: 'ehrExtract' + } + } }; const errorMessage = { 'data.attributes.nhsNumber': "'nhsNumber' provided is not numeric" }; @@ -230,12 +230,12 @@ describe('storeMessageController', () => { data: { attributes: { nhsNumber: '1234567890987654', - messageType: 'ehrExtract', - }, - }, + messageType: 'ehrExtract' + } + } }; const errorMessage = { - 'data.attributes.nhsNumber': "'nhsNumber' provided is not 10 characters", + 'data.attributes.nhsNumber': "'nhsNumber' provided is not 10 characters" }; const res = await request(app) @@ -251,13 +251,13 @@ describe('storeMessageController', () => { const requestBody = { data: { attributes: { - messageType: 'not-a-message-type', - }, - }, + messageType: 'not-a-message-type' + } + } }; const errorMessage = { 'data.attributes.messageType': - "'messageType' provided is not one of the following: ehrExtract, fragment", + "'messageType' provided is not one of the following: ehrExtract, fragment" }; const res = await request(app) @@ -278,9 +278,9 @@ describe('storeMessageController', () => { conversationId: uuid(), nhsNumber: '1234567890', messageType: 'ehrExtract', - fragmentMessageIds: [], - }, - }, + fragmentMessageIds: [] + } + } }; const res = await request(app) @@ -295,13 +295,13 @@ describe('storeMessageController', () => { const requestBody = { data: { attributes: { - messageType: 'ehrExtract', - }, - }, + messageType: 'ehrExtract' + } + } }; const errorMessage = { - 'data.attributes.nhsNumber': "'nhsNumber' is required for messageType ehrExtract", + 'data.attributes.nhsNumber': "'nhsNumber' is required for messageType ehrExtract" }; const res = await request(app) @@ -322,9 +322,9 @@ describe('storeMessageController', () => { conversationId: uuid(), nhsNumber: '1234567890', messageType: 'ehrExtract', - fragmentMessageIds: [], - }, - }, + fragmentMessageIds: [] + } + } }; const res = await request(app) .post('/messages') @@ -339,13 +339,13 @@ describe('storeMessageController', () => { data: { attributes: { nhsNumber: '1234567890', - messageType: 'fragment', - }, - }, + messageType: 'fragment' + } + } }; const errorMessage = { - 'data.attributes.nhsNumber': "'nhsNumber' should be empty for messageType fragment", + 'data.attributes.nhsNumber': "'nhsNumber' should be empty for messageType fragment" }; const res = await request(app) @@ -365,9 +365,9 @@ describe('storeMessageController', () => { attributes: { conversationId: uuid(), messageType: 'fragment', - fragmentMessageIds: [], - }, - }, + fragmentMessageIds: [] + } + } }; const res = await request(app) @@ -382,13 +382,13 @@ describe('storeMessageController', () => { const requestBody = { data: { attributes: { - fragmentMessageIds: ['not-a-uuid'], - }, - }, + fragmentMessageIds: ['not-a-uuid'] + } + } }; const errorMessage = { - 'data.attributes.fragmentMessageIds[0]': "'fragmentMessageIds' should be UUIDs", + 'data.attributes.fragmentMessageIds[0]': "'fragmentMessageIds' should be UUIDs" }; const res = await request(app) @@ -404,13 +404,13 @@ describe('storeMessageController', () => { const requestBody = { data: { attributes: { - fragmentMessageIds: 'not-an-array', - }, - }, + fragmentMessageIds: 'not-an-array' + } + } }; const errorMessage = { - 'data.attributes.fragmentMessageIds': "'fragmentMessageIds' should be an array", + 'data.attributes.fragmentMessageIds': "'fragmentMessageIds' should be an array" }; const res = await request(app) @@ -431,9 +431,9 @@ describe('storeMessageController', () => { attributes: { conversationId: uuid(), nhsNumber: '1234567890', - messageType: 'ehrExtract', - }, - }, + messageType: 'ehrExtract' + } + } }; it('should return 401 when authentication keys are missing', async () => { diff --git a/src/api/messages/index.js b/src/api/messages/index.js index 36dc2d9a..db5ae9f3 100644 --- a/src/api/messages/index.js +++ b/src/api/messages/index.js @@ -3,11 +3,11 @@ import { authenticateRequest } from '../../middleware/auth'; import { validate } from '../../middleware/validation'; import { messageLocationController, - messageLocationControllerValidation, + messageLocationControllerValidation } from './message-location-controller'; import { storeMessageController, - storeMessageControllerValidation, + storeMessageControllerValidation } from './store-message-controller'; import * as tracing from '../../middleware/tracing'; diff --git a/src/api/messages/message-location-controller.js b/src/api/messages/message-location-controller.js index 12c36f21..451adb59 100644 --- a/src/api/messages/message-location-controller.js +++ b/src/api/messages/message-location-controller.js @@ -6,7 +6,7 @@ import { fragmentAlreadyReceived } from '../../services/database/ehr-fragment-re export const messageLocationControllerValidation = [ param('conversationId').isUUID().withMessage("'conversationId' provided is not a UUID"), - param('messageId').isUUID().withMessage("'messageId' provided is not a UUID"), + param('messageId').isUUID().withMessage("'messageId' provided is not a UUID") ]; export const messageLocationController = async (req, res) => { diff --git a/src/api/messages/store-message-controller.js b/src/api/messages/store-message-controller.js index b03e2dcc..d9f22783 100644 --- a/src/api/messages/store-message-controller.js +++ b/src/api/messages/store-message-controller.js @@ -5,11 +5,11 @@ import { setCurrentSpanAttributes } from '../../config/tracing'; import { createCore } from '../../services/database/ehr-core-repository'; import { fragmentExistsInRecord, - markFragmentAsReceivedAndCreateItsParts, + markFragmentAsReceivedAndCreateItsParts } from '../../services/database/ehr-fragment-repository'; import { getConversationStatus, - updateConversationCompleteness, + updateConversationCompleteness } from '../../services/database/ehr-conversation-repository'; export const storeMessageControllerValidation = [ @@ -40,7 +40,7 @@ export const storeMessageControllerValidation = [ .withMessage("'fragmentMessageIds' should be UUIDs"), body('data.attributes.fragmentMessageIds') .isArray() - .withMessage("'fragmentMessageIds' should be an array"), + .withMessage("'fragmentMessageIds' should be an array") ]; export const storeMessageController = async (req, res) => { @@ -53,7 +53,7 @@ export const storeMessageController = async (req, res) => { await createCore({ messageId, conversationId, - fragmentMessageIds, + fragmentMessageIds }); } if (messageType === MessageType.FRAGMENT) { diff --git a/src/api/patients/__tests__/delete-ehr-controller.test.js b/src/api/patients/__tests__/delete-ehr-controller.test.js index 2d160a59..2a9901f6 100644 --- a/src/api/patients/__tests__/delete-ehr-controller.test.js +++ b/src/api/patients/__tests__/delete-ehr-controller.test.js @@ -9,12 +9,12 @@ jest.mock('../../../services/database/ehr-conversation-repository'); jest.mock('../../../middleware/logging'); jest.mock('../../../services/storage/get-signed-url'); jest.mock('../../../config', () => ({ - initializeConfig: jest.fn().mockReturnValue({}), + initializeConfig: jest.fn().mockReturnValue({}) })); describe('deleteEhrController', () => { initializeConfig.mockReturnValue({ - consumerApiKeys: { TEST_USER: 'correct-key' }, + consumerApiKeys: { TEST_USER: 'correct-key' } }); const authorizationKeys = 'correct-key'; diff --git a/src/api/patients/__tests__/health-record-controller.test.js b/src/api/patients/__tests__/health-record-controller.test.js index 5f5c9d93..6ef1ad53 100644 --- a/src/api/patients/__tests__/health-record-controller.test.js +++ b/src/api/patients/__tests__/health-record-controller.test.js @@ -7,12 +7,12 @@ import { HealthRecordStatus } from '../../../models/enums'; jest.mock('../../../services/database/ehr-conversation-repository'); jest.mock('../../../config', () => ({ - initializeConfig: jest.fn().mockReturnValue({}), + initializeConfig: jest.fn().mockReturnValue({}) })); describe('healthRecordController', () => { initializeConfig.mockReturnValue({ - consumerApiKeys: { TEST_USER: 'correct-key' }, + consumerApiKeys: { TEST_USER: 'correct-key' } }); const authorizationKeys = 'correct-key'; diff --git a/src/api/patients/__tests__/patient-details-controller.test.js b/src/api/patients/__tests__/patient-details-controller.test.js index 2f9fc300..bdf46794 100644 --- a/src/api/patients/__tests__/patient-details-controller.test.js +++ b/src/api/patients/__tests__/patient-details-controller.test.js @@ -7,7 +7,7 @@ import { logError, logInfo, logWarning } from '../../../middleware/logging'; import getSignedUrl from '../../../services/storage/get-signed-url'; import { getCurrentConversationIdForPatient, - getMessageIdsForConversation, + getMessageIdsForConversation } from '../../../services/database/ehr-conversation-repository'; import { HealthRecordNotFoundError } from '../../../errors/errors'; @@ -15,12 +15,12 @@ jest.mock('../../../services/database/ehr-conversation-repository'); jest.mock('../../../middleware/logging'); jest.mock('../../../services/storage/get-signed-url'); jest.mock('../../../config', () => ({ - initializeConfig: jest.fn().mockReturnValue({}), + initializeConfig: jest.fn().mockReturnValue({}) })); describe('patientDetailsController', () => { initializeConfig.mockReturnValue({ - consumerApiKeys: { TEST_USER: 'correct-key' }, + consumerApiKeys: { TEST_USER: 'correct-key' } }); const authorizationKeys = 'correct-key'; @@ -36,7 +36,7 @@ describe('patientDetailsController', () => { getCurrentConversationIdForPatient.mockResolvedValue(conversationId); getMessageIdsForConversation.mockResolvedValue({ coreMessageId: messageId, - fragmentMessageIds: [], + fragmentMessageIds: [] }); getSignedUrl.mockResolvedValue(presignedUrl); @@ -65,7 +65,7 @@ describe('patientDetailsController', () => { getCurrentConversationIdForPatient.mockResolvedValue(conversationId); getMessageIdsForConversation.mockResolvedValue({ coreMessageId: healthRecordExtractId, - fragmentMessageIds: [fragmentMessageId], + fragmentMessageIds: [fragmentMessageId] }); when(getSignedUrl) .calledWith(conversationId, healthRecordExtractId, 'getObject') @@ -97,7 +97,7 @@ describe('patientDetailsController', () => { getCurrentConversationIdForPatient.mockResolvedValue(conversationId); getMessageIdsForConversation.mockResolvedValue({ coreMessageId: healthRecordExtractId, - fragmentMessageIds: [fragmentMessageId], + fragmentMessageIds: [fragmentMessageId] }); when(getSignedUrl) .calledWith(conversationId, healthRecordExtractId, 'getObject') @@ -144,7 +144,7 @@ describe('patientDetailsController', () => { // then expect(res.status).toEqual(503); expect(logError).toHaveBeenCalledWith('Could not retrieve patient health record', { - bob: 'cheese', + bob: 'cheese' }); }); }); diff --git a/src/api/patients/delete-ehr-controller.js b/src/api/patients/delete-ehr-controller.js index d859caa4..aa400001 100644 --- a/src/api/patients/delete-ehr-controller.js +++ b/src/api/patients/delete-ehr-controller.js @@ -6,7 +6,7 @@ export const deleteEhrValidation = [ .isNumeric() .withMessage("'nhsNumber' provided is not numeric") .isLength({ min: 10, max: 10 }) - .withMessage("'nhsNumber' provided is not 10 characters"), + .withMessage("'nhsNumber' provided is not 10 characters") ]; export const deleteEhrController = async (req, res) => { @@ -26,8 +26,8 @@ export const deleteEhrController = async (req, res) => { data: { type: 'patients', id: nhsNumber, - conversationIds, - }, + conversationIds + } }; res.status(200).json(responseBody); diff --git a/src/api/patients/health-record-controller.js b/src/api/patients/health-record-controller.js index 8219a827..d6e7dd73 100644 --- a/src/api/patients/health-record-controller.js +++ b/src/api/patients/health-record-controller.js @@ -9,7 +9,7 @@ export const healthRecordControllerValidation = [ .isNumeric() .withMessage("'nhsNumber' provided is not numeric") .isLength({ min: 10, max: 10 }) - .withMessage("'nhsNumber' provided is not 10 characters"), + .withMessage("'nhsNumber' provided is not 10 characters") ]; export const healthRecordController = async (req, res) => { diff --git a/src/api/patients/index.js b/src/api/patients/index.js index 1cfed792..adefe1eb 100644 --- a/src/api/patients/index.js +++ b/src/api/patients/index.js @@ -1,7 +1,7 @@ import express from 'express'; import { healthRecordController, - healthRecordControllerValidation, + healthRecordControllerValidation } from './health-record-controller'; import { validate } from '../../middleware/validation'; import { authenticateRequest } from '../../middleware/auth'; diff --git a/src/api/patients/patient-details-controller.js b/src/api/patients/patient-details-controller.js index 949d6e64..4faa2637 100644 --- a/src/api/patients/patient-details-controller.js +++ b/src/api/patients/patient-details-controller.js @@ -4,7 +4,7 @@ import getSignedUrl from '../../services/storage/get-signed-url'; import { setCurrentSpanAttributes } from '../../config/tracing'; import { getCurrentConversationIdForPatient, - getMessageIdsForConversation, + getMessageIdsForConversation } from '../../services/database/ehr-conversation-repository'; import { HealthRecordNotFoundError } from '../../errors/errors'; @@ -13,7 +13,7 @@ export const patientDetailsValidation = [ .isNumeric() .withMessage("'nhsNumber' provided is not numeric") .isLength({ min: 10, max: 10 }) - .withMessage("'nhsNumber' provided is not 10 characters"), + .withMessage("'nhsNumber' provided is not 10 characters") ]; export const patientDetailsController = async (req, res) => { @@ -41,7 +41,7 @@ export const patientDetailsController = async (req, res) => { // TODO: remove this duplicated `conversationIdFromEhrIn` field, // after updating ehr-out to use the field name "inboundConversationId" (planned in PRMT-4587) conversationIdFromEhrIn: currentHealthRecordConversationId, - inboundConversationId: currentHealthRecordConversationId, + inboundConversationId: currentHealthRecordConversationId }; res.status(200).json(responseBody); diff --git a/src/app.js b/src/app.js index de8477e5..1f680bb4 100644 --- a/src/app.js +++ b/src/app.js @@ -22,7 +22,7 @@ app.use(express.json()); // Sets "Strict-Transport-Security: max-age=31536000; includeSubDomains" app.use( helmet.hsts({ - maxAge: 31536000, + maxAge: 31536000 }) ); app.use(requestLogger(options)); diff --git a/src/config/__tests__/logging.test.js b/src/config/__tests__/logging.test.js index 98273279..eb74367b 100644 --- a/src/config/__tests__/logging.test.js +++ b/src/config/__tests__/logging.test.js @@ -6,8 +6,8 @@ jest.mock('winston', () => ({ log: jest.fn(), error: jest.fn(), debug: jest.fn(), - warn: jest.fn(), - })), + warn: jest.fn() + })) })); describe('logging', () => { @@ -17,24 +17,24 @@ describe('logging', () => { it('should replace top level data key value with obfuscated values', () => { const obfuscatedObject = formatter.transform({ - data: 'secret-payload', + data: 'secret-payload' }); expect(obfuscatedObject).toStrictEqual( expect.objectContaining({ - data: obfuscatedString, + data: obfuscatedString }) ); }); it('should replace top level passcode key value with obfuscated values', () => { const obfuscatedObject = formatter.transform({ - passcode: '123456789', + passcode: '123456789' }); expect(obfuscatedObject).toStrictEqual( expect.objectContaining({ - passcode: obfuscatedString, + passcode: obfuscatedString }) ); }); @@ -42,15 +42,15 @@ describe('logging', () => { it('should replace nested passcode key value with obfuscated values', () => { const obfuscatedObject = formatter.transform({ nested: { - passcode: '123456789', - }, + passcode: '123456789' + } }); expect(obfuscatedObject).toStrictEqual( expect.objectContaining({ nested: { - passcode: obfuscatedString, - }, + passcode: obfuscatedString + } }) ); }); @@ -58,15 +58,15 @@ describe('logging', () => { it('should replace nested passcode key value with obfuscated values', () => { const obfuscatedObject = formatter.transform({ nested: { - data: 'some-secret-data', - }, + data: 'some-secret-data' + } }); expect(obfuscatedObject).toStrictEqual( expect.objectContaining({ nested: { - data: obfuscatedString, - }, + data: obfuscatedString + } }) ); }); @@ -86,11 +86,11 @@ describe('logging', () => { login: 'abcdefg', authorization: '1234567', Authorization: '1234567', - apiKey: '1234567', - }, - }, + apiKey: '1234567' + } + } }, - [messageSymbol]: 'some-symbol-message', + [messageSymbol]: 'some-symbol-message' }); expect(result).toEqual({ @@ -104,11 +104,11 @@ describe('logging', () => { login: 'abcdefg', authorization: '********', Authorization: '********', - apiKey: '********', - }, - }, + apiKey: '********' + } + } }, - [messageSymbol]: 'some-symbol-message', + [messageSymbol]: 'some-symbol-message' }); }); }); @@ -138,10 +138,10 @@ describe('logging', () => { login: 'abcdefg', authorization: '1234567', Authorization: '1234567', - apiKey: '1234567', - }, - }, - }, + apiKey: '1234567' + } + } + } }); const messageSymbol = Object.getOwnPropertySymbols(result)[0]; diff --git a/src/config/index.js b/src/config/index.js index 6ebf87f7..51678bf8 100644 --- a/src/config/index.js +++ b/src/config/index.js @@ -5,7 +5,7 @@ export const initializeConfig = () => ({ awsS3BucketName: process.env.S3_BUCKET_NAME, localstackUrl: process.env.LOCALSTACK_URL, nhsEnvironment: process.env.NHS_ENVIRONMENT || 'local', - consumerApiKeys: loadConsumerKeys(), + consumerApiKeys: loadConsumerKeys() }); const loadConsumerKeys = () => { diff --git a/src/config/logging.js b/src/config/logging.js index 86748445..f79e4440 100644 --- a/src/config/logging.js +++ b/src/config/logging.js @@ -40,7 +40,7 @@ export const options = { format.json() ), level: process.env.LOG_LEVEL, - transports: [new transports.Console({ handleExceptions: true })], + transports: [new transports.Console({ handleExceptions: true })] }; export const logger = createLogger(options); diff --git a/src/errors/errors.js b/src/errors/errors.js index 3b24a217..d2248b56 100644 --- a/src/errors/errors.js +++ b/src/errors/errors.js @@ -2,7 +2,7 @@ import { logError } from '../middleware/logging'; export const errorMessages = { HealthRecordNotFound: 'No complete health record was found with given criteria', - MessageNotFound: 'There were no existing messages associated with conversation id', + MessageNotFound: 'There were no existing messages associated with conversation id' }; export class HealthRecordNotFoundError extends Error { diff --git a/src/middleware/__tests__/auth.test.js b/src/middleware/__tests__/auth.test.js index 0a72672d..05b95e0f 100644 --- a/src/middleware/__tests__/auth.test.js +++ b/src/middleware/__tests__/auth.test.js @@ -15,9 +15,9 @@ jest.mock('../../config', () => ({ consumerApiKeys: { TEST_USER: 'correct-key', DUPLICATE_TEST_USER: 'correct-key', - USER_2: 'key_2', - }, - }), + USER_2: 'key_2' + } + }) })); describe('auth', () => { @@ -39,7 +39,7 @@ describe('auth', () => { describe('Authorization key environment variables not provided', () => { it('should return 412 with an explicit error message if auth keys have not been set', async () => { const errorMessage = { - error: 'Server-side Authorization keys have not been set, cannot authenticate', + error: 'Server-side Authorization keys have not been set, cannot authenticate' }; initializeConfig.mockReturnValueOnce({ consumerApiKeys: {} }); const res = await request(app) @@ -54,7 +54,7 @@ describe('auth', () => { describe('Authorization header not provided', () => { it('should return HTTP 401 with an explicit error message when no authorization header provided', async () => { const errorMessage = { - error: 'The request (/messages) requires a valid Authorization header to be set', + error: 'The request (/messages) requires a valid Authorization header to be set' }; const res = await request(app).get(`/messages/${conversationId}/${messageId}`); diff --git a/src/middleware/__tests__/tracing.test.js b/src/middleware/__tests__/tracing.test.js index 6d9c0db3..4b9670d8 100644 --- a/src/middleware/__tests__/tracing.test.js +++ b/src/middleware/__tests__/tracing.test.js @@ -4,7 +4,7 @@ import { middleware } from '../tracing'; describe('tracing middleware', () => { it('should generate traceId if none is provided', () => { let req = { - headers: {}, + headers: {} }; startRequest(() => { middleware(req, {}, () => {}); @@ -16,8 +16,8 @@ describe('tracing middleware', () => { it('should set traceId to the traceId provided in the header', () => { let req = { headers: { - traceid: 'testtraceid', - }, + traceid: 'testtraceid' + } }; startRequest(() => { middleware(req, {}, () => {}); diff --git a/src/middleware/auth.js b/src/middleware/auth.js index fce5f36b..31730950 100644 --- a/src/middleware/auth.js +++ b/src/middleware/auth.js @@ -5,7 +5,7 @@ export const authenticateRequest = (req, res, next) => { const { consumerApiKeys } = initializeConfig(); if (Object.keys(consumerApiKeys).length === 0) { res.status(412).json({ - error: `Server-side Authorization keys have not been set, cannot authenticate`, + error: `Server-side Authorization keys have not been set, cannot authenticate` }); return; } @@ -15,7 +15,7 @@ export const authenticateRequest = (req, res, next) => { if (!authorizationKey) { res.status(401).json({ - error: `The request (${req.baseUrl}) requires a valid Authorization header to be set`, + error: `The request (${req.baseUrl}) requires a valid Authorization header to be set` }); return; } @@ -27,7 +27,7 @@ export const authenticateRequest = (req, res, next) => { }, API Key: ******${authorizationKey.slice(-3)}` ); res.status(403).json({ - error: `Authorization header is provided but not valid`, + error: `Authorization header is provided but not valid` }); return; } diff --git a/src/middleware/validation.js b/src/middleware/validation.js index f087d84b..edd4fe8c 100644 --- a/src/middleware/validation.js +++ b/src/middleware/validation.js @@ -11,9 +11,9 @@ export const validate = (req, res, next) => { const mappedErrors = errors.array().map((err) => ({ [err.param]: err.msg })); logError('validation-failed', { - validation: { errors: mappedErrors }, + validation: { errors: mappedErrors } }); return res.status(422).json({ - errors: mappedErrors, + errors: mappedErrors }); }; diff --git a/src/models/conversation.js b/src/models/conversation.js index c017b5c9..24072401 100644 --- a/src/models/conversation.js +++ b/src/models/conversation.js @@ -8,12 +8,12 @@ export const buildConversationUpdateParams = (conversationId, changes) => { const baseParams = { Key: { InboundConversationId: conversationId, - Layer: RecordType.CONVERSATION, + Layer: RecordType.CONVERSATION }, UpdateExpression: 'set UpdatedAt = :now', ExpressionAttributeValues: { - ':now': getUKTimestamp(), - }, + ':now': getUKTimestamp() + } }; return addChangesToUpdateParams(baseParams, changes, fieldsAllowedToUpdate); diff --git a/src/models/core.js b/src/models/core.js index 940051d1..d1e123be 100644 --- a/src/models/core.js +++ b/src/models/core.js @@ -14,7 +14,7 @@ export const buildCore = (inboundConversationId, messageId) => { CreatedAt: timestamp, ReceivedAt: timestamp, UpdatedAt: timestamp, - TransferStatus: CoreStatus.COMPLETE, + TransferStatus: CoreStatus.COMPLETE }; }; diff --git a/src/models/enums.js b/src/models/enums.js index 65f16136..66721604 100644 --- a/src/models/enums.js +++ b/src/models/enums.js @@ -2,7 +2,7 @@ export const RecordType = { ALL: 'ALL', CONVERSATION: 'CONVERSATION', CORE: 'CORE', - FRAGMENT: 'FRAGMENT', + FRAGMENT: 'FRAGMENT' }; export const ConversationStatus = { @@ -11,26 +11,26 @@ export const ConversationStatus = { CONTINUE_REQUEST_SENT: 'INBOUND_CONTINUE_REQUEST_SENT', COMPLETE: 'INBOUND_COMPLETE', FAILED: 'INBOUND_FAILED', - TIMEOUT: 'INBOUND_TIMEOUT', + TIMEOUT: 'INBOUND_TIMEOUT' }; export const CoreStatus = { - COMPLETE: 'STORED_IN_REPOSITORY', + COMPLETE: 'STORED_IN_REPOSITORY' }; export const FragmentStatus = { - COMPLETE: 'STORED_IN_REPOSITORY', + COMPLETE: 'STORED_IN_REPOSITORY' }; export const HealthRecordStatus = { COMPLETE: 'complete', PENDING: 'pending', - NOT_FOUND: 'notFound', + NOT_FOUND: 'notFound' }; export const MessageType = { EHR_EXTRACT: 'ehrExtract', - FRAGMENT: 'fragment', + FRAGMENT: 'fragment' }; Object.freeze(HealthRecordStatus); diff --git a/src/models/fragment.js b/src/models/fragment.js index 1ab5ea43..4200aa75 100644 --- a/src/models/fragment.js +++ b/src/models/fragment.js @@ -15,14 +15,14 @@ export const buildFragment = ({ inboundConversationId, fragmentMessageId, parent InboundMessageId: fragmentMessageId, ParentId: parentMessageId, CreatedAt: timestamp, - UpdatedAt: timestamp, + UpdatedAt: timestamp }; }; export const buildMultipleFragments = ({ inboundConversationId, fragmentMessageIds, - parentMessageId, + parentMessageId }) => { if (!fragmentMessageIds || !Array.isArray(fragmentMessageIds)) { return []; @@ -38,15 +38,15 @@ export const buildFragmentUpdateParams = (conversationId, messageId, changes) => const params = { Key: { InboundConversationId: conversationId, - Layer: [RecordType.FRAGMENT, messageId].join('#'), + Layer: [RecordType.FRAGMENT, messageId].join('#') }, UpdateExpression: `set CreatedAt = if_not_exists(CreatedAt, :now), \ InboundMessageId = if_not_exists(InboundMessageId, :messageId), \ UpdatedAt = :now`, ExpressionAttributeValues: { ':now': getUKTimestamp(), - ':messageId': messageId, - }, + ':messageId': messageId + } }; return addChangesToUpdateParams(params, changes, fieldsAllowedToUpdate); diff --git a/src/services/database/__tests__/ehr-conversation-repository.integration.test.js b/src/services/database/__tests__/ehr-conversation-repository.integration.test.js index 438be114..d5e89c8c 100644 --- a/src/services/database/__tests__/ehr-conversation-repository.integration.test.js +++ b/src/services/database/__tests__/ehr-conversation-repository.integration.test.js @@ -6,12 +6,12 @@ import { getMessageIdsForConversation, getConversationStatus, markRecordAsSoftDeleteForPatient, - updateConversationCompleteness, + updateConversationCompleteness } from '../ehr-conversation-repository'; import { ConversationStatus, HealthRecordStatus, RecordType } from '../../../models/enums'; import { cleanupRecordsForTest, - createConversationForTest, + createConversationForTest } from '../../../utilities/integration-test-utilities'; import { createCore } from '../ehr-core-repository'; import { EhrTransferTracker } from '../dynamo-ehr-transfer-tracker'; @@ -49,7 +49,7 @@ describe('ehr-conversation-repository', () => { const conversationId = uuid(); const nhsNumber = '1234567890'; await createConversationForTest(conversationId, nhsNumber, { - TransferStatus: ConversationStatus.COMPLETE, + TransferStatus: ConversationStatus.COMPLETE }); // when @@ -64,7 +64,7 @@ describe('ehr-conversation-repository', () => { const conversationId = uuid(); const nhsNumber = '1234567890'; await createConversationForTest(conversationId, nhsNumber, { - TransferStatus: ConversationStatus.CONTINUE_REQUEST_SENT, + TransferStatus: ConversationStatus.CONTINUE_REQUEST_SENT }); // when @@ -112,7 +112,7 @@ describe('ehr-conversation-repository', () => { const messageId = uuid(); const nhsNumber = '1234567890'; await createConversationForTest(conversationId, nhsNumber, { - TransferStatus: ConversationStatus.REQUEST_SENT, + TransferStatus: ConversationStatus.REQUEST_SENT }); await createCore({ conversationId, messageId, fragmentMessageIds: [] }); @@ -133,7 +133,7 @@ describe('ehr-conversation-repository', () => { const nhsNumber = '1234567890'; await createConversationForTest(conversationId, nhsNumber, { - TransferStatus: ConversationStatus.CONTINUE_REQUEST_SENT, + TransferStatus: ConversationStatus.CONTINUE_REQUEST_SENT }); await createCore({ conversationId, messageId, fragmentMessageIds: [fragmentMessageId] }); @@ -154,7 +154,7 @@ describe('ehr-conversation-repository', () => { const nhsNumber = '1234567890'; await createConversationForTest(conversationId, nhsNumber, { - TransferStatus: ConversationStatus.CONTINUE_REQUEST_SENT, + TransferStatus: ConversationStatus.CONTINUE_REQUEST_SENT }); await createCore({ conversationId, messageId, fragmentMessageIds: fragmentMessageIds }); for (const fragmentId of fragmentMessageIds) { @@ -197,15 +197,15 @@ describe('ehr-conversation-repository', () => { await createConversationForTest(previousHealthRecordConversationId, nhsNumber, { TransferStatus: ConversationStatus.COMPLETE, - CreatedAt: '2024-01-01T10:00:00+00:00', + CreatedAt: '2024-01-01T10:00:00+00:00' }); await createConversationForTest(incompleteHealthRecordConversationId, nhsNumber, { - TransferStatus: ConversationStatus.TIMEOUT, + TransferStatus: ConversationStatus.TIMEOUT }); await createConversationForTest(currentHealthRecordConversationId, nhsNumber, { - TransferStatus: ConversationStatus.COMPLETE, + TransferStatus: ConversationStatus.COMPLETE }); // when @@ -220,7 +220,7 @@ describe('ehr-conversation-repository', () => { const nhsNumber = '9876543211'; const incompleteHealthRecordConversationId = uuid(); await createConversationForTest(incompleteHealthRecordConversationId, nhsNumber, { - TransferStatus: ConversationStatus.TIMEOUT, + TransferStatus: ConversationStatus.TIMEOUT }); // when @@ -309,7 +309,7 @@ describe('ehr-conversation-repository', () => { await createCore({ conversationId, messageId, fragmentMessageIds: [fragmentMessageId] }); await markFragmentAsReceivedAndCreateItsParts(fragmentMessageId, conversationId, [ - nestedFragmentId, + nestedFragmentId ]); await markFragmentAsReceived(nestedFragmentId, conversationId); @@ -351,7 +351,7 @@ describe('ehr-conversation-repository', () => { fragmentMessageIds = [] ) => { await createConversationForTest(conversationId, nhsNumber, { - TransferStatus: ConversationStatus.COMPLETE, + TransferStatus: ConversationStatus.COMPLETE }); await createCore({ conversationId, messageId, fragmentMessageIds }); for (const fragmentMessageId of fragmentMessageIds) { @@ -389,7 +389,7 @@ describe('ehr-conversation-repository', () => { for (const item of deletedRecords) { expect(item).toMatchObject({ InboundConversationId: conversationId, - DeletedAt: expectedDeletedAtTime, + DeletedAt: expectedDeletedAtTime }); } }); @@ -426,7 +426,7 @@ describe('ehr-conversation-repository', () => { for (const item of deletedRecords) { expect(item).toMatchObject({ - DeletedAt: expectedDeletedAtTime, + DeletedAt: expectedDeletedAtTime }); } }); diff --git a/src/services/database/__tests__/ehr-core-repository.integration.test.js b/src/services/database/__tests__/ehr-core-repository.integration.test.js index 5f3e30f5..79e3c04e 100644 --- a/src/services/database/__tests__/ehr-core-repository.integration.test.js +++ b/src/services/database/__tests__/ehr-core-repository.integration.test.js @@ -3,7 +3,7 @@ import { v4 as uuid } from 'uuid'; import { logError } from '../../../middleware/logging'; import { createCore, getCoreByKey } from '../ehr-core-repository'; import { getFragmentByKey } from '../ehr-fragment-repository'; -import { RecordType } from "../../../models/enums"; +import { RecordType } from '../../../models/enums'; // Mocking jest.mock('../../../middleware/logging'); @@ -65,7 +65,7 @@ describe('ehr-core-repository', () => { const ehrExtract = { messageId, conversationId, - fragmentMessageIds: [], + fragmentMessageIds: [] }; try { diff --git a/src/services/database/__tests__/ehr-fragment-repository.integration.test.js b/src/services/database/__tests__/ehr-fragment-repository.integration.test.js index 7e2f3e80..09df6830 100644 --- a/src/services/database/__tests__/ehr-fragment-repository.integration.test.js +++ b/src/services/database/__tests__/ehr-fragment-repository.integration.test.js @@ -5,7 +5,7 @@ import { fragmentAlreadyReceived, fragmentExistsInRecord, getFragmentByKey, - markFragmentAsReceivedAndCreateItsParts, + markFragmentAsReceivedAndCreateItsParts } from '../ehr-fragment-repository'; import { buildFragment } from '../../../models/fragment'; import { EhrTransferTracker } from '../dynamo-ehr-transfer-tracker'; @@ -46,7 +46,7 @@ describe('ehr-fragment-repository', () => { await createCore({ conversationId, messageId: ehrMessageId, - fragmentMessageIds: [fragmentMessageId], + fragmentMessageIds: [fragmentMessageId] }); // when @@ -79,12 +79,12 @@ describe('ehr-fragment-repository', () => { await createCore({ conversationId, messageId: ehrMessageId, - fragmentMessageIds: [fragmentMessageId], + fragmentMessageIds: [fragmentMessageId] }); // when await markFragmentAsReceivedAndCreateItsParts(fragmentMessageId, conversationId, [ - nestedFragmentMessageId, + nestedFragmentMessageId ]); // then @@ -104,19 +104,19 @@ describe('ehr-fragment-repository', () => { await createCore({ conversationId, messageId: ehrMessageId, - fragmentMessageIds: [fragmentMessageId], + fragmentMessageIds: [fragmentMessageId] }); const nestedFragmentArrivedEarly = buildFragment({ inboundConversationId: conversationId, - fragmentMessageId: nestedFragmentMessageId, + fragmentMessageId: nestedFragmentMessageId }); const db = EhrTransferTracker.getInstance(); await db.writeItemsInTransaction([nestedFragmentArrivedEarly]); // when await markFragmentAsReceivedAndCreateItsParts(fragmentMessageId, conversationId, [ - nestedFragmentMessageId, + nestedFragmentMessageId ]); // then @@ -133,7 +133,7 @@ describe('ehr-fragment-repository', () => { const fragment = buildFragment({ inboundConversationId: conversationId, - fragmentMessageId: messageId, + fragmentMessageId: messageId }); const db = EhrTransferTracker.getInstance(); await db.writeItemsInTransaction([fragment]); diff --git a/src/services/database/dynamo-ehr-transfer-tracker.js b/src/services/database/dynamo-ehr-transfer-tracker.js index 09f7a6e7..ad826000 100644 --- a/src/services/database/dynamo-ehr-transfer-tracker.js +++ b/src/services/database/dynamo-ehr-transfer-tracker.js @@ -1,7 +1,7 @@ import { TransactWriteCommand, QueryCommand, GetCommand } from '@aws-sdk/lib-dynamodb'; import chunk from 'lodash.chunk'; -import { logError, logInfo, logWarning } from "../../middleware/logging"; +import { logError, logInfo, logWarning } from '../../middleware/logging'; import { RecordType } from '../../models/enums'; import { getDynamodbClient } from './dynamodb-client'; import { IS_IN_LOCAL } from '../../utilities/integration-test-utilities'; @@ -55,7 +55,7 @@ export class EhrTransferTracker { for (const batch of splitItemBy100) { const command = new TransactWriteCommand({ - TransactItems: batch.map(item => ({ + TransactItems: batch.map((item) => ({ Put: { TableName: this.tableName, Item: item @@ -84,7 +84,7 @@ export class EhrTransferTracker { for (const batch of splitItemBy100) { logInfo(`Updating dynamodb record with params: ${JSON.stringify(batch)}`); const command = new TransactWriteCommand({ - TransactItems: batch.map(params => ({ + TransactItems: batch.map((params) => ({ Update: { TableName: this.tableName, ...params @@ -95,17 +95,17 @@ export class EhrTransferTracker { } } - async queryTableByNhsNumber(nhsNumber, includeDeletedRecord = false) { + async queryTableByNhsNumber(nhsNumber, includeDeletedRecord = false) { const params = { TableName: this.tableName, IndexName: 'NhsNumberSecondaryIndex', ExpressionAttributeValues: { - ':nhsNumber': nhsNumber, + ':nhsNumber': nhsNumber }, ExpressionAttributeNames: { - '#NhsNumber': 'NhsNumber', + '#NhsNumber': 'NhsNumber' }, - KeyConditionExpression: '#NhsNumber = :nhsNumber', + KeyConditionExpression: '#NhsNumber = :nhsNumber' }; if (!includeDeletedRecord) { params.FilterExpression = 'attribute_not_exists(DeletedAt)'; @@ -129,12 +129,12 @@ export class EhrTransferTracker { const params = { TableName: this.tableName, ExpressionAttributeNames: { - '#PrimaryKey': 'InboundConversationId', + '#PrimaryKey': 'InboundConversationId' }, ExpressionAttributeValues: { - ':InboundConversationId': inboundConversationId, + ':InboundConversationId': inboundConversationId }, - KeyConditionExpression: '#PrimaryKey = :InboundConversationId', + KeyConditionExpression: '#PrimaryKey = :InboundConversationId' }; if (!includeDeletedRecord) { params.FilterExpression = 'attribute_not_exists(DeletedAt)'; @@ -175,13 +175,14 @@ export class EhrTransferTracker { throw new Error('must be called with both inboundConversationId and inboundMessageId'); } - const sortKey = recordType === RecordType.FRAGMENT ? `${recordType}#${inboundMessageId}` : recordType; + const sortKey = + recordType === RecordType.FRAGMENT ? `${recordType}#${inboundMessageId}` : recordType; const command = new GetCommand({ TableName: this.tableName, Key: { InboundConversationId: inboundConversationId, - Layer: sortKey, - }, + Layer: sortKey + } }); const response = await this.client.send(command); diff --git a/src/services/database/ehr-conversation-repository.js b/src/services/database/ehr-conversation-repository.js index 2808ef9a..cdc893d1 100644 --- a/src/services/database/ehr-conversation-repository.js +++ b/src/services/database/ehr-conversation-repository.js @@ -54,7 +54,7 @@ export const updateConversationCompleteness = async (conversationId) => { logInfo('All fragments are received. Will mark this inbound conversation as complete'); const updateParam = buildConversationUpdateParams(conversationId, { - TransferStatus: ConversationStatus.COMPLETE, + TransferStatus: ConversationStatus.COMPLETE }); await db.updateItemsInTransaction([updateParam]); diff --git a/src/services/database/ehr-core-repository.js b/src/services/database/ehr-core-repository.js index 9fe7c6c2..e4f9684f 100644 --- a/src/services/database/ehr-core-repository.js +++ b/src/services/database/ehr-core-repository.js @@ -13,7 +13,7 @@ export const createCore = async ({ conversationId, messageId, fragmentMessageIds const directFragments = buildMultipleFragments({ inboundConversationId: conversationId, fragmentMessageIds, - parentMessageId: messageId, + parentMessageId: messageId }); itemsToWrite.push(...directFragments); } diff --git a/src/services/database/ehr-fragment-repository.js b/src/services/database/ehr-fragment-repository.js index 250b3837..b89e00fd 100644 --- a/src/services/database/ehr-fragment-repository.js +++ b/src/services/database/ehr-fragment-repository.js @@ -15,7 +15,7 @@ export const markFragmentAsReceivedAndCreateItsParts = async ( const currentFragmentParams = buildFragmentUpdateParams(conversationId, messageId, { ReceivedAt: timestamp, - TransferStatus: FragmentStatus.COMPLETE, + TransferStatus: FragmentStatus.COMPLETE }); const childFragmentsParams = remainingPartsIds.map((fragmentPartId) => { diff --git a/src/services/health-check/__tests__/get-health-check.test.js b/src/services/health-check/__tests__/get-health-check.test.js index 9ebb6f9e..38bf6e13 100644 --- a/src/services/health-check/__tests__/get-health-check.test.js +++ b/src/services/health-check/__tests__/get-health-check.test.js @@ -14,7 +14,7 @@ describe('getHealthCheck', () => { beforeEach(() => { S3.mockImplementation(() => ({ putObject: mockPutObject, - headBucket: mockHeadBucket, + headBucket: mockHeadBucket })); }); @@ -28,7 +28,7 @@ describe('getHealthCheck', () => { type: 's3', bucketName: config.awsS3BucketName, available: true, - writable: true, + writable: true }); }); }); @@ -44,7 +44,7 @@ describe('getHealthCheck', () => { bucketName: config.awsS3BucketName, available: true, writable: false, - error: error, + error: error }); }); }); @@ -60,7 +60,7 @@ describe('getHealthCheck', () => { bucketName: config.awsS3BucketName, available: false, writable: false, - error: error, + error: error }); }); }); diff --git a/src/services/health-check/get-health-check.js b/src/services/health-check/get-health-check.js index d763e097..2a82979c 100644 --- a/src/services/health-check/get-health-check.js +++ b/src/services/health-check/get-health-check.js @@ -15,8 +15,8 @@ export function getHealthCheck() { description: 'Health of EHR Repo service', nhsEnvironment: config.nhsEnvironment, details: { - filestore: s3HealthCheckResult, - }, + filestore: s3HealthCheckResult + } }; }); } diff --git a/src/services/storage/__tests__/get-signed-url.test.js b/src/services/storage/__tests__/get-signed-url.test.js index 858ab595..bfa053d7 100644 --- a/src/services/storage/__tests__/get-signed-url.test.js +++ b/src/services/storage/__tests__/get-signed-url.test.js @@ -10,7 +10,7 @@ describe('getSignedUrl', () => { it('should return presigned url from s3 for storing ehr', async () => { const mockGetSignedUrlPromise = jest.fn().mockResolvedValue('some-url'); S3.mockImplementation(() => ({ - getSignedUrlPromise: mockGetSignedUrlPromise, + getSignedUrlPromise: mockGetSignedUrlPromise })); const url = await getSignedUrl(conversationId, messageId, operation); @@ -25,7 +25,7 @@ describe('getSignedUrl', () => { const mockGetSignedUrlPromise = jest.fn(); S3.mockImplementation(() => ({ - getSignedUrlPromise: mockGetSignedUrlPromise, + getSignedUrlPromise: mockGetSignedUrlPromise })); await getSignedUrl(conversationId, messageId, 'getObject'); diff --git a/src/services/storage/__tests__/s3.integration.test.js b/src/services/storage/__tests__/s3.integration.test.js index e2c9a525..fcad48cf 100644 --- a/src/services/storage/__tests__/s3.integration.test.js +++ b/src/services/storage/__tests__/s3.integration.test.js @@ -13,7 +13,7 @@ describe('S3Service integration test with localstack', () => { const getObjectByName = (filename) => { const getObjectParams = { Bucket: S3CLIENT.Bucket, - Key: filename, + Key: filename }; return S3CLIENT.s3.getObject(getObjectParams).promise(); }; @@ -28,7 +28,7 @@ describe('S3Service integration test with localstack', () => { available: true, bucketName: 'test-bucket', type: 's3', - writable: true, + writable: true }); }); @@ -54,7 +54,7 @@ describe('S3Service integration test with localstack', () => { ebXML: 'ebXML', payload: 'payload', attachments: [], - external_attachments: [], + external_attachments: [] }; it('return a presigned url for upload when operation = putObject', async () => { diff --git a/src/services/storage/__tests__/s3.test.js b/src/services/storage/__tests__/s3.test.js index 14f9b255..b9c39105 100644 --- a/src/services/storage/__tests__/s3.test.js +++ b/src/services/storage/__tests__/s3.test.js @@ -19,13 +19,13 @@ describe('S3Service', () => { type: 's3', bucketName: config.awsS3BucketName, available: false, - writable: false, + writable: false }; beforeEach(() => { S3.mockImplementation(() => ({ putObject: mockPutObject, - headBucket: mockHeadBucket, + headBucket: mockHeadBucket })); }); @@ -36,7 +36,7 @@ describe('S3Service', () => { expect(result).toStrictEqual({ ...expectedResultBase, available: true, - writable: true, + writable: true }); }); }); @@ -48,7 +48,7 @@ describe('S3Service', () => { expect(result).toStrictEqual({ ...expectedResultBase, error: error, - available: true, + available: true }); }); }); @@ -59,7 +59,7 @@ describe('S3Service', () => { return new S3Service().checkS3Health().then((result) => { expect(result).toStrictEqual({ ...expectedResultBase, - error: 'some-error', + error: 'some-error' }); }); }); diff --git a/src/services/storage/s3.js b/src/services/storage/s3.js index cc181294..1f3c8e93 100644 --- a/src/services/storage/s3.js +++ b/src/services/storage/s3.js @@ -17,7 +17,7 @@ export default class S3Service { type: 's3', bucketName: config.awsS3BucketName, available: true, - writable: false, + writable: false }; const date = dayjs().format('YYYY-MM-DD HH:mm:ss'); @@ -34,7 +34,7 @@ export default class S3Service { const params = { Bucket: config.awsS3BucketName, Key: filename, - Body: data, + Body: data }; return this.s3.putObject(params).promise(); } @@ -43,7 +43,7 @@ export default class S3Service { const params = { Bucket: this.Bucket, Key: filename, - Expires: URL_EXPIRY_TIME, + Expires: URL_EXPIRY_TIME }; if (operation === 'putObject') { @@ -57,7 +57,7 @@ export default class S3Service { return new Promise((resolve, reject) => { this.s3.headBucket( { - Bucket: config.awsS3BucketName, + Bucket: config.awsS3BucketName }, (err) => { if (err) reject(err); @@ -73,7 +73,7 @@ export default class S3Service { accessKeyId: 'test-access-key', secretAccessKey: 'test-secret-key', endpoint: new Endpoint(config.localstackUrl), - s3ForcePathStyle: true, + s3ForcePathStyle: true }; } diff --git a/src/utilities/dynamodb-helper.js b/src/utilities/dynamodb-helper.js index 34038642..ea45e223 100644 --- a/src/utilities/dynamodb-helper.js +++ b/src/utilities/dynamodb-helper.js @@ -33,12 +33,12 @@ export const buildSoftDeleteUpdateParams = (item) => { return { Key: { InboundConversationId: item.InboundConversationId, - Layer: item.Layer, + Layer: item.Layer }, UpdateExpression: `set UpdatedAt = :now, DeletedAt = :deletedAt`, ExpressionAttributeValues: { ':now': getUKTimestamp(), - ':deletedAt': getEpochTimeInSecond(eightWeeksAfter), - }, + ':deletedAt': getEpochTimeInSecond(eightWeeksAfter) + } }; }; diff --git a/test/docker/health.test.js b/test/docker/health.test.js index 165ebc6e..6edfd465 100644 --- a/test/docker/health.test.js +++ b/test/docker/health.test.js @@ -12,9 +12,9 @@ describe('GET /health', () => { details: expect.objectContaining({ filestore: expect.objectContaining({ available: true, - writable: true, - }), - }), + writable: true + }) + }) }) ); }); diff --git a/test/performance/ehr-with-100s-small-fragments.test.js b/test/performance/ehr-with-100s-small-fragments.test.js index 2394b781..fb627788 100644 --- a/test/performance/ehr-with-100s-small-fragments.test.js +++ b/test/performance/ehr-with-100s-small-fragments.test.js @@ -12,14 +12,14 @@ async function sendFragment(id, conversationId, fragmentMessageIds) { attributes: { conversationId, messageType: 'fragment', - fragmentMessageIds, - }, - }, + fragmentMessageIds + } + } }; const response = await axios.post(`${process.env.SERVICE_URL}/messages`, fragment, { adapter, - headers, + headers }); // Assert 201 for each fragment expect(response.status).toEqual(201); @@ -34,14 +34,14 @@ async function sendEhrExtract(ehrExtractMessageId, conversationId, nhsNumber, fr conversationId, nhsNumber, messageType: 'ehrExtract', - fragmentMessageIds: fragmentMessageIds, - }, - }, + fragmentMessageIds: fragmentMessageIds + } + } }; const ehrResponse = await axios.post(`${process.env.SERVICE_URL}/messages`, ehrExtract, { adapter, - headers, + headers }); expect(ehrResponse.status).toEqual(201); @@ -92,7 +92,7 @@ const testPerformance = async ( `${process.env.SERVICE_URL}/patients/${nhsNumber}/health-records/${conversationId}`, { headers, - adapter, + adapter } );