fix(admin-panel): resolve feature flag key mismatch (#9530)
Update feature flag handling by mapping input keys to enum values. This ensures compatibility and prevents potential runtime errors when updating workspace feature flags.
This commit is contained in:
@ -26,7 +26,7 @@ export class FeatureFlagEntity {
|
||||
|
||||
@Field(() => FeatureFlagKey)
|
||||
@Column({ nullable: false, type: 'text' })
|
||||
key: FeatureFlagKey;
|
||||
key: `${FeatureFlagKey}`;
|
||||
|
||||
@Field()
|
||||
@Column({ nullable: false, type: 'uuid' })
|
||||
|
||||
@ -0,0 +1,24 @@
|
||||
import { CustomException } from 'src/utils/custom-exception';
|
||||
import { featureFlagValidator } from 'src/engine/core-modules/feature-flag/validates/feature-flag.validate';
|
||||
|
||||
describe('featureFlagValidator', () => {
|
||||
describe('assertIsFeatureFlagKey', () => {
|
||||
it('should not throw error if featureFlagKey is valid', () => {
|
||||
expect(() =>
|
||||
featureFlagValidator.assertIsFeatureFlagKey(
|
||||
'IsWorkflowEnabled',
|
||||
new CustomException('Error', 'Error'),
|
||||
),
|
||||
).not.toThrow();
|
||||
});
|
||||
|
||||
it('should throw error if featureFlagKey is invalid', () => {
|
||||
const invalidKey = 'InvalidKey';
|
||||
const exception = new CustomException('Error', 'Error');
|
||||
|
||||
expect(() =>
|
||||
featureFlagValidator.assertIsFeatureFlagKey(invalidKey, exception),
|
||||
).toThrow(exception);
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -0,0 +1,17 @@
|
||||
import { CustomException } from 'src/utils/custom-exception';
|
||||
import { FeatureFlagKey } from 'src/engine/core-modules/feature-flag/enums/feature-flag-key.enum';
|
||||
import { isDefined } from 'src/utils/is-defined';
|
||||
|
||||
const assertIsFeatureFlagKey = (
|
||||
featureFlagKey: string,
|
||||
exceptionToThrow: CustomException,
|
||||
): asserts featureFlagKey is FeatureFlagKey => {
|
||||
if (isDefined(FeatureFlagKey[featureFlagKey])) return;
|
||||
throw exceptionToThrow;
|
||||
};
|
||||
|
||||
export const featureFlagValidator: {
|
||||
assertIsFeatureFlagKey: typeof assertIsFeatureFlagKey;
|
||||
} = {
|
||||
assertIsFeatureFlagKey: assertIsFeatureFlagKey,
|
||||
};
|
||||
Reference in New Issue
Block a user