Skip to content

Commit

Permalink
feat(DTFS2-7080): update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MarRobSoftwire committed Apr 4, 2024
1 parent 3477ffa commit 53ff85e
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 24 deletions.
2 changes: 1 addition & 1 deletion e2e-tests/gef/cypress/support/commands/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ const addUnderwriterCommentToTfm = (dealId, underwriterComment) =>
.request({
url: `${centralApiUrl()}/v1/tfm/deals/${dealId}`,
method: 'put',
body: { dealUpdate: underwriterComment, user: UNDERWRITER_1_WITH_MOCK_ID },
body: { dealUpdate: underwriterComment, userInformation: { userType: 'tfm', id: UNDERWRITER_1_WITH_MOCK_ID._id } },
headers,
})
.then((resp) => {
Expand Down
2 changes: 1 addition & 1 deletion e2e-tests/tfm/cypress/support/central-api/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ module.exports.updateTFMDeal = (dealId, dealUpdate) =>
method: 'PUT',
body: {
dealUpdate,
user: UNDERWRITER_1_WITH_MOCK_ID,
userInformation: { userType: 'tfm', id: UNDERWRITER_1_WITH_MOCK_ID._id },
},
headers,
}).then((resp) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const api = require('../../../src/v1/api');
const updateFacilityAmendment = require('../utils/updateFacilityAmendment.util');
const MOCK_GEF_AIN_DEAL = require('../../../src/v1/__mocks__/mock-TFM-deal-AIN-submitted');
const { mockUpdateDeal } = require('../../../src/v1/__mocks__/common-api-mocks');
const MOCK_USERS = require('../../../src/v1/__mocks__/mock-users');

describe('update tfm-deals on amendment completion', () => {
const mockAmendment = {
Expand Down Expand Up @@ -38,7 +39,7 @@ describe('update tfm-deals on amendment completion', () => {

it('updateTFMDealLastUpdated() - should update lastUpdated to now when dealId exists', async () => {
mockUpdateDeal();
const result = await amendmentController.updateTFMDealLastUpdated(mockAmendment.dealId, mockAmendment.facilityId);
const result = await amendmentController.updateTFMDealLastUpdated(mockAmendment.dealId, mockAmendment.facilityId, MOCK_USERS[0]);

const expected = format(new Date(), 'dd/MM/yyyy');
const expectedResult = format(result.tfm.lastUpdated, 'dd/MM/yyyy');
Expand All @@ -47,7 +48,7 @@ describe('update tfm-deals on amendment completion', () => {

it('updateTFMDealLastUpdated() - should return null when dealId is null', async () => {
mockAmendment.dealId = null;
const result = await amendmentController.updateTFMDealLastUpdated(mockAmendment.dealId, mockAmendment.facilityId);
const result = await amendmentController.updateTFMDealLastUpdated(mockAmendment.dealId, mockAmendment.facilityId, MOCK_USERS[0]);

expect(result).toBeNull();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ describe('/v1/deals', () => {
partyUrn: '',
},
},
tasks: createDealTasks(body),
tasks: createDealTasks(body, MOCK_PORTAL_USERS[0]),
},
};

Expand All @@ -139,7 +139,7 @@ describe('/v1/deals', () => {
partyUrn: '',
},
},
tasks: createDealTasks(body),
tasks: createDealTasks(body, MOCK_PORTAL_USERS[0]),
},
};

Expand All @@ -161,7 +161,7 @@ describe('/v1/deals', () => {
partyUrn: 'testPartyUrn',
},
},
tasks: createDealTasks(body),
tasks: createDealTasks(body, MOCK_PORTAL_USERS[0]),
},
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const MOCK_DEAL_MIA_SUBMITTED = require('../../../src/v1/__mocks__/mock-deal-MIA

const MOCK_NOTIFY_EMAIL_RESPONSE = require('../../../src/v1/__mocks__/mock-notify-email-response');
const MOCK_TEAMS = require('../../../src/v1/__mocks__/mock-teams');
const { MOCK_PORTAL_USERS } = require('../../../src/v1/__mocks__/mock-portal-users');

const sendEmailApiSpy = jest.fn(() => Promise.resolve(MOCK_NOTIFY_EMAIL_RESPONSE));

Expand Down Expand Up @@ -59,7 +60,7 @@ describe('/v1/deals', () => {

expect(status).toEqual(200);

const taskCreation = await createDealTasks(submittedDeal);
const taskCreation = await createDealTasks(submittedDeal, MOCK_PORTAL_USERS[0]);

const expected = taskCreation.tfm.tasks;
expected[0].groupTasks[0].emailSent = true;
Expand Down Expand Up @@ -102,7 +103,7 @@ describe('/v1/deals', () => {

expect(status).toEqual(200);

const taskCreation = await createDealTasks(submittedDeal);
const taskCreation = await createDealTasks(submittedDeal, MOCK_PORTAL_USERS[0]);

const expected = taskCreation.tfm.tasks;
expected[0].groupTasks[0].emailSent = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ const ALL_MOCK_DEALS = require('../mock-deals');

module.exports = {
mockUpdateDeal: (mockDealToReturn = undefined) => {
api.updateDeal.mockImplementation(({ dealId, dealUpdate: updatedTfmDealData }) => {
api.updateDeal.mockImplementation(({ dealId, dealUpdate }) => {
let deal = mockDealToReturn || ALL_MOCK_DEALS.find((d) => d._id === dealId);

// if stage is updated, add to the mock deal.
if (updatedTfmDealData.tfm?.stage) {
if (dealUpdate.tfm?.stage) {
deal = {
...deal,
tfm: {
...updatedTfmDealData.tfm,
tasks: updatedTfmDealData.tfm.tasks,
...dealUpdate.tfm,
tasks: dealUpdate.tfm.tasks,
},
};
if (!mockDealToReturn) {
Expand All @@ -25,7 +25,7 @@ module.exports = {
dealSnapshot: {
...deal,
},
...updatedTfmDealData,
...dealUpdate,
};
});
},
Expand Down
20 changes: 10 additions & 10 deletions trade-finance-manager-api/src/v1/controllers/tasks.api-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ describe('tasks controller', () => {
};

it('should return the updated task', async () => {
const result = await updateTfmTask({ dealId: updatableTaskDealId, groupId, taskId: updatableTaskId, taskUpdate: updatableTaskUpdateDone });
const result = await updateTfmTask({ dealId: updatableTaskDealId, groupId, taskId: updatableTaskId, taskUpdate: updatableTaskUpdateDone, sessionTfmUser: MOCK_USERS[0] });

const expectedUpdatedTask = {
id: updatableTaskId,
Expand Down Expand Up @@ -371,7 +371,7 @@ describe('tasks controller', () => {
api.findOneDeal = findOneDealMock;

await expect(
updateTfmTask({ dealId: updatableTaskDealId, groupId, taskId: updatableTaskId, taskUpdate: updatableTaskUpdateToDo }),
updateTfmTask({ dealId: updatableTaskDealId, groupId, taskId: updatableTaskId, taskUpdate: updatableTaskUpdateToDo, sessionTfmUser: MOCK_USERS[0] }),
).rejects.toThrowError(`Deal not found ${updatableTaskDealId}`);
});
});
Expand All @@ -381,7 +381,7 @@ describe('tasks controller', () => {
const nonExistantGroupId = 567;

await expect(
updateTfmTask({ dealId: updatableTaskDealId, groupId: nonExistantGroupId, taskId: updatableTaskId, taskUpdate: updatableTaskUpdateToDo }),
updateTfmTask({ dealId: updatableTaskDealId, groupId: nonExistantGroupId, taskId: updatableTaskId, taskUpdate: updatableTaskUpdateToDo, sessionTfmUser: MOCK_USERS[0] }),
).rejects.toThrowError(`Group not found ${nonExistantGroupId}`);
});
});
Expand All @@ -391,22 +391,22 @@ describe('tasks controller', () => {
const nonExistantTaskId = 789;

await expect(
updateTfmTask({ dealId: updatableTaskDealId, groupId, taskId: nonExistantTaskId, taskUpdate: updatableTaskUpdateToDo }),
updateTfmTask({ dealId: updatableTaskDealId, groupId, taskId: nonExistantTaskId, taskUpdate: updatableTaskUpdateToDo, sessionTfmUser: MOCK_USERS[0] }),
).rejects.toThrowError(`Task not found ${nonExistantTaskId}`);
});
});

describe('when task cannot be updated', () => {
it('should return the original task', async () => {
const result = await updateTfmTask({ dealId: unUpdateableTaskDealId, groupId, taskId: unUpdateableTaskId, taskUpdate: unUpdateableTaskUpdate });
const result = await updateTfmTask({ dealId: unUpdateableTaskDealId, groupId, taskId: unUpdateableTaskId, taskUpdate: unUpdateableTaskUpdate, sessionTfmUser: MOCK_USERS[0] });

expect(result).toEqual(unUpdateableTask);
});
});

describe('when an MIA deal has the first task in the first group completed immediately', () => {
it('should update deal.tfm.stage to `In progress`', async () => {
await updateTfmTask({ dealId: updatableTaskDealId, groupId, taskId: updatableTaskId, taskUpdate: updatableTaskUpdateDone });
await updateTfmTask({ dealId: updatableTaskDealId, groupId, taskId: updatableTaskId, taskUpdate: updatableTaskUpdateDone, sessionTfmUser: MOCK_USERS[0] });

const deal = await api.findOneDeal(updatableTaskDealId);

Expand All @@ -416,21 +416,21 @@ describe('tasks controller', () => {

describe('when an MIA deal has the first task in the first group completed after being `In progress`', () => {
it('should update deal.tfm.stage to `In progress`', async () => {
await updateTfmTask({ dealId: updatableTaskDealId, groupId, taskId: updatableTaskId, taskUpdate: updatableTaskUpdateToDo });
await updateTfmTask({ dealId: updatableTaskDealId, groupId, taskId: updatableTaskId, taskUpdate: updatableTaskUpdateToDo, sessionTfmUser: MOCK_USERS[0] });

await api.resetDealForApiTest(updatableTaskDealId);

const initialDeal = await api.findOneDeal(updatableTaskDealId);

expect(initialDeal.tfm.stage).toBeUndefined();

await updateTfmTask({ dealId: updatableTaskDealId, groupId, taskId: updatableTaskId, taskUpdate: updatableTaskUpdateInProgress });
await updateTfmTask({ dealId: updatableTaskDealId, groupId, taskId: updatableTaskId, taskUpdate: updatableTaskUpdateInProgress, sessionTfmUser: MOCK_USERS[0] });

const dealAfterFirstUpdate = await api.findOneDeal(updatableTaskDealId);

expect(dealAfterFirstUpdate.tfm.stage).toEqual('In progress');

await updateTfmTask({ dealId: updatableTaskDealId, groupId, taskId: updatableTaskId, taskUpdate: updatableTaskUpdateDone });
await updateTfmTask({ dealId: updatableTaskDealId, groupId, taskId: updatableTaskId, taskUpdate: updatableTaskUpdateDone, sessionTfmUser: MOCK_USERS[0] });

const dealAfterSecondUpdate = await api.findOneDeal(updatableTaskDealId);

Expand All @@ -452,7 +452,7 @@ describe('tasks controller', () => {

const tfmTaskUpdate = createTaskUpdateObj(1, 1);

await updateTfmTask({ dealId, groupId: tfmTaskUpdate.groupId, taskId: tfmTaskUpdate.id, taskUpdate: tfmTaskUpdate });
await updateTfmTask({ dealId, groupId: tfmTaskUpdate.groupId, taskId: tfmTaskUpdate.id, taskUpdate: tfmTaskUpdate, sessionTfmUser: MOCK_USERS[0] });

const mappedTaskObj = await mapTaskObject(MOCK_AIN_TASKS[0].groupTasks[0], tfmTaskUpdate);

Expand Down

0 comments on commit 53ff85e

Please sign in to comment.