From 5528313ef9cccf7a41bdf97a8f49c42a549c9bfd Mon Sep 17 00:00:00 2001 From: Joe Fong Date: Mon, 11 Mar 2024 13:25:50 +0000 Subject: [PATCH] [PRMT-4568] Run linter and formatter --- src/__tests__/app.integration.test.js | 16 +++------- src/api/fragments/get-fragment-controller.js | 2 +- .../message-location-controller.test.js | 4 +-- .../store-message-controller.test.js | 32 +++++++++++-------- .../messages/message-location-controller.js | 2 +- src/api/messages/store-message-controller.js | 12 +++---- .../__tests__/delete-ehr-controller.test.js | 2 +- .../patient-details-controller.test.js | 6 ++-- src/api/patients/delete-ehr-controller.js | 2 +- src/api/patients/health-record-controller.js | 4 +-- .../patients/patient-details-controller.js | 2 +- src/errors/errors.js | 14 ++++---- src/middleware/__tests__/auth.test.js | 2 +- src/models/core.js | 2 +- src/models/fragment.js | 4 +-- ...o-ehr-transfer-tracker.integration.test.js | 2 -- ...onversation-repository.integration.test.js | 18 +++++++---- .../database/dynamo-ehr-transfer-tracker.js | 8 ++--- src/services/database/dynamodb-client.js | 2 +- .../database/ehr-fragment-repository.js | 6 ++-- src/services/time.js | 1 - src/utilities/integration-test-utilities.js | 2 +- 22 files changed, 70 insertions(+), 75 deletions(-) diff --git a/src/__tests__/app.integration.test.js b/src/__tests__/app.integration.test.js index 97209898..ab712726 100644 --- a/src/__tests__/app.integration.test.js +++ b/src/__tests__/app.integration.test.js @@ -12,12 +12,12 @@ import { createConversationForTest, } from '../utilities/integration-test-utilities'; import { getConversationById } from '../services/database/ehr-conversation-repository'; -import { ConversationStatus, MessageType, RecordType } from "../models/enums"; +import { ConversationStatus, MessageType, RecordType } from '../models/enums'; import { isCore } from '../models/core'; import { getFragmentByKey } from '../services/database/ehr-fragment-repository'; import { isFragment } from '../models/fragment'; -import { getEpochTimeInSecond, TIMESTAMP_REGEX } from "../services/time"; -import moment from "moment-timezone"; +import { getEpochTimeInSecond, TIMESTAMP_REGEX } from '../services/time'; +import moment from 'moment-timezone'; describe('app', () => { const config = initializeConfig(); @@ -85,8 +85,6 @@ describe('app', () => { const fragmentMessageId = v4(); const nhsNumber = '2345678901'; - const db = EhrTransferTracker.getInstance(); - it('should return presigned url when the fragment record exists', async () => { // setting up database const coreMessageResponse = await request(app) @@ -400,7 +398,6 @@ describe('app', () => { }); describe('POST /messages', () => { - const db = EhrTransferTracker.getInstance(); const nhsNumber = '1234567890'; let conversationId; let messageId; @@ -416,8 +413,7 @@ describe('app', () => { cleanupRecordsForTest(conversationId); }); - afterAll(async () => { - }); + afterAll(async () => {}); it('should save health record without fragments in the database and return 201', async () => { // when @@ -653,7 +649,6 @@ describe('app', () => { const timestampAfterDelete = getEpochTimeInSecond(moment().add(8, 'week')); - for (const item of softDeletedRecords) { expect(item).toMatchObject({ InboundConversationId: inboundConversationId, @@ -664,7 +659,6 @@ describe('app', () => { } }); - it('should delete all record if patient has more than one set of record in our storage', async () => { // given const inboundConversationId1 = uuid(); @@ -673,7 +667,7 @@ describe('app', () => { const coreMessageId2 = uuid(); await createCompleteRecord(nhsNumber, inboundConversationId1, coreMessageId1); - await new Promise(resolve => setTimeout(resolve, 1500)); // time buffer to ensure record 2 get a newer timestamp + await new Promise((resolve) => setTimeout(resolve, 1500)); // time buffer to ensure record 2 get a newer timestamp await createCompleteRecord(nhsNumber, inboundConversationId2, coreMessageId2); diff --git a/src/api/fragments/get-fragment-controller.js b/src/api/fragments/get-fragment-controller.js index c3577ead..b39c9a55 100644 --- a/src/api/fragments/get-fragment-controller.js +++ b/src/api/fragments/get-fragment-controller.js @@ -2,7 +2,7 @@ import { getSignedUrl } from '../../services/storage'; import { param } from 'express-validator'; import { logError, logInfo } from '../../middleware/logging'; import { setCurrentSpanAttributes } from '../../config/tracing'; -import { fragmentAlreadyReceived } from "../../services/database/ehr-fragment-repository"; +import { fragmentAlreadyReceived } from '../../services/database/ehr-fragment-repository'; export const getFragmentControllerValidation = [ param('conversationId').isUUID().withMessage("'conversationId' provided is not a UUID"), diff --git a/src/api/messages/__tests__/message-location-controller.test.js b/src/api/messages/__tests__/message-location-controller.test.js index 35bebf95..38d5ce51 100644 --- a/src/api/messages/__tests__/message-location-controller.test.js +++ b/src/api/messages/__tests__/message-location-controller.test.js @@ -4,10 +4,10 @@ import { getSignedUrl } from '../../../services/storage'; import { v4 as uuid } from 'uuid'; import { logError, logInfo } from '../../../middleware/logging'; import { initializeConfig } from '../../../config'; -import { fragmentAlreadyReceived } from "../../../services/database/ehr-fragment-repository"; +import { fragmentAlreadyReceived } from '../../../services/database/ehr-fragment-repository'; jest.mock('../../../services/storage'); -jest.mock("../../../services/database/ehr-fragment-repository"); +jest.mock('../../../services/database/ehr-fragment-repository'); jest.mock('../../../middleware/logging'); jest.mock('../../../config', () => ({ initializeConfig: jest.fn().mockReturnValue({}), diff --git a/src/api/messages/__tests__/store-message-controller.test.js b/src/api/messages/__tests__/store-message-controller.test.js index 094b0e33..60b573ea 100644 --- a/src/api/messages/__tests__/store-message-controller.test.js +++ b/src/api/messages/__tests__/store-message-controller.test.js @@ -3,20 +3,20 @@ import request from 'supertest'; import app from '../../../app'; import { initializeConfig } from '../../../config'; import { logError } from '../../../middleware/logging'; -import { MessageType } from "../../../models/enums"; +import { MessageType } from '../../../models/enums'; import { getConversationStatus, - updateConversationCompleteness -} from "../../../services/database/ehr-conversation-repository"; -import { createCore } from "../../../services/database/ehr-core-repository"; + updateConversationCompleteness, +} from '../../../services/database/ehr-conversation-repository'; +import { createCore } from '../../../services/database/ehr-core-repository'; import { fragmentExistsInRecord, - markFragmentAsReceivedAndCreateItsParts -} from "../../../services/database/ehr-fragment-repository"; + markFragmentAsReceivedAndCreateItsParts, +} from '../../../services/database/ehr-fragment-repository'; -jest.mock("../../../services/database/ehr-conversation-repository"); -jest.mock("../../../services/database/ehr-core-repository"); -jest.mock("../../../services/database/ehr-fragment-repository"); +jest.mock('../../../services/database/ehr-conversation-repository'); +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({}), @@ -83,9 +83,11 @@ describe('storeMessageController', () => { expect(res.status).toBe(201); expect(createCore).not.toHaveBeenCalled(); - expect(markFragmentAsReceivedAndCreateItsParts).toHaveBeenCalledWith(messageId, conversationId, [ - nestedFragmentId, - ]); + expect(markFragmentAsReceivedAndCreateItsParts).toHaveBeenCalledWith( + messageId, + conversationId, + [nestedFragmentId] + ); expect(updateConversationCompleteness).toHaveBeenCalledWith(conversationId); }); @@ -107,7 +109,11 @@ describe('storeMessageController', () => { expect(res.status).toBe(201); expect(fragmentExistsInRecord).toHaveBeenCalledWith(nestedFragmentId); - expect(markFragmentAsReceivedAndCreateItsParts).toHaveBeenCalledWith(nestedFragmentId, conversationId, []); + expect(markFragmentAsReceivedAndCreateItsParts).toHaveBeenCalledWith( + nestedFragmentId, + conversationId, + [] + ); expect(updateConversationCompleteness).toHaveBeenCalledWith(conversationId); }); }); diff --git a/src/api/messages/message-location-controller.js b/src/api/messages/message-location-controller.js index 52396d54..12c36f21 100644 --- a/src/api/messages/message-location-controller.js +++ b/src/api/messages/message-location-controller.js @@ -2,7 +2,7 @@ import { getSignedUrl } from '../../services/storage'; import { param } from 'express-validator'; import { logError, logInfo } from '../../middleware/logging'; import { setCurrentSpanAttributes } from '../../config/tracing'; -import { fragmentAlreadyReceived } from "../../services/database/ehr-fragment-repository"; +import { fragmentAlreadyReceived } from '../../services/database/ehr-fragment-repository'; export const messageLocationControllerValidation = [ param('conversationId').isUUID().withMessage("'conversationId' provided is not a UUID"), diff --git a/src/api/messages/store-message-controller.js b/src/api/messages/store-message-controller.js index e214a361..b03e2dcc 100644 --- a/src/api/messages/store-message-controller.js +++ b/src/api/messages/store-message-controller.js @@ -2,15 +2,15 @@ import { body } from 'express-validator'; import { MessageType } from '../../models/enums'; import { logError, logInfo, logWarning } from '../../middleware/logging'; import { setCurrentSpanAttributes } from '../../config/tracing'; -import { createCore } from "../../services/database/ehr-core-repository"; +import { createCore } from '../../services/database/ehr-core-repository'; import { fragmentExistsInRecord, - markFragmentAsReceivedAndCreateItsParts -} from "../../services/database/ehr-fragment-repository"; + markFragmentAsReceivedAndCreateItsParts, +} from '../../services/database/ehr-fragment-repository'; import { getConversationStatus, - updateConversationCompleteness -} from "../../services/database/ehr-conversation-repository"; + updateConversationCompleteness, +} from '../../services/database/ehr-conversation-repository'; export const storeMessageControllerValidation = [ body('data.type').equals('messages'), @@ -57,7 +57,7 @@ export const storeMessageController = async (req, res) => { }); } if (messageType === MessageType.FRAGMENT) { - if (!await fragmentExistsInRecord(messageId)) { + if (!(await fragmentExistsInRecord(messageId))) { logWarning( `Fragment message ${messageId} did not arrive in order. Fragment parts: ${JSON.stringify( fragmentMessageIds diff --git a/src/api/patients/__tests__/delete-ehr-controller.test.js b/src/api/patients/__tests__/delete-ehr-controller.test.js index c258c0d4..2d160a59 100644 --- a/src/api/patients/__tests__/delete-ehr-controller.test.js +++ b/src/api/patients/__tests__/delete-ehr-controller.test.js @@ -1,6 +1,6 @@ import request from 'supertest'; import app from '../../../app'; -import { markRecordAsSoftDeleteForPatient } from "../../../services/database/ehr-conversation-repository"; +import { markRecordAsSoftDeleteForPatient } from '../../../services/database/ehr-conversation-repository'; import { initializeConfig } from '../../../config'; import { logError, logWarning } from '../../../middleware/logging'; import { v4 as uuid } from 'uuid'; diff --git a/src/api/patients/__tests__/patient-details-controller.test.js b/src/api/patients/__tests__/patient-details-controller.test.js index 51f243e3..2f9fc300 100644 --- a/src/api/patients/__tests__/patient-details-controller.test.js +++ b/src/api/patients/__tests__/patient-details-controller.test.js @@ -7,9 +7,9 @@ import { logError, logInfo, logWarning } from '../../../middleware/logging'; import getSignedUrl from '../../../services/storage/get-signed-url'; import { getCurrentConversationIdForPatient, - getMessageIdsForConversation -} from "../../../services/database/ehr-conversation-repository"; -import { HealthRecordNotFoundError } from "../../../errors/errors"; + getMessageIdsForConversation, +} from '../../../services/database/ehr-conversation-repository'; +import { HealthRecordNotFoundError } from '../../../errors/errors'; jest.mock('../../../services/database/ehr-conversation-repository'); jest.mock('../../../middleware/logging'); diff --git a/src/api/patients/delete-ehr-controller.js b/src/api/patients/delete-ehr-controller.js index 98eaab1c..d859caa4 100644 --- a/src/api/patients/delete-ehr-controller.js +++ b/src/api/patients/delete-ehr-controller.js @@ -1,6 +1,6 @@ import { param } from 'express-validator'; import { logError, logInfo, logWarning } from '../../middleware/logging'; -import { markRecordAsSoftDeleteForPatient } from "../../services/database/ehr-conversation-repository"; +import { markRecordAsSoftDeleteForPatient } from '../../services/database/ehr-conversation-repository'; export const deleteEhrValidation = [ param('nhsNumber') .isNumeric() diff --git a/src/api/patients/health-record-controller.js b/src/api/patients/health-record-controller.js index ecb3939f..8219a827 100644 --- a/src/api/patients/health-record-controller.js +++ b/src/api/patients/health-record-controller.js @@ -1,7 +1,7 @@ import { param } from 'express-validator'; import { setCurrentSpanAttributes } from '../../config/tracing'; -import { HealthRecordStatus } from "../../models/enums"; -import { getConversationStatus } from "../../services/database/ehr-conversation-repository"; +import { HealthRecordStatus } from '../../models/enums'; +import { getConversationStatus } from '../../services/database/ehr-conversation-repository'; export const healthRecordControllerValidation = [ param('conversationId').isUUID().withMessage("'conversationId' provided is not a UUID"), diff --git a/src/api/patients/patient-details-controller.js b/src/api/patients/patient-details-controller.js index 2fdf4d22..7009099b 100644 --- a/src/api/patients/patient-details-controller.js +++ b/src/api/patients/patient-details-controller.js @@ -45,7 +45,7 @@ export const patientDetailsController = async (req, res) => { // TODO: remove this duplicated `conversationIdFromEhrIn` field, // after updating ehr-out to use the field name "inboundConversationId" conversationIdFromEhrIn: currentHealthRecordConversationId, - inboundConversationId: currentHealthRecordConversationId + inboundConversationId: currentHealthRecordConversationId, }; res.status(200).json(responseBody); diff --git a/src/errors/errors.js b/src/errors/errors.js index df73eda1..f1a29742 100644 --- a/src/errors/errors.js +++ b/src/errors/errors.js @@ -1,22 +1,20 @@ -import { logError } from "../middleware/logging"; +import { logError } from '../middleware/logging'; export const errorMessages = { HealthRecordNotFound: 'No complete health record was found with given criteria', - MessageNotFound: 'There were no undeleted messages associated with conversation id' -} - + MessageNotFound: 'There were no undeleted messages associated with conversation id', +}; export class HealthRecordNotFoundError extends Error { constructor(error) { super(errorMessages.HealthRecordNotFound); logError(errorMessages.HealthRecordNotFound, error); - }; + } } - export class MessageNotFoundError extends Error { constructor(error) { super(errorMessages.MessageNotFound); logError(errorMessages.MessageNotFound, error); - }; -} \ No newline at end of file + } +} diff --git a/src/middleware/__tests__/auth.test.js b/src/middleware/__tests__/auth.test.js index 9fe6c41f..0a72672d 100644 --- a/src/middleware/__tests__/auth.test.js +++ b/src/middleware/__tests__/auth.test.js @@ -3,7 +3,7 @@ import app from '../../app'; import { v4 as uuid } from 'uuid'; import { initializeConfig } from '../../config'; import { logInfo, logWarning } from '../logging'; -import { fragmentAlreadyReceived } from "../../services/database/ehr-fragment-repository"; +import { fragmentAlreadyReceived } from '../../services/database/ehr-fragment-repository'; jest.mock('../logging'); jest.mock('../../services/database/ehr-fragment-repository'); diff --git a/src/models/core.js b/src/models/core.js index b152b069..cbe61dac 100644 --- a/src/models/core.js +++ b/src/models/core.js @@ -1,5 +1,5 @@ import { getUKTimestamp } from '../services/time'; -import { CoreStatus, RecordType } from "./enums"; +import { CoreStatus, RecordType } from './enums'; import { validateIds } from '../utilities/dynamodb-helper'; export const buildCore = (inboundConversationId, messageId) => { diff --git a/src/models/fragment.js b/src/models/fragment.js index a524cf6d..1ab5ea43 100644 --- a/src/models/fragment.js +++ b/src/models/fragment.js @@ -1,6 +1,6 @@ import { getUKTimestamp } from '../services/time'; -import { addChangesToUpdateParams, validateIds } from "../utilities/dynamodb-helper"; -import { RecordType } from "./enums"; +import { addChangesToUpdateParams, validateIds } from '../utilities/dynamodb-helper'; +import { RecordType } from './enums'; const fieldsAllowedToUpdate = ['TransferStatus', 'ParentId', 'ReceivedAt', 'DeletedAt']; diff --git a/src/services/database/__tests__/dynamo-ehr-transfer-tracker.integration.test.js b/src/services/database/__tests__/dynamo-ehr-transfer-tracker.integration.test.js index 11fe2f78..92ac7342 100644 --- a/src/services/database/__tests__/dynamo-ehr-transfer-tracker.integration.test.js +++ b/src/services/database/__tests__/dynamo-ehr-transfer-tracker.integration.test.js @@ -1,12 +1,10 @@ import { EhrTransferTracker } from '../dynamo-ehr-transfer-tracker'; import { v4 as uuid } from 'uuid'; import { RecordType } from '../../../models/enums'; -import { createCore } from '../ehr-core-repository'; import { cleanupRecordsForTest, createConversationForTest, } from '../../../utilities/integration-test-utilities'; -import { markFragmentAsReceivedAndCreateItsParts } from '../ehr-fragment-repository'; import { buildCore } from '../../../models/core'; describe('EhrTransferTracker', () => { 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 12e9c5c7..438be114 100644 --- a/src/services/database/__tests__/ehr-conversation-repository.integration.test.js +++ b/src/services/database/__tests__/ehr-conversation-repository.integration.test.js @@ -15,13 +15,11 @@ import { } from '../../../utilities/integration-test-utilities'; import { createCore } from '../ehr-core-repository'; import { EhrTransferTracker } from '../dynamo-ehr-transfer-tracker'; -import { - markFragmentAsReceivedAndCreateItsParts, -} from '../ehr-fragment-repository'; +import { markFragmentAsReceivedAndCreateItsParts } from '../ehr-fragment-repository'; import { HealthRecordNotFoundError, MessageNotFoundError } from '../../../errors/errors'; import { buildCore } from '../../../models/core'; import { getEpochTimeInSecond } from '../../time'; -import moment from "moment-timezone"; +import moment from 'moment-timezone'; jest.mock('../../../middleware/logging'); @@ -274,7 +272,9 @@ describe('ehr-conversation-repository', () => { await createCore({ conversationId, messageId, fragmentMessageIds: [] }); // when - const { coreMessageId, fragmentMessageIds } = await getMessageIdsForConversation(conversationId); + const { coreMessageId, fragmentMessageIds } = await getMessageIdsForConversation( + conversationId + ); // then expect(coreMessageId).toEqual(messageId); @@ -291,7 +291,9 @@ describe('ehr-conversation-repository', () => { await markFragmentAsReceived(fragmentMessageId, conversationId); // when - const { coreMessageId, fragmentMessageIds } = await getMessageIdsForConversation(conversationId); + const { coreMessageId, fragmentMessageIds } = await getMessageIdsForConversation( + conversationId + ); // then expect(coreMessageId).toEqual(messageId); @@ -312,7 +314,9 @@ describe('ehr-conversation-repository', () => { await markFragmentAsReceived(nestedFragmentId, conversationId); // when - const { coreMessageId, fragmentMessageIds } = await getMessageIdsForConversation(conversationId); + const { coreMessageId, fragmentMessageIds } = await getMessageIdsForConversation( + conversationId + ); // then expect(coreMessageId).toEqual(messageId); diff --git a/src/services/database/dynamo-ehr-transfer-tracker.js b/src/services/database/dynamo-ehr-transfer-tracker.js index 6c6b008f..75b24e20 100644 --- a/src/services/database/dynamo-ehr-transfer-tracker.js +++ b/src/services/database/dynamo-ehr-transfer-tracker.js @@ -1,13 +1,9 @@ -import { - TransactWriteCommand, - QueryCommand, - GetCommand, -} from '@aws-sdk/lib-dynamodb'; +import { TransactWriteCommand, QueryCommand, GetCommand } from '@aws-sdk/lib-dynamodb'; import { logError, logInfo } from '../../middleware/logging'; import { RecordType } from '../../models/enums'; import { getDynamodbClient } from './dynamodb-client'; -import { IS_IN_LOCAL } from "../../utilities/integration-test-utilities"; +import { IS_IN_LOCAL } from '../../utilities/integration-test-utilities'; export class EhrTransferTracker { /** diff --git a/src/services/database/dynamodb-client.js b/src/services/database/dynamodb-client.js index df0eaec2..42c9e870 100644 --- a/src/services/database/dynamodb-client.js +++ b/src/services/database/dynamodb-client.js @@ -1,6 +1,6 @@ import { DynamoDBClient } from '@aws-sdk/client-dynamodb'; import { DynamoDBDocumentClient } from '@aws-sdk/lib-dynamodb'; -import { IS_IN_LOCAL } from "../../utilities/integration-test-utilities"; +import { IS_IN_LOCAL } from '../../utilities/integration-test-utilities'; export const getDynamodbClient = () => { const clientConfig = { diff --git a/src/services/database/ehr-fragment-repository.js b/src/services/database/ehr-fragment-repository.js index 37a14f73..250b3837 100644 --- a/src/services/database/ehr-fragment-repository.js +++ b/src/services/database/ehr-fragment-repository.js @@ -1,7 +1,7 @@ import { getUKTimestamp } from '../time'; import { EhrTransferTracker } from './dynamo-ehr-transfer-tracker'; import { buildFragmentUpdateParams } from '../../models/fragment'; -import { FragmentStatus, RecordType } from "../../models/enums"; +import { FragmentStatus, RecordType } from '../../models/enums'; import { logError } from '../../middleware/logging'; export const markFragmentAsReceivedAndCreateItsParts = async ( @@ -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) => { @@ -52,4 +52,4 @@ export const fragmentAlreadyReceived = async (conversationId, messageId) => { logError('Querying database for fragment message failed', e); throw e; } -} +}; diff --git a/src/services/time.js b/src/services/time.js index 149d45fe..bf86806a 100644 --- a/src/services/time.js +++ b/src/services/time.js @@ -10,4 +10,3 @@ export const TIMESTAMP_REGEX = /\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\+\d{2}:00/; export const getEpochTimeInSecond = (datetime) => { return moment(datetime).unix(); }; - diff --git a/src/utilities/integration-test-utilities.js b/src/utilities/integration-test-utilities.js index b927e358..f656e548 100644 --- a/src/utilities/integration-test-utilities.js +++ b/src/utilities/integration-test-utilities.js @@ -71,4 +71,4 @@ export const cleanupRecordsForTestByNhsNumber = async (nhsNumber) => { return Promise.all(removeAllRecords); }; -export const IS_IN_LOCAL = process.env.NHS_ENVIRONMENT === 'local' || !process.env.NHS_ENVIRONMENT; \ No newline at end of file +export const IS_IN_LOCAL = process.env.NHS_ENVIRONMENT === 'local' || !process.env.NHS_ENVIRONMENT;