From 505610e8874bedfa4f1ca95cd9c10d6b75ea3ac7 Mon Sep 17 00:00:00 2001 From: Aleksandra Frost Date: Tue, 30 Apr 2024 10:14:08 +0200 Subject: [PATCH] [ADD] test for proposal history util, cleaning --- .../events/location-vote/location-vote.service.ts | 4 ---- .../proposal-contracting.controller.spec.ts | 2 +- .../controller/proposal-contracting.controller.ts | 2 +- src/modules/proposal/enums/history-event.enum.ts | 1 - .../proposal/enums/proposal-status.enum.ts | 1 - .../proposal-contracting.service.spec.ts | 7 ++++++- .../utils/__tests__/proposal-history.util.spec.ts | 15 +++++++++++++++ .../proposal/utils/handle-location-vote.util.ts | 1 - src/modules/proposal/utils/location-flow.util.ts | 2 -- .../proposal/utils/proposal-history.util.ts | 1 - 10 files changed, 23 insertions(+), 13 deletions(-) diff --git a/src/modules/event-engine/events/location-vote/location-vote.service.ts b/src/modules/event-engine/events/location-vote/location-vote.service.ts index 7935f38..9bc47f4 100644 --- a/src/modules/event-engine/events/location-vote/location-vote.service.ts +++ b/src/modules/event-engine/events/location-vote/location-vote.service.ts @@ -59,8 +59,4 @@ export class LocationVoteService { await Promise.allSettled(emailTasks); } - - async handleRevertUacApproval(proposal: Proposal, vote: boolean, location: MiiLocation, proposalUrl: string) { - // ? - } } diff --git a/src/modules/proposal/controller/__tests__/proposal-contracting.controller.spec.ts b/src/modules/proposal/controller/__tests__/proposal-contracting.controller.spec.ts index 54faf7e..d3dd48f 100644 --- a/src/modules/proposal/controller/__tests__/proposal-contracting.controller.spec.ts +++ b/src/modules/proposal/controller/__tests__/proposal-contracting.controller.spec.ts @@ -84,7 +84,7 @@ describe('ProposalContractingController', () => { const input = new RevertLocationDecisionDto(); jest.spyOn(proposalContractingService, 'revertLocationDecision'); - await proposalContractingController.revertUacApproval(params, input, request); + await proposalContractingController.revertLocationDecision(params, input, request); expect(proposalContractingService.revertLocationDecision).toHaveBeenCalledWith( params.id, input.location, diff --git a/src/modules/proposal/controller/proposal-contracting.controller.ts b/src/modules/proposal/controller/proposal-contracting.controller.ts index f20b675..d8c1a08 100644 --- a/src/modules/proposal/controller/proposal-contracting.controller.ts +++ b/src/modules/proposal/controller/proposal-contracting.controller.ts @@ -75,7 +75,7 @@ export class ProposalContractingController { @ApiNoContentResponse({ description: 'Location Decision reverted. No content returns.' }) @HttpCode(204) @ApiBody({ type: RevertLocationDecisionDto }) - async revertUacApproval( + async revertLocationDecision( @Param() { id }: MongoIdParamDto, @Body() { location }: RevertLocationDecisionDto, @Request() { user }: FdpgRequest, diff --git a/src/modules/proposal/enums/history-event.enum.ts b/src/modules/proposal/enums/history-event.enum.ts index dc5f9b2..f1d2763 100644 --- a/src/modules/proposal/enums/history-event.enum.ts +++ b/src/modules/proposal/enums/history-event.enum.ts @@ -7,7 +7,6 @@ export enum HistoryEventType { ProposalRework = 'PROPOSAL_REWORK', ProposalRejected = 'PROPOSAL_REJECT', ProposalLocationCheck = 'PROPOSAL_LOCATION_CHECK', - ProposalUacApprovalReverted = 'PROPOSAL_UAC_APPROVAL_REVERTED', ProposalContracting = 'PROPOSAL_CONTRACTING', ProposalDataDelivery = 'PROPOSAL_DATA_DELIVERY', ProposalDataCorrupt = 'PROPOSAL_DATA_CORRUPT', diff --git a/src/modules/proposal/enums/proposal-status.enum.ts b/src/modules/proposal/enums/proposal-status.enum.ts index a2e1dd2..da929c8 100644 --- a/src/modules/proposal/enums/proposal-status.enum.ts +++ b/src/modules/proposal/enums/proposal-status.enum.ts @@ -5,7 +5,6 @@ export enum ProposalStatus { Rework = 'REWORK', FdpgCheck = 'FDPG_CHECK', LocationCheck = 'LOCATION_CHECK', - UacApprovalReverted = 'UAC_APPROVAL_REVERTED', Contracting = 'CONTRACTING', ExpectDataDelivery = 'EXPECT_DATA_DELIVERY', DataResearch = 'DATA_RESEARCH', diff --git a/src/modules/proposal/services/__tests__/proposal-contracting.service.spec.ts b/src/modules/proposal/services/__tests__/proposal-contracting.service.spec.ts index 48f703a..0bba9bf 100644 --- a/src/modules/proposal/services/__tests__/proposal-contracting.service.spec.ts +++ b/src/modules/proposal/services/__tests__/proposal-contracting.service.spec.ts @@ -255,7 +255,12 @@ describe('ProposalContractingService', () => { await proposalContractingService.revertLocationDecision(proposalId, request.user.miiLocation, request.user); expect(validateRevertLocationDecision).toHaveBeenCalledWith(proposalDocument); - expect(handleLocationDecision).toHaveBeenCalledWith(proposalDocument, request.user.miiLocation, request.user); + expect(handleLocationDecision).toHaveBeenCalledWith( + proposalDocument, + request.user.miiLocation, + request.user, + proposalUploadService, + ); expect(addHistoryItemForRevertLocationDecision).toHaveBeenCalledWith( proposalDocument, request.user, diff --git a/src/modules/proposal/utils/__tests__/proposal-history.util.spec.ts b/src/modules/proposal/utils/__tests__/proposal-history.util.spec.ts index 5e4229c..64a8c98 100644 --- a/src/modules/proposal/utils/__tests__/proposal-history.util.spec.ts +++ b/src/modules/proposal/utils/__tests__/proposal-history.util.spec.ts @@ -13,6 +13,7 @@ import { addHistoryItemForContractSystemReject, addHistoryItemForProposalLock, addHistoryItemForUnselectedLocation, + addHistoryItemForRevertLocationDecision, } from '../proposal-history.util'; const proposalId = 'proposalId'; @@ -191,6 +192,20 @@ describe('ProposalHistoryUtil', () => { }); }); + describe('addHistoryItemForRevertLocationDecision', () => { + it('should add history item for reverted location decision', () => { + const request = getRequest(); + const proposal = getProposalDocument(); + const location = MiiLocation.UKRUB; + + addHistoryItemForRevertLocationDecision(proposal, request.user, location); + expect(proposal.history.length).toBe(1); + + const expectedType = HistoryEventType.FdpgRevertedLocationDecision; + expect(proposal.history[0].type).toBe(expectedType); + }); + }); + describe('addHistoryItemForUacCondition', () => { test.each([true, false])(`should add history item for uac condition (isApproved: %s)`, (isApproved) => { const request = getRequest(); diff --git a/src/modules/proposal/utils/handle-location-vote.util.ts b/src/modules/proposal/utils/handle-location-vote.util.ts index 73c8d84..76572c4 100644 --- a/src/modules/proposal/utils/handle-location-vote.util.ts +++ b/src/modules/proposal/utils/handle-location-vote.util.ts @@ -12,7 +12,6 @@ import { UacApproval } from '../schema/sub-schema/uac-approval.schema'; import { addFdpgTaskAndReturnId, removeFdpgTask } from './add-fdpg-task.util'; import { clearLocationsVotes } from './location-flow.util'; import { getLocationState } from './validate-access.util'; -import { RevertLocationDecisionDto } from '../dto/revert-location-decision.dto'; import { ProposalUploadService } from '../services/proposal-upload.service'; export const addDizApproval = (proposal: Proposal, user: IRequestUser, vote: SetDizApprovalDto) => { diff --git a/src/modules/proposal/utils/location-flow.util.ts b/src/modules/proposal/utils/location-flow.util.ts index ff5ceeb..2388846 100644 --- a/src/modules/proposal/utils/location-flow.util.ts +++ b/src/modules/proposal/utils/location-flow.util.ts @@ -1,4 +1,3 @@ -import { RevertLocationDecisionDto } from './../dto/revert-location-decision.dto'; import { SYSTEM_OWNER_ID } from 'src/shared/constants/global.constants'; import { MiiLocation } from 'src/shared/constants/mii-locations'; import { IRequestUser } from 'src/shared/types/request-user.interface'; @@ -7,7 +6,6 @@ import { ConditionalApproval } from '../schema/sub-schema/conditional-approval.s import { UacApproval } from '../schema/sub-schema/uac-approval.schema'; import { addHistoryItemForContractSystemReject, addHistoryItemForUacCondition } from './proposal-history.util'; import { excludeUnselectedLocations } from './unselect-approved-location.util'; -import { filter } from 'rxjs'; export const clearLocationsVotes = (proposal: Proposal, location: MiiLocation) => { proposal.openDizChecks = proposal.openDizChecks.filter((filterLocation) => filterLocation !== location); diff --git a/src/modules/proposal/utils/proposal-history.util.ts b/src/modules/proposal/utils/proposal-history.util.ts index ef550b0..ecf00a5 100644 --- a/src/modules/proposal/utils/proposal-history.util.ts +++ b/src/modules/proposal/utils/proposal-history.util.ts @@ -5,7 +5,6 @@ import { HistoryEventType } from '../enums/history-event.enum'; import { ProposalStatus } from '../enums/proposal-status.enum'; import { Proposal } from '../schema/proposal.schema'; import { HistoryEvent } from '../schema/sub-schema/history-event.schema'; -import { RevertLocationDecisionDto } from '../dto/revert-location-decision.dto'; const pushHistoryItem = ( proposalAfterChanges: Proposal,