Skip to content

Commit

Permalink
[FIX] import, split handle util, change naming to vote
Browse files Browse the repository at this point in the history
  • Loading branch information
af-ofr committed Apr 30, 2024
1 parent b648d3f commit 7a0f77e
Show file tree
Hide file tree
Showing 13 changed files with 360 additions and 296 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Role } from 'src/shared/enums/role.enum';
import { FdpgRequest } from 'src/shared/types/request-user.interface';
import { SetDizApprovalDto } from '../../dto/set-diz-approval.dto';
import { SetUacApprovalDto } from '../../dto/set-uac-approval.dto';
import { RevertLocationDecisionDto } from '../../dto/revert-location-decision.dto';
import { RevertLocationVoteDto } from '../../dto/revert-location-vote.dto';
import { SignContractDto } from '../../dto/sign-contract.dto';
import { ProposalContractingController } from '../proposal-contracting.controller';
import { ProposalContractingService } from '../../services/proposal-contracting.service';
Expand Down Expand Up @@ -76,16 +76,16 @@ describe('ProposalContractingController', () => {
});
});

describe('revertLocationDecision', () => {
it('should revert the location decision', async () => {
describe('revertLocationVote', () => {
it('should revert the location vote', async () => {
const params = {
id: 'mongoId',
};
const input = new RevertLocationDecisionDto();
jest.spyOn(proposalContractingService, 'revertLocationDecision');
const input = new RevertLocationVoteDto();
jest.spyOn(proposalContractingService, 'handleLocationVote');

await proposalContractingController.revertLocationDecision(params, input, request);
expect(proposalContractingService.revertLocationDecision).toHaveBeenCalledWith(
await proposalContractingController.revertLocationVote(params, input, request);
expect(proposalContractingService.handleLocationVote).toHaveBeenCalledWith(
params.id,
input.location,
request.user,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { ProposalContractingService } from './../services/proposal-contracting.service';
import {
Body,
HttpCode,
Expand All @@ -25,9 +24,10 @@ import { ContractingUploadDto } from '../dto/contracting-upload.dto';
import { ProposalMarkConditionAcceptedReturnDto } from '../dto/proposal/proposal.dto';
import { SetDizApprovalDto } from '../dto/set-diz-approval.dto';
import { SetUacApprovalDto, SetUacApprovalWithFileDto } from '../dto/set-uac-approval.dto';
import { RevertLocationDecisionDto } from '../dto/revert-location-decision.dto';
import { RevertLocationVoteDto } from '../dto/revert-location-vote.dto';
import { SignContractDto, SignContractWithFileDto } from '../dto/sign-contract.dto';
import { InitContractingDto } from '../dto/proposal/init-contracting.dto';
import { ProposalContractingService } from '../services/proposal-contracting.service';

@ApiController('proposals', undefined, 'contracting')
export class ProposalContractingController {
Expand Down Expand Up @@ -68,19 +68,19 @@ export class ProposalContractingController {
}

@Auth(Role.FdpgMember)
@Put(':id/revertLocationDecision')
@Put(':id/revertLocationVote')
@UsePipes(ValidationPipe)
@ApiNotFoundResponse({ description: 'Proposal could not be found' })
@ApiOperation({ summary: 'Reverts the Location Decision' })
@ApiNoContentResponse({ description: 'Location Decision reverted. No content returns.' })
@ApiOperation({ summary: 'FDPG member reverts locations vote ' })
@ApiNoContentResponse({ description: 'Locations vote reverted. No content returns.' })
@HttpCode(204)
@ApiBody({ type: RevertLocationDecisionDto })
async revertLocationDecision(
@ApiBody({ type: RevertLocationVoteDto })
async revertLocationVote(
@Param() { id }: MongoIdParamDto,
@Body() { location }: RevertLocationDecisionDto,
@Body() { location }: RevertLocationVoteDto,
@Request() { user }: FdpgRequest,
): Promise<void> {
return await this.proposalContractingService.revertLocationDecision(id, location, user);
return await this.proposalContractingService.handleLocationVote(id, location, user);
}

@Auth(Role.FdpgMember)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { IsEnum } from 'class-validator';
import { MiiLocation } from 'src/shared/constants/mii-locations';

@Exclude()
export class RevertLocationDecisionDto {
export class RevertLocationVoteDto {
@Expose()
@IsEnum(MiiLocation)
location: MiiLocation;
Expand Down
4 changes: 2 additions & 2 deletions src/modules/proposal/enums/history-event.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ export enum HistoryEventType {
/** FDPG Veto */
FdpgApprovedLocationRemoved = 'FDPG_APPROVED_LOCATION_REMOVED',

/** FDPG reverts DIZ and UAC decision */
FdpgRevertedLocationDecision = 'FDPG_REVERTED_LOCATION_DECISION',
/** FDPG reverts DIZ and UAC vote */
FdpgRevertedLocationVote = 'FDPG_REVERTED_LOCATION_VOTE',

/** Data Delivery */

Expand Down
Original file line number Diff line number Diff line change
@@ -1,39 +1,35 @@
import { handleLocationDecision } from './../../utils/handle-location-vote.util';
import { ForbiddenException, NotFoundException } from '@nestjs/common';
import { Test, TestingModule } from '@nestjs/testing';
import { StorageService } from 'src/modules/storage/storage.service';
import { EventEngineService } from 'src/modules/event-engine/event-engine.service';
import { StorageService } from 'src/modules/storage/storage.service';
import { MiiLocation } from 'src/shared/constants/mii-locations';
import { Role } from 'src/shared/enums/role.enum';
import { FdpgRequest } from 'src/shared/types/request-user.interface';
import { NoErrorThrownError, getError } from 'test/get-error';
import { InitContractingDto } from '../../dto/proposal/init-contracting.dto';
import { SetDizApprovalDto } from '../../dto/set-diz-approval.dto';
import { SetUacApprovalDto } from '../../dto/set-uac-approval.dto';
import { SignContractDto } from '../../dto/sign-contract.dto';
import { ProposalStatus } from '../../enums/proposal-status.enum';
import { ProposalDocument } from '../../schema/proposal.schema';
import { addContractSign } from '../../utils/add-contract-sign.util';
import { addDizApproval, addUacApproval, addUacApprovalWithCondition } from '../../utils/handle-location-vote.util';
import { addDizApproval, addUacApproval, addUacApprovalWithCondition } from '../../utils/add-location-vote.util';
import {
addHistoryItemForContractSign,
addHistoryItemForDizApproval,
addHistoryItemForRevertLocationVote,
addHistoryItemForStatus,
addHistoryItemForUacApproval,
addHistoryItemForRevertLocationDecision,
} from '../../utils/proposal-history.util';
import { addUpload } from '../../utils/proposal.utils';
import { revertLocationVote } from '../../utils/revert-location-vote.util';
import { validateContractSign } from '../../utils/validate-contract-sign.util';
import { validateStatusChange } from '../../utils/validate-status-change.util';
import {
validateDizApproval,
validateRevertLocationDecision,
validateUacApproval,
} from '../../utils/validate-vote.util';
import { validateDizApproval, validateRevertLocationVote, validateUacApproval } from '../../utils/validate-vote.util';
import { ProposalContractingService } from '../proposal-contracting.service';
import { ProposalCrudService } from '../proposal-crud.service';
import { StatusChangeService } from '../status-change.service';
import { ForbiddenException, NotFoundException } from '@nestjs/common';
import { NoErrorThrownError, getError } from 'test/get-error';
import { InitContractingDto } from '../../dto/proposal/init-contracting.dto';
import { ProposalUploadService } from '../proposal-upload.service';
import { StatusChangeService } from '../status-change.service';

jest.mock('class-transformer', () => {
const original = jest.requireActual('class-transformer');
Expand All @@ -46,15 +42,17 @@ jest.mock('class-transformer', () => {
jest.mock('../../utils/validate-vote.util', () => ({
validateDizApproval: jest.fn(),
validateUacApproval: jest.fn(),
validateRevertLocationDecision: jest.fn(),
validateRevertLocationVote: jest.fn(),
}));

jest.mock('../../utils/handle-location-vote.util', () => ({
jest.mock('../../utils/add-location-vote.util', () => ({
addDizApproval: jest.fn(),
addUacApproval: jest.fn(),
addUacApprovalWithCondition: jest.fn(),
addUacConditionReview: jest.fn(),
handleLocationDecision: jest.fn(),
}));
jest.mock('../../utils/revert-location-vote.util', () => ({
revertLocationVote: jest.fn(),
}));

jest.mock('../../utils/proposal-history.util', () => ({
Expand All @@ -63,7 +61,7 @@ jest.mock('../../utils/proposal-history.util', () => ({
addHistoryItemForStatus: jest.fn(),
addHistoryItemForUacApproval: jest.fn(),
addHistoryItemForUacCondition: jest.fn(),
addHistoryItemForRevertLocationDecision: jest.fn(),
addHistoryItemForRevertLocationVote: jest.fn(),
}));

jest.mock('../../utils/proposal.utils', () => ({
Expand Down Expand Up @@ -148,7 +146,7 @@ describe('ProposalContractingService', () => {
handleProposalUacApproval: jest.fn(),
handleProposalStatusChange: jest.fn(),
handleProposalContractSign: jest.fn(),
handleLocationDecision: jest.fn(),
handleLocationVote: jest.fn(),
},
},
{
Expand Down Expand Up @@ -247,21 +245,21 @@ describe('ProposalContractingService', () => {
});
});

describe('revertLocationDecision', () => {
it('should revert the location decision', async () => {
describe('revertLocationVote', () => {
it('should revert the location vote', async () => {
const proposalDocument = getProposalDocument();
jest.spyOn(proposalCrudService, 'findDocument').mockResolvedValueOnce(proposalDocument);

await proposalContractingService.revertLocationDecision(proposalId, request.user.miiLocation, request.user);
await proposalContractingService.handleLocationVote(proposalId, request.user.miiLocation, request.user);

expect(validateRevertLocationDecision).toHaveBeenCalledWith(proposalDocument);
expect(handleLocationDecision).toHaveBeenCalledWith(
expect(validateRevertLocationVote).toHaveBeenCalledWith(proposalDocument);
expect(revertLocationVote).toHaveBeenCalledWith(
proposalDocument,
request.user.miiLocation,
request.user,
proposalUploadService,
);
expect(addHistoryItemForRevertLocationDecision).toHaveBeenCalledWith(
expect(addHistoryItemForRevertLocationVote).toHaveBeenCalledWith(
proposalDocument,
request.user,
request.user.miiLocation,
Expand Down
36 changes: 18 additions & 18 deletions src/modules/proposal/services/proposal-contracting.service.ts
Original file line number Diff line number Diff line change
@@ -1,46 +1,46 @@
import { ProposalUploadService } from './proposal-upload.service';
import { ForbiddenException, Injectable, NotFoundException } from '@nestjs/common';
import { plainToClass } from 'class-transformer';
import { ValidationException } from 'src/exceptions/validation/validation.exception';
import { MiiLocation } from 'src/shared/constants/mii-locations';
import { ValidationErrorInfo } from 'src/shared/dto/validation/validation-error-info.dto';
import { BadRequestError } from 'src/shared/enums/bad-request-error.enum';
import { Role } from 'src/shared/enums/role.enum';
import { IRequestUser } from 'src/shared/types/request-user.interface';
import { convertUserToGroups } from 'src/shared/utils/user-group.utils';
import { StorageService } from '../../storage/storage.service';
import { EventEngineService } from '../../event-engine/event-engine.service';
import { StorageService } from '../../storage/storage.service';
import { InitContractingDto } from '../dto/proposal/init-contracting.dto';
import { ProposalMarkConditionAcceptedReturnDto } from '../dto/proposal/proposal.dto';
import { SetDizApprovalDto } from '../dto/set-diz-approval.dto';
import { SetUacApprovalDto } from '../dto/set-uac-approval.dto';
import { SignContractDto } from '../dto/sign-contract.dto';
import { UploadDto } from '../dto/upload.dto';
import { ProposalValidation } from '../enums/porposal-validation.enum';
import { ProposalStatus } from '../enums/proposal-status.enum';
import { UseCaseUpload } from '../enums/upload-type.enum';
import { ProposalCrudService } from './proposal-crud.service';
import { StatusChangeService } from './status-change.service';
import { addContractSign } from '../utils/add-contract-sign.util';
import {
addDizApproval,
addUacApproval,
addUacApprovalWithCondition,
addUacConditionReview,
handleLocationDecision,
} from '../utils/handle-location-vote.util';
} from '../utils/add-location-vote.util';
import {
addHistoryItemForContractSign,
addHistoryItemForDizApproval,
addHistoryItemForRevertLocationVote,
addHistoryItemForStatus,
addHistoryItemForUacApproval,
addHistoryItemForUacCondition,
addHistoryItemForRevertLocationDecision,
} from '../utils/proposal-history.util';
import { addUpload, getBlobName } from '../utils/proposal.utils';
import { revertLocationVote } from '../utils/revert-location-vote.util';
import { validateContractSign } from '../utils/validate-contract-sign.util';
import { validateStatusChange } from '../utils/validate-status-change.util';
import { validateDizApproval, validateUacApproval, validateRevertLocationDecision } from '../utils/validate-vote.util';
import { SetDizApprovalDto } from '../dto/set-diz-approval.dto';
import { InitContractingDto } from '../dto/proposal/init-contracting.dto';
import { ValidationErrorInfo } from 'src/shared/dto/validation/validation-error-info.dto';
import { ValidationException } from 'src/exceptions/validation/validation.exception';
import { BadRequestError } from 'src/shared/enums/bad-request-error.enum';
import { MiiLocation } from 'src/shared/constants/mii-locations';
import { validateDizApproval, validateRevertLocationVote, validateUacApproval } from '../utils/validate-vote.util';
import { ProposalCrudService } from './proposal-crud.service';
import { ProposalUploadService } from './proposal-upload.service';
import { StatusChangeService } from './status-change.service';

@Injectable()
export class ProposalContractingService {
Expand Down Expand Up @@ -90,12 +90,12 @@ export class ProposalContractingService {
await this.eventEngineService.handleProposalUacApproval(saveResult, vote.value, user.miiLocation);
}

async revertLocationDecision(proposalId: string, location: MiiLocation, user: IRequestUser): Promise<void> {
async handleLocationVote(proposalId: string, location: MiiLocation, user: IRequestUser): Promise<void> {
const toBeUpdated = await this.proposalCrudService.findDocument(proposalId, user, undefined, true);
validateRevertLocationDecision(toBeUpdated);
validateRevertLocationVote(toBeUpdated);

await handleLocationDecision(toBeUpdated, location, user, this.proposalUploadService);
addHistoryItemForRevertLocationDecision(toBeUpdated, user, location);
await revertLocationVote(toBeUpdated, location, user, this.proposalUploadService);
addHistoryItemForRevertLocationVote(toBeUpdated, user, location);

await toBeUpdated.save();
}
Expand Down
Loading

0 comments on commit 7a0f77e

Please sign in to comment.