diff --git a/e2e-tests/gef/cypress/support/commands/api.js b/e2e-tests/gef/cypress/support/commands/api.js index 5f0803b205c..fd849324cb4 100644 --- a/e2e-tests/gef/cypress/support/commands/api.js +++ b/e2e-tests/gef/cypress/support/commands/api.js @@ -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) => { diff --git a/e2e-tests/tfm/cypress/support/central-api/api.js b/e2e-tests/tfm/cypress/support/central-api/api.js index 2bd5811a7a0..bb8fa58a082 100644 --- a/e2e-tests/tfm/cypress/support/central-api/api.js +++ b/e2e-tests/tfm/cypress/support/central-api/api.js @@ -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) => { diff --git a/trade-finance-manager-api/api-tests/v1/amendments/update-tfm-deal-amendment-completion.api-test.js b/trade-finance-manager-api/api-tests/v1/amendments/update-tfm-deal-amendment-completion.api-test.js index fe411279f57..936940cada8 100644 --- a/trade-finance-manager-api/api-tests/v1/amendments/update-tfm-deal-amendment-completion.api-test.js +++ b/trade-finance-manager-api/api-tests/v1/amendments/update-tfm-deal-amendment-completion.api-test.js @@ -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 = { @@ -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'); @@ -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(); }); diff --git a/trade-finance-manager-api/api-tests/v1/deals/deals-submit.api-test.js b/trade-finance-manager-api/api-tests/v1/deals/deals-submit.api-test.js index d86745280ed..d011fece535 100644 --- a/trade-finance-manager-api/api-tests/v1/deals/deals-submit.api-test.js +++ b/trade-finance-manager-api/api-tests/v1/deals/deals-submit.api-test.js @@ -118,7 +118,7 @@ describe('/v1/deals', () => { partyUrn: '', }, }, - tasks: createDealTasks(body), + tasks: createDealTasks(body, MOCK_PORTAL_USERS[0]), }, }; @@ -139,7 +139,7 @@ describe('/v1/deals', () => { partyUrn: '', }, }, - tasks: createDealTasks(body), + tasks: createDealTasks(body, MOCK_PORTAL_USERS[0]), }, }; @@ -161,7 +161,7 @@ describe('/v1/deals', () => { partyUrn: 'testPartyUrn', }, }, - tasks: createDealTasks(body), + tasks: createDealTasks(body, MOCK_PORTAL_USERS[0]), }, }; diff --git a/trade-finance-manager-api/api-tests/v1/deals/deals-submit.tasks.api-test.js b/trade-finance-manager-api/api-tests/v1/deals/deals-submit.tasks.api-test.js index ea3783bb8cc..0cb301fa5e2 100644 --- a/trade-finance-manager-api/api-tests/v1/deals/deals-submit.tasks.api-test.js +++ b/trade-finance-manager-api/api-tests/v1/deals/deals-submit.tasks.api-test.js @@ -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)); @@ -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; @@ -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; diff --git a/trade-finance-manager-api/src/v1/__mocks__/common-api-mocks/update-deal.js b/trade-finance-manager-api/src/v1/__mocks__/common-api-mocks/update-deal.js index e344bf60288..1fb33ade502 100644 --- a/trade-finance-manager-api/src/v1/__mocks__/common-api-mocks/update-deal.js +++ b/trade-finance-manager-api/src/v1/__mocks__/common-api-mocks/update-deal.js @@ -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) { @@ -25,7 +25,7 @@ module.exports = { dealSnapshot: { ...deal, }, - ...updatedTfmDealData, + ...dealUpdate, }; }); }, diff --git a/trade-finance-manager-api/src/v1/controllers/tasks.api-test.js b/trade-finance-manager-api/src/v1/controllers/tasks.api-test.js index 106a2c566a2..4cb12c78882 100644 --- a/trade-finance-manager-api/src/v1/controllers/tasks.api-test.js +++ b/trade-finance-manager-api/src/v1/controllers/tasks.api-test.js @@ -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, @@ -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}`); }); }); @@ -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}`); }); }); @@ -391,14 +391,14 @@ 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); }); @@ -406,7 +406,7 @@ describe('tasks controller', () => { 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); @@ -416,7 +416,7 @@ 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); @@ -424,13 +424,13 @@ describe('tasks controller', () => { 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); @@ -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);