1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-03-18 00:19:49 +01:00

fix: enable disabled strategies keeps settings (#7955)

This commit is contained in:
Mateusz Kwasniewski 2024-08-21 16:48:50 +02:00 committed by GitHub
parent 23c7fc162d
commit 8ebebd790d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 54 additions and 20 deletions

View File

@ -82,9 +82,7 @@
"testTimeout": 10000, "testTimeout": 10000,
"globalSetup": "./scripts/jest-setup.js", "globalSetup": "./scripts/jest-setup.js",
"transform": { "transform": {
"^.+\\.tsx?$": [ "^.+\\.tsx?$": ["@swc/jest"]
"@swc/jest"
]
}, },
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$", "testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
"testPathIgnorePatterns": [ "testPathIgnorePatterns": [
@ -93,13 +91,7 @@
"/frontend/", "/frontend/",
"/website/" "/website/"
], ],
"moduleFileExtensions": [ "moduleFileExtensions": ["ts", "tsx", "js", "jsx", "json"],
"ts",
"tsx",
"js",
"jsx",
"json"
],
"coveragePathIgnorePatterns": [ "coveragePathIgnorePatterns": [
"/node_modules/", "/node_modules/",
"/dist/", "/dist/",
@ -237,14 +229,8 @@
"tough-cookie": "4.1.3" "tough-cookie": "4.1.3"
}, },
"lint-staged": { "lint-staged": {
"*.{js,ts}": [ "*.{js,ts}": ["biome check --apply --no-errors-on-unmatched"],
"biome check --apply --no-errors-on-unmatched" "*.{jsx,tsx}": ["biome check --apply --no-errors-on-unmatched"],
], "*.json": ["biome format --write --no-errors-on-unmatched"]
"*.{jsx,tsx}": [
"biome check --apply --no-errors-on-unmatched"
],
"*.json": [
"biome format --write --no-errors-on-unmatched"
]
} }
} }

View File

@ -1783,7 +1783,7 @@ class FeatureToggleService {
strategies.map((strategy) => strategies.map((strategy) =>
this.updateStrategy( this.updateStrategy(
strategy.id, strategy.id,
{ disabled: false }, { ...strategy, disabled: false },
{ {
environment, environment,
projectId: project, projectId: project,

View File

@ -734,3 +734,51 @@ test('Should return last seen at per environment', async () => {
); );
expect(featureToggle.lastSeenAt).toEqual(new Date(lastSeenAtStoreDate)); expect(featureToggle.lastSeenAt).toEqual(new Date(lastSeenAtStoreDate));
}); });
test('Should enable disabled strategies on feature environment enabled', async () => {
const flagName = 'enableThisFlag';
const project = 'default';
const environment = 'default';
const shouldActivateDisabledStrategies = true;
await service.createFeatureToggle(
project,
{
name: flagName,
},
TEST_AUDIT_USER,
);
const config: Omit<FeatureStrategySchema, 'id'> = {
name: 'default',
constraints: [
{ contextName: 'userId', operator: 'IN', values: ['1', '1'] },
],
parameters: { param: 'a' },
variants: [
{
name: 'a',
weight: 100,
weightType: 'variable',
stickiness: 'random',
},
],
disabled: true,
};
const createdConfig = await service.createStrategy(
config,
{ projectId: project, featureName: flagName, environment },
TEST_AUDIT_USER,
);
await service.updateEnabled(
project,
flagName,
environment,
true,
TEST_AUDIT_USER,
{ email: 'test@example.com' } as User,
shouldActivateDisabledStrategies,
);
const strategy = await service.getStrategy(createdConfig.id);
expect(strategy).toMatchObject({ ...config, disabled: false });
});