Skip to content

Commit

Permalink
[ADD] test for proposal history util, cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
af-ofr committed Apr 30, 2024
1 parent eb4fd67 commit 505610e
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,4 @@ export class LocationVoteService {

await Promise.allSettled(emailTasks);
}

async handleRevertUacApproval(proposal: Proposal, vote: boolean, location: MiiLocation, proposalUrl: string) {
// ?
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion src/modules/proposal/enums/history-event.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
1 change: 0 additions & 1 deletion src/modules/proposal/enums/proposal-status.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
15 changes: 15 additions & 0 deletions src/modules/proposal/utils/__tests__/proposal-history.util.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
addHistoryItemForContractSystemReject,
addHistoryItemForProposalLock,
addHistoryItemForUnselectedLocation,
addHistoryItemForRevertLocationDecision,
} from '../proposal-history.util';

const proposalId = 'proposalId';
Expand Down Expand Up @@ -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();
Expand Down
1 change: 0 additions & 1 deletion src/modules/proposal/utils/handle-location-vote.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
2 changes: 0 additions & 2 deletions src/modules/proposal/utils/location-flow.util.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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);
Expand Down
1 change: 0 additions & 1 deletion src/modules/proposal/utils/proposal-history.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 505610e

Please sign in to comment.