1
0
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:
Thomas Heartman 2024-04-05 10:29:21 +02:00
parent cf32af5925
commit e6d4a07f80
No known key found for this signature in database
GPG Key ID: BD1F880DAED1EE78
4 changed files with 20 additions and 61 deletions

View File

@ -1,15 +1,15 @@
import { cleanContext } from './clean-context'; import { cleanContext } from './clean-context';
const invalidJsonTypes = {
object: {},
array: [],
true: true,
false: false,
number: 123,
null: null,
};
test('strips invalid context properties from the context', async () => { test('strips invalid context properties from the context', async () => {
const invalidJsonTypes = {
object: {},
array: [],
true: true,
false: false,
number: 123,
null: null,
};
const validValues = { const validValues = {
appName: 'test', appName: 'test',
}; };
@ -19,7 +19,7 @@ test('strips invalid context properties from the context', async () => {
...validValues, ...validValues,
}; };
const { context: cleanedContext } = cleanContext(inputContext); const cleanedContext = cleanContext(inputContext);
expect(cleanedContext).toStrictEqual(validValues); expect(cleanedContext).toStrictEqual(validValues);
}); });
@ -29,25 +29,7 @@ test("doesn't add non-existing properties", async () => {
appName: 'test', appName: 'test',
}; };
const { context: output } = cleanContext(input); const output = cleanContext(input);
expect(output).toStrictEqual(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),
);
});

View File

@ -1,26 +1,16 @@
import type { SdkContextSchema } from '../../openapi'; import type { SdkContextSchema } from '../../openapi';
export const cleanContext = ( export const cleanContext = (context: SdkContextSchema): SdkContextSchema => {
context: SdkContextSchema,
): { context: SdkContextSchema; removedProperties: string[] } => {
const { appName, ...otherContextFields } = context; const { appName, ...otherContextFields } = context;
const removedProperties: string[] = [];
const cleanedContextFields = Object.fromEntries( const cleanedContextFields = Object.fromEntries(
Object.entries(otherContextFields).filter(([key, value]) => { Object.entries(otherContextFields).filter(
if (key === 'properties' || typeof value === 'string') { ([key, value]) => key === 'properties' || typeof value === 'string',
return true; ),
}
removedProperties.push(key);
return false;
}),
); );
return { return {
context: { ...cleanedContextFields,
...cleanedContextFields, appName,
appName,
},
removedProperties,
}; };
}; };

View File

@ -28,7 +28,6 @@ import type { AdvancedPlaygroundEnvironmentFeatureSchema } from '../../openapi/s
import { validateQueryComplexity } from './validateQueryComplexity'; import { validateQueryComplexity } from './validateQueryComplexity';
import type { IPrivateProjectChecker } from '../private-project/privateProjectCheckerType'; import type { IPrivateProjectChecker } from '../private-project/privateProjectCheckerType';
import { getDefaultVariant } from './feature-evaluator/variant'; import { getDefaultVariant } from './feature-evaluator/variant';
import { cleanContext } from './clean-context';
type EvaluationInput = { type EvaluationInput = {
features: FeatureConfigurationClient[]; features: FeatureConfigurationClient[];
@ -103,10 +102,7 @@ export class PlaygroundService {
context: SdkContextSchema, context: SdkContextSchema,
limit: number, limit: number,
userId: number, userId: number,
): Promise<{ ): Promise<AdvancedPlaygroundFeatureEvaluationResult[]> {
result: AdvancedPlaygroundFeatureEvaluationResult[];
invalidContextProperties: string[];
}> {
const segments = await this.segmentReadModel.getActive(); const segments = await this.segmentReadModel.getActive();
let filteredProjects: typeof projects = projects; let filteredProjects: typeof projects = projects;
@ -128,10 +124,7 @@ export class PlaygroundService {
this.resolveFeatures(filteredProjects, env), this.resolveFeatures(filteredProjects, env),
), ),
); );
const contexts = generateObjectCombinations(context);
const { context: cleanedContext, removedProperties } =
cleanContext(context);
const contexts = generateObjectCombinations(cleanedContext);
validateQueryComplexity( validateQueryComplexity(
environments.length, environments.length,
@ -156,7 +149,7 @@ export class PlaygroundService {
); );
const items = results.flat(); const items = results.flat();
const itemsByName = groupBy(items, (item) => item.name); const itemsByName = groupBy(items, (item) => item.name);
const result = Object.values(itemsByName).map((entries) => { return Object.values(itemsByName).map((entries) => {
const groupedEnvironments = groupBy( const groupedEnvironments = groupBy(
entries, entries,
(entry) => entry.environment, (entry) => entry.environment,
@ -167,11 +160,6 @@ export class PlaygroundService {
environments: groupedEnvironments, environments: groupedEnvironments,
}; };
}); });
return {
result,
invalidContextProperties: removedProperties,
};
} }
private async evaluate({ private async evaluate({

View File

@ -40,7 +40,6 @@ const addStrategyEditLink = (
export const advancedPlaygroundViewModel = ( export const advancedPlaygroundViewModel = (
input: AdvancedPlaygroundRequestSchema, input: AdvancedPlaygroundRequestSchema,
playgroundResult: AdvancedPlaygroundFeatureEvaluationResult[], playgroundResult: AdvancedPlaygroundFeatureEvaluationResult[],
invalidContextProperties?: string[],
): AdvancedPlaygroundResponseSchema => { ): AdvancedPlaygroundResponseSchema => {
const features = playgroundResult.map(({ environments, ...rest }) => { const features = playgroundResult.map(({ environments, ...rest }) => {
const transformedEnvironments = Object.entries(environments).map( const transformedEnvironments = Object.entries(environments).map(