From deaec3ff3b680440e1e16339a78bdee4a332537f Mon Sep 17 00:00:00 2001 From: Emmanuel Zamora Date: Mon, 2 Oct 2023 11:02:04 -0300 Subject: [PATCH] Code optimization & warn declaration --- src/logger/messages/warn.ts | 1 + src/sdkClient/clientInputValidation.ts | 2 +- .../settingsValidation/__tests__/splitFilters.spec.ts | 4 ++-- src/utils/settingsValidation/splitFilters.ts | 9 ++------- 4 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/logger/messages/warn.ts b/src/logger/messages/warn.ts index b576095a..3699ac52 100644 --- a/src/logger/messages/warn.ts +++ b/src/logger/messages/warn.ts @@ -24,6 +24,7 @@ export const codesWarn: [number, string][] = codesError.concat([ [c.WARN_NOT_EXISTENT_SPLIT, '%s: feature flag "%s" does not exist in this environment. Please double check what feature flags exist in the Split user interface.'], [c.WARN_LOWERCASE_TRAFFIC_TYPE, '%s: traffic_type_name should be all lowercase - converting string to lowercase.'], [c.WARN_NOT_EXISTENT_TT, '%s: traffic type "%s" does not have any corresponding feature flag in this environment, make sure you\'re tracking your events to a valid traffic type defined in the Split user interface.'], + [c.WARN_FLAGSET_NOT_CONFIGURED, '%s: : you passed %s wich is not part of the configured FlagSetsFilter, ignoring Flag Set.'], // initialization / settings validation [c.WARN_INTEGRATION_INVALID, c.LOG_PREFIX_SETTINGS+': %s integration item(s) at settings is invalid. %s'], [c.WARN_SPLITS_FILTER_IGNORED, c.LOG_PREFIX_SETTINGS+': feature flag filters have been configured but will have no effect if mode is not "%s", since synchronization is being deferred to an external tool.'], diff --git a/src/sdkClient/clientInputValidation.ts b/src/sdkClient/clientInputValidation.ts index 28d4099c..50860b9f 100644 --- a/src/sdkClient/clientInputValidation.ts +++ b/src/sdkClient/clientInputValidation.ts @@ -31,7 +31,7 @@ export function clientInputValidationDecorator { // set_3 not included in configuration but set_1 included => [set_1] & warn expect(flagSetsAreValid(loggerMock, 'test_method', ['set_1','set_3'], flagSetsFilter)).toEqual(['set_1']); - expect(loggerMock.warn.mock.calls[6]).toEqual([WARN_FLAGSET_NOT_CONFIGURED, ['set_3']]); + expect(loggerMock.warn.mock.calls[6]).toEqual([WARN_FLAGSET_NOT_CONFIGURED, ['test_method', 'set_3']]); // set_3 not included in configuration => [] & warn expect(flagSetsAreValid(loggerMock, 'test_method', ['set_3'], flagSetsFilter)).toEqual([]); - expect(loggerMock.warn.mock.calls[7]).toEqual([WARN_FLAGSET_NOT_CONFIGURED, ['set_3']]); + expect(loggerMock.warn.mock.calls[7]).toEqual([WARN_FLAGSET_NOT_CONFIGURED, ['test_method','set_3']]); // empty config diff --git a/src/utils/settingsValidation/splitFilters.ts b/src/utils/settingsValidation/splitFilters.ts index 1df96f1b..558a870c 100644 --- a/src/utils/settingsValidation/splitFilters.ts +++ b/src/utils/settingsValidation/splitFilters.ts @@ -189,19 +189,14 @@ export function validateSplitFilters(log: ILogger, maybeSplitFilters: any, mode: } export function flagSetsAreValid(log: ILogger, method: string, flagSets: string[], flagSetsInConfig: string[]): string[] { - let toReturn: string[] = []; - if (flagSets.length === 0) { - log.error(ERROR_EMPTY_ARRAY, [method, 'flagSets']); - return toReturn; - } const sets = validateSplits(log, flagSets, method, 'flag sets', 'flag set'); - toReturn = sets ? sanitizeFlagSets(log, sets) : []; + let toReturn = sets ? sanitizeFlagSets(log, sets) : []; if (flagSetsInConfig.length > 0) { toReturn = toReturn.filter(flagSet => { if (flagSetsInConfig.indexOf(flagSet) > -1) { return true; } - log.warn(WARN_FLAGSET_NOT_CONFIGURED, [flagSet]); + log.warn(WARN_FLAGSET_NOT_CONFIGURED, [method, flagSet]); return false; }); }