Skip to content

Commit

Permalink
[PRMT-4568] Run linter and formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
joefong-nhs committed Mar 11, 2024
1 parent 711d959 commit 5528313
Show file tree
Hide file tree
Showing 22 changed files with 70 additions and 75 deletions.
16 changes: 5 additions & 11 deletions src/__tests__/app.integration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -400,7 +398,6 @@ describe('app', () => {
});

describe('POST /messages', () => {
const db = EhrTransferTracker.getInstance();
const nhsNumber = '1234567890';
let conversationId;
let messageId;
Expand All @@ -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
Expand Down Expand Up @@ -653,7 +649,6 @@ describe('app', () => {

const timestampAfterDelete = getEpochTimeInSecond(moment().add(8, 'week'));


for (const item of softDeletedRecords) {
expect(item).toMatchObject({
InboundConversationId: inboundConversationId,
Expand All @@ -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();
Expand All @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion src/api/fragments/get-fragment-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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({}),
Expand Down
32 changes: 19 additions & 13 deletions src/api/messages/__tests__/store-message-controller.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({}),
Expand Down Expand Up @@ -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);
});

Expand All @@ -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);
});
});
Expand Down
2 changes: 1 addition & 1 deletion src/api/messages/message-location-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
12 changes: 6 additions & 6 deletions src/api/messages/store-message-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/api/patients/__tests__/delete-ehr-controller.test.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
6 changes: 3 additions & 3 deletions src/api/patients/__tests__/patient-details-controller.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion src/api/patients/delete-ehr-controller.js
Original file line number Diff line number Diff line change
@@ -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()
Expand Down
4 changes: 2 additions & 2 deletions src/api/patients/health-record-controller.js
Original file line number Diff line number Diff line change
@@ -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"),
Expand Down
2 changes: 1 addition & 1 deletion src/api/patients/patient-details-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
14 changes: 6 additions & 8 deletions src/errors/errors.js
Original file line number Diff line number Diff line change
@@ -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);
};
}
}
}
2 changes: 1 addition & 1 deletion src/middleware/__tests__/auth.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion src/models/core.js
Original file line number Diff line number Diff line change
@@ -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) => {
Expand Down
4 changes: 2 additions & 2 deletions src/models/fragment.js
Original file line number Diff line number Diff line change
@@ -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'];

Expand Down
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down
8 changes: 2 additions & 6 deletions src/services/database/dynamo-ehr-transfer-tracker.js
Original file line number Diff line number Diff line change
@@ -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 {
/**
Expand Down
2 changes: 1 addition & 1 deletion src/services/database/dynamodb-client.js
Original file line number Diff line number Diff line change
@@ -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 = {
Expand Down
6 changes: 3 additions & 3 deletions src/services/database/ehr-fragment-repository.js
Original file line number Diff line number Diff line change
@@ -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 (
Expand All @@ -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) => {
Expand Down Expand Up @@ -52,4 +52,4 @@ export const fragmentAlreadyReceived = async (conversationId, messageId) => {
logError('Querying database for fragment message failed', e);
throw e;
}
}
};
Loading

0 comments on commit 5528313

Please sign in to comment.