mirror of
https://github.com/Unleash/unleash.git
synced 2025-09-05 17:53:12 +02:00
chore: revert most changes
This commit is contained in:
parent
cf32af5925
commit
e6d4a07f80
@ -1,15 +1,15 @@
|
||||
import { cleanContext } from './clean-context';
|
||||
|
||||
const invalidJsonTypes = {
|
||||
test('strips invalid context properties from the context', async () => {
|
||||
const invalidJsonTypes = {
|
||||
object: {},
|
||||
array: [],
|
||||
true: true,
|
||||
false: false,
|
||||
number: 123,
|
||||
null: null,
|
||||
};
|
||||
};
|
||||
|
||||
test('strips invalid context properties from the context', async () => {
|
||||
const validValues = {
|
||||
appName: 'test',
|
||||
};
|
||||
@ -19,7 +19,7 @@ test('strips invalid context properties from the context', async () => {
|
||||
...validValues,
|
||||
};
|
||||
|
||||
const { context: cleanedContext } = cleanContext(inputContext);
|
||||
const cleanedContext = cleanContext(inputContext);
|
||||
|
||||
expect(cleanedContext).toStrictEqual(validValues);
|
||||
});
|
||||
@ -29,25 +29,7 @@ test("doesn't add non-existing properties", async () => {
|
||||
appName: 'test',
|
||||
};
|
||||
|
||||
const { context: output } = cleanContext(input);
|
||||
const output = cleanContext(input);
|
||||
|
||||
expect(output).toStrictEqual(input);
|
||||
});
|
||||
|
||||
test('it returns the names of all the properties it removed', async () => {
|
||||
const { removedProperties } = cleanContext({
|
||||
appName: 'test',
|
||||
...invalidJsonTypes,
|
||||
});
|
||||
|
||||
const invalidProperties = Object.keys(invalidJsonTypes);
|
||||
|
||||
// verify that the two lists contain all the same elements
|
||||
expect(removedProperties).toEqual(
|
||||
expect.arrayContaining(invalidProperties),
|
||||
);
|
||||
|
||||
expect(invalidProperties).toEqual(
|
||||
expect.arrayContaining(removedProperties),
|
||||
);
|
||||
});
|
||||
|
@ -1,26 +1,16 @@
|
||||
import type { SdkContextSchema } from '../../openapi';
|
||||
|
||||
export const cleanContext = (
|
||||
context: SdkContextSchema,
|
||||
): { context: SdkContextSchema; removedProperties: string[] } => {
|
||||
export const cleanContext = (context: SdkContextSchema): SdkContextSchema => {
|
||||
const { appName, ...otherContextFields } = context;
|
||||
const removedProperties: string[] = [];
|
||||
|
||||
const cleanedContextFields = Object.fromEntries(
|
||||
Object.entries(otherContextFields).filter(([key, value]) => {
|
||||
if (key === 'properties' || typeof value === 'string') {
|
||||
return true;
|
||||
}
|
||||
removedProperties.push(key);
|
||||
return false;
|
||||
}),
|
||||
Object.entries(otherContextFields).filter(
|
||||
([key, value]) => key === 'properties' || typeof value === 'string',
|
||||
),
|
||||
);
|
||||
|
||||
return {
|
||||
context: {
|
||||
...cleanedContextFields,
|
||||
appName,
|
||||
},
|
||||
removedProperties,
|
||||
};
|
||||
};
|
||||
|
@ -28,7 +28,6 @@ import type { AdvancedPlaygroundEnvironmentFeatureSchema } from '../../openapi/s
|
||||
import { validateQueryComplexity } from './validateQueryComplexity';
|
||||
import type { IPrivateProjectChecker } from '../private-project/privateProjectCheckerType';
|
||||
import { getDefaultVariant } from './feature-evaluator/variant';
|
||||
import { cleanContext } from './clean-context';
|
||||
|
||||
type EvaluationInput = {
|
||||
features: FeatureConfigurationClient[];
|
||||
@ -103,10 +102,7 @@ export class PlaygroundService {
|
||||
context: SdkContextSchema,
|
||||
limit: number,
|
||||
userId: number,
|
||||
): Promise<{
|
||||
result: AdvancedPlaygroundFeatureEvaluationResult[];
|
||||
invalidContextProperties: string[];
|
||||
}> {
|
||||
): Promise<AdvancedPlaygroundFeatureEvaluationResult[]> {
|
||||
const segments = await this.segmentReadModel.getActive();
|
||||
|
||||
let filteredProjects: typeof projects = projects;
|
||||
@ -128,10 +124,7 @@ export class PlaygroundService {
|
||||
this.resolveFeatures(filteredProjects, env),
|
||||
),
|
||||
);
|
||||
|
||||
const { context: cleanedContext, removedProperties } =
|
||||
cleanContext(context);
|
||||
const contexts = generateObjectCombinations(cleanedContext);
|
||||
const contexts = generateObjectCombinations(context);
|
||||
|
||||
validateQueryComplexity(
|
||||
environments.length,
|
||||
@ -156,7 +149,7 @@ export class PlaygroundService {
|
||||
);
|
||||
const items = results.flat();
|
||||
const itemsByName = groupBy(items, (item) => item.name);
|
||||
const result = Object.values(itemsByName).map((entries) => {
|
||||
return Object.values(itemsByName).map((entries) => {
|
||||
const groupedEnvironments = groupBy(
|
||||
entries,
|
||||
(entry) => entry.environment,
|
||||
@ -167,11 +160,6 @@ export class PlaygroundService {
|
||||
environments: groupedEnvironments,
|
||||
};
|
||||
});
|
||||
|
||||
return {
|
||||
result,
|
||||
invalidContextProperties: removedProperties,
|
||||
};
|
||||
}
|
||||
|
||||
private async evaluate({
|
||||
|
@ -40,7 +40,6 @@ const addStrategyEditLink = (
|
||||
export const advancedPlaygroundViewModel = (
|
||||
input: AdvancedPlaygroundRequestSchema,
|
||||
playgroundResult: AdvancedPlaygroundFeatureEvaluationResult[],
|
||||
invalidContextProperties?: string[],
|
||||
): AdvancedPlaygroundResponseSchema => {
|
||||
const features = playgroundResult.map(({ environments, ...rest }) => {
|
||||
const transformedEnvironments = Object.entries(environments).map(
|
||||
|
Loading…
Reference in New Issue
Block a user