Skip to content

Commit

Permalink
Revert "Solve mark and assignment issue"
Browse files Browse the repository at this point in the history
This reverts commit 59ca301.
  • Loading branch information
RidhamShah committed Sep 14, 2023
1 parent 59ca301 commit ce82483
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
IGroupMembership,
IUserAliases,
IWorkingGroup,
EXPERIMENT_TYPE,
PAYLOAD_TYPE,
IPayload,
} from 'upgrade_types';
Expand Down Expand Up @@ -539,6 +540,7 @@ export class ExperimentClientController {
});
return {
...rest,
experimentType: assignedFactor ? EXPERIMENT_TYPE.FACTORIAL : EXPERIMENT_TYPE.SIMPLE,
assignedCondition: finalConditionData,
assignedFactor: assignedFactor ? finalFactorData : undefined,
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
import { Type } from 'class-transformer';
import {
IsNotEmpty,
IsDefined,
IsString,
IsOptional,
IsEnum,
IsObject,
ValidateNested,
ValidateIf,
ValidationOptions,
registerDecorator,
} from 'class-validator';
import { MARKED_DECISION_POINT_STATUS, PAYLOAD_TYPE } from 'upgrade_types';
import { IsNotEmpty, IsDefined, IsString, IsOptional, IsEnum, IsObject, ValidateNested, ValidateIf, ValidationOptions, registerDecorator } from 'class-validator';
import { EXPERIMENT_TYPE, MARKED_DECISION_POINT_STATUS, PAYLOAD_TYPE } from 'upgrade_types';

const IsAssignedFactorRecord = (validationOptions?: ValidationOptions) => {
return function (object: unknown, propertyName: string) {
Expand All @@ -26,14 +15,16 @@ const IsAssignedFactorRecord = (validationOptions?: ValidationOptions) => {
},
validator: {
validate(value: any) {
return validateAssignedFactorData(value);
return validateAssignedFactorData(value)
},
},
});
};
};

function validateAssignedFactorData(data: any): boolean {
function validateAssignedFactorData(
data: any
): boolean {
const keys = Object.keys(data);
for (const key of keys) {
const factor = data[key];
Expand All @@ -54,7 +45,9 @@ function isValidAssignedFactor(value: any): value is AssignedFactor {

function isValidPayload(value: any): value is Payload {
return (
typeof value === 'object' && Object.values(PAYLOAD_TYPE).includes(value.type) && typeof value.value === 'string'
typeof value === 'object' &&
Object.values(PAYLOAD_TYPE).includes(value.type) &&
typeof value.value === 'string'
);
}

Expand All @@ -79,13 +72,14 @@ class AssignedFactor {
}

class AssignedCondition {
@IsOptional()
@IsNotEmpty()
@IsString()
id?: string;
id: string;

@IsOptional()
@IsDefined()
@IsNotEmpty()
@IsString()
conditionCode?: string;
conditionCode: string;

@IsObject()
@ValidateNested()
Expand All @@ -107,6 +101,11 @@ class Data {
@IsString()
target: string;

@IsEnum(EXPERIMENT_TYPE)
@IsDefined()
@IsNotEmpty()
experimentType: EXPERIMENT_TYPE;

@IsOptional()
@ValidateNested()
@Type(() => AssignedCondition)
Expand Down
28 changes: 5 additions & 23 deletions clientlibs/js/src/common/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IExperimentAssignmentv5, PAYLOAD_TYPE } from 'upgrade_types';
import { IExperimentAssignmentv5 } from "../../../../types/src";

export function rotateAssignmentList(assignment: IExperimentAssignmentv5) {
if (assignment.assignedCondition.length > 1) {
Expand All @@ -10,25 +10,7 @@ export function rotateAssignmentList(assignment: IExperimentAssignmentv5) {
return assignment;
}

export function findExperimentAssignmentBySiteAndTarget(
site: string,
target: string,
experimentAssignmentData: IExperimentAssignmentv5[]
): IExperimentAssignmentv5 {
const assignment = experimentAssignmentData.find(
(assignment) => assignment.site === site && assignment.target === target
);
return (
assignment || {
site: site,
target: target,
assignedCondition: [
{
conditionCode: null,
payload: null,
id: null,
},
],
}
);
}
export function findExperimentAssignmentBySiteAndTarget(site: string, target: string, experimentAssignmentData: IExperimentAssignmentv5[]): IExperimentAssignmentv5 {
const assignment = experimentAssignmentData.find((assignment) => assignment.site === site && assignment.target === target);
return assignment;
};
18 changes: 11 additions & 7 deletions clientlibs/js/src/functions/getDecisionPointAssignment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,18 @@ export default function getDecisionPointAssignment(
clientState: UpGradeClientInterfaces.IClientState
): Assignment {
if (clientState?.allExperimentAssignmentData) {
const experimentAssignment = findExperimentAssignmentBySiteAndTarget(
site,
target,
clientState.allExperimentAssignmentData
);
const experimentAssignment = findExperimentAssignmentBySiteAndTarget(site, target, clientState.allExperimentAssignmentData)

const assignment = new Assignment(experimentAssignment, clientState);
return assignment;
if (experimentAssignment) {
const assignment = new Assignment(
experimentAssignment,
clientState,
);

return assignment;
} else {
return null;
}
} else {
return null;
}
Expand Down
16 changes: 7 additions & 9 deletions clientlibs/js/src/functions/markDecisionPoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,15 @@ export default async function markDecisionPoint(
uniquifier?: string,
clientError?: string
): Promise<UpGradeClientInterfaces.IMarkExperimentPoint> {
const assignment = findExperimentAssignmentBySiteAndTarget(site, target, experimentAssignmentData);
const assignment = findExperimentAssignmentBySiteAndTarget(site, target, experimentAssignmentData)

if (!assignment) {
throw new Error('No assignment found');
}

rotateAssignmentList(assignment);

const data = { ...assignment, assignedCondition: { ...assignment.assignedCondition[0], conditionCode: condition } };
const data = { ...assignment, assignedCondition: { ...assignment.assignedCondition[0], conditionCode : condition} };

let requestBody: UpGradeClientInterfaces.IMarkDecisionPointRequestBody = {
userId,
Expand All @@ -40,13 +44,7 @@ export default async function markDecisionPoint(
clientError,
};
}
const response = await fetchDataService(
url,
token,
clientSessionId,
requestBody,
UpGradeClientEnums.REQUEST_TYPES.POST
);
const response = await fetchDataService(url, token, clientSessionId, requestBody, UpGradeClientEnums.REQUEST_TYPES.POST);
if (response.status) {
return response.data;
} else {
Expand Down

0 comments on commit ce82483

Please sign in to comment.