Skip to content

Commit

Permalink
peer review comments for params updates in api
Browse files Browse the repository at this point in the history
  • Loading branch information
ppratikcr7 committed Oct 29, 2024
1 parent fc4cf35 commit 727438c
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1137,9 +1137,9 @@ export class ExperimentController {
experiment: ExperimentDTO,
@CurrentUser() currentUser: UserDTO,
@Req() request: AppRequest
): Promise<Experiment> {
): Promise<ExperimentDTO> {
request.logger.child({ user: currentUser });
return this.experimentService.update(experiment, currentUser, request.logger);
return this.experimentService.update({ ...experiment, id }, currentUser, request.logger);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ export class FeatureFlagsController {
@CurrentUser() currentUser: UserDTO,
@Req() request: AppRequest
): Promise<FeatureFlag> {
return this.featureFlagService.update(flag, id, currentUser, request.logger);
return this.featureFlagService.update({ ...flag, id }, currentUser, request.logger);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import { PreviewUserService } from '../services/PreviewUserService';
import { PreviewUser } from '../models/PreviewUser';
import { PaginatedParamsValidator } from './validators/PaginatedParamsValidator';
import { AppRequest, PaginationResponse } from '../../types';
import { IdValidator, PreviewUserValidator } from './validators/PreviewUserValidator';
import { PreviewUserValidator } from './validators/PreviewUserValidator';
import { IdValidator } from './validators/ExperimentUserValidator';

interface PreviewUserPaginationInfo extends PaginationResponse {
nodes: PreviewUser[];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ValidateNested, IsOptional, IsString, IsArray, IsNotEmpty } from 'class-validator';
import { ValidateNested, IsOptional, IsString, IsArray } from 'class-validator';
import { Type } from 'class-transformer';
import { Experiment } from '../../../../src/api/models/Experiment';
import { ExperimentCondition } from '../../../../src/api/models/ExperimentCondition';
Expand Down Expand Up @@ -26,9 +26,3 @@ export class PreviewUserValidator {
@Type(() => ExplicitIndividualAssignment)
public assignments?: ExplicitIndividualAssignment[];
}

export class IdValidator {
@IsNotEmpty()
@IsString()
public id: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ export class ExperimentService {
});
}

public async update(experiment: ExperimentDTO, currentUser: UserDTO, logger: UpgradeLogger): Promise<Experiment> {
public async update(experiment: ExperimentDTO, currentUser: UserDTO, logger: UpgradeLogger): Promise<ExperimentDTO> {
if (logger) {
logger.info({ message: `Update the experiment`, details: experiment });
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,12 +322,9 @@ export class FeatureFlagService {

public async update(
flagDTO: FeatureFlagValidation,
flagId: string,
currentUser: UserDTO,
logger: UpgradeLogger
): Promise<FeatureFlag> {
// update the flag with the flagId from the path params:
flagDTO.id = flagId;
logger.info({ message: `Update a Feature Flag => ${flagDTO.toString()}` });
const result = await this.featureFlagRepository.validateUniqueKey(flagDTO);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export default async function ConditionPayload(): Promise<void> {
updatedExperimentDoc = await experimentService.getSingleExperiment(
updatedExperimentDoc.id as any,
new UpgradeLogger()
) as any;
);

expect(updatedExperimentDoc.conditionPayloads.length).toEqual(1);
expect(updatedExperimentDoc.conditionPayloads).toEqual(
Expand All @@ -128,6 +128,6 @@ export default async function ConditionPayload(): Promise<void> {
updatedExperimentDoc = await experimentService.getSingleExperiment(
updatedExperimentDoc.id as any,
new UpgradeLogger()
) as any;
);
expect(updatedExperimentDoc.conditionPayloads.length).toEqual(0);
}
Original file line number Diff line number Diff line change
Expand Up @@ -370,15 +370,15 @@ describe('Feature Flag Service Testing', () => {
});

it('should update the flag', async () => {
const results = await service.update(mockFlag2, uuid(), mockUser1, logger);
const results = await service.update(mockFlag2, mockUser1, logger);
expect(isUUID(results.id)).toBeTruthy();
});

it('should throw an error when unable to update flag', async () => {
const err = new Error('insert error');
flagRepo.updateFeatureFlag = jest.fn().mockRejectedValue(err);
expect(async () => {
await service.update(mockFlag2, uuid(), mockUser1, logger);
await service.update(mockFlag2, mockUser1, logger);
}).rejects.toThrow(
new Error('Error in updating feature flag document "updateFeatureFlagInDB" Error: insert error')
);
Expand Down

0 comments on commit 727438c

Please sign in to comment.