diff --git a/src/logger/messages/warn.ts b/src/logger/messages/warn.ts index e10da2f5..78c0c46c 100644 --- a/src/logger/messages/warn.ts +++ b/src/logger/messages/warn.ts @@ -25,7 +25,7 @@ export const codesWarn: [number, string][] = codesError.concat([ [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 split in this environment, make sure you\'re tracking your events to a valid traffic type defined in the web console.'], // initialization / settings validation - [c.WARN_INTEGRATION_INVALID, c.logPrefixSettings+': %s integration %s at settings %s invalid. %s'], + [c.WARN_INTEGRATION_INVALID, c.logPrefixSettings+': %s integration item(s) at settings is invalid. %s'], [c.WARN_SPLITS_FILTER_IGNORED, c.logPrefixSettings+': split filters have been configured but will have no effect if mode is not "%s", since synchronization is being deferred to an external tool.'], [c.WARN_SPLITS_FILTER_INVALID, c.logPrefixSettings+': split filter at position %s is invalid. It must be an object with a valid filter type ("byName" or "byPrefix") and a list of "values".'], [c.WARN_SPLITS_FILTER_EMPTY, c.logPrefixSettings+': splitFilters configuration must be a non-empty array of filter objects.'], diff --git a/src/utils/inputValidation/__tests__/apiKey.spec.ts b/src/utils/inputValidation/__tests__/apiKey.spec.ts index c1cbb25d..76d18f1f 100644 --- a/src/utils/inputValidation/__tests__/apiKey.spec.ts +++ b/src/utils/inputValidation/__tests__/apiKey.spec.ts @@ -86,9 +86,9 @@ describe('validateAndTrackApiKey', () => { expect(validateAndTrackApiKey(loggerMock, validApiKey)).toBe(validApiKey); expect(loggerMock.warn.mock.calls).toEqual([ - [WARN_API_KEY, ['1 factory with this API Key']], - [WARN_API_KEY, ['2 factories with this API Key']], - [WARN_API_KEY, ['3 factories with this API Key']] + [WARN_API_KEY, ['1 factory/ies with this API Key']], + [WARN_API_KEY, ['2 factory/ies with this API Key']], + [WARN_API_KEY, ['3 factory/ies with this API Key']] ]); // We get a warning each time we register the same api key, with the number of instances we have. // We will release the used api key leaving only 1 "use" on the cache. @@ -100,7 +100,7 @@ describe('validateAndTrackApiKey', () => { // So we get the warning again. expect(validateAndTrackApiKey(loggerMock, validApiKey)).toBe(validApiKey); - expect(loggerMock.warn).toBeCalledWith(WARN_API_KEY, ['1 factory with this API Key']); + expect(loggerMock.warn).toBeCalledWith(WARN_API_KEY, ['1 factory/ies with this API Key']); // Leave it with 0 releaseApiKey(validApiKey); diff --git a/src/utils/inputValidation/__tests__/event.spec.ts b/src/utils/inputValidation/__tests__/event.spec.ts index 2e54136b..ce7e2cff 100644 --- a/src/utils/inputValidation/__tests__/event.spec.ts +++ b/src/utils/inputValidation/__tests__/event.spec.ts @@ -47,7 +47,7 @@ describe('INPUT VALIDATION for Event types', () => { const expectedLog = invalidEvents[i]['msg']; expect(validateEvent(loggerMock, invalidValue, 'test_method')).toBe(false); // Invalid event types should always return false. - expect(loggerMock.error).toBeCalledWith(expectedLog, expectedLog === ERROR_EVENT_TYPE_FORMAT ? ['test_method', invalidValue] : ['test_method']); // Should log the error for the invalid event type. + expect(loggerMock.error).toBeCalledWith(expectedLog, expectedLog === ERROR_EVENT_TYPE_FORMAT ? ['test_method', invalidValue] : ['test_method', 'event_type']); // Should log the error for the invalid event type. loggerMock.error.mockClear(); } diff --git a/src/utils/inputValidation/__tests__/trafficType.spec.ts b/src/utils/inputValidation/__tests__/trafficType.spec.ts index bbea3d23..7a3b6bb3 100644 --- a/src/utils/inputValidation/__tests__/trafficType.spec.ts +++ b/src/utils/inputValidation/__tests__/trafficType.spec.ts @@ -59,7 +59,7 @@ describe('INPUT VALIDATION for Traffic Types', () => { const expectedLog = invalidTrafficTypes[i]['msg']; expect(validateTrafficType(loggerMock, invalidValue, 'test_method')).toBe(false); // Invalid traffic types should always return false. - expect(loggerMock.error.mock.calls[i]).toEqual([expectedLog, ['test_method']]); // Should log the error for the invalid traffic type. + expect(loggerMock.error.mock.calls[i]).toEqual([expectedLog, ['test_method', 'traffic_type']]); // Should log the error for the invalid traffic type. } expect(loggerMock.warn).not.toBeCalled(); // It should have not logged any warnings. diff --git a/src/utils/inputValidation/apiKey.ts b/src/utils/inputValidation/apiKey.ts index 0b891abf..f97860cf 100644 --- a/src/utils/inputValidation/apiKey.ts +++ b/src/utils/inputValidation/apiKey.ts @@ -36,7 +36,7 @@ export function validateAndTrackApiKey(log: ILogger, maybeApiKey: any): string | log.warn(WARN_API_KEY, ['an instance of the Split factory']); } } else { - log.warn(WARN_API_KEY, [`${usedKeysMap[apiKey]} ${usedKeysMap[apiKey] === 1 ? 'factory' : 'factories'} with this API Key`]); + log.warn(WARN_API_KEY, [`${usedKeysMap[apiKey]} factory/ies with this API Key`]); usedKeysMap[apiKey]++; } } diff --git a/src/utils/inputValidation/event.ts b/src/utils/inputValidation/event.ts index 03e79c9e..98311224 100644 --- a/src/utils/inputValidation/event.ts +++ b/src/utils/inputValidation/event.ts @@ -3,15 +3,16 @@ import { ILogger } from '../../logger/types'; import { isString } from '../lang'; const EVENT_TYPE_REGEX = /^[a-zA-Z0-9][-_.:a-zA-Z0-9]{0,79}$/; +const item = 'event_type'; export function validateEvent(log: ILogger, maybeEvent: any, method: string): string | false { if (maybeEvent == undefined) { // eslint-disable-line eqeqeq - log.error(ERROR_NULL, [method]); + log.error(ERROR_NULL, [method, item]); } else if (!isString(maybeEvent)) { - log.error(ERROR_INVALID, [method]); + log.error(ERROR_INVALID, [method, item]); } else { // It is a string. if (maybeEvent.length === 0) { - log.error(ERROR_EMPTY, [method]); + log.error(ERROR_EMPTY, [method, item]); } else if (!EVENT_TYPE_REGEX.test(maybeEvent)) { log.error(ERROR_EVENT_TYPE_FORMAT, [method, maybeEvent]); } else { diff --git a/src/utils/inputValidation/trafficType.ts b/src/utils/inputValidation/trafficType.ts index 79f1eb02..01c64dbd 100644 --- a/src/utils/inputValidation/trafficType.ts +++ b/src/utils/inputValidation/trafficType.ts @@ -3,15 +3,16 @@ import { ILogger } from '../../logger/types'; import { isString } from '../lang'; const CAPITAL_LETTERS_REGEX = /[A-Z]/; +const item = 'traffic_type'; export function validateTrafficType(log: ILogger, maybeTT: any, method: string): string | false { if (maybeTT == undefined) { // eslint-disable-line eqeqeq - log.error(ERROR_NULL, [method]); + log.error(ERROR_NULL, [method, item]); } else if (!isString(maybeTT)) { - log.error(ERROR_INVALID, [method]); + log.error(ERROR_INVALID, [method, item]); } else { if (maybeTT.length === 0) { - log.error(ERROR_EMPTY, [method]); + log.error(ERROR_EMPTY, [method, item]); } else { if (CAPITAL_LETTERS_REGEX.test(maybeTT)) { log.warn(WARN_LOWERCASE_TRAFFIC_TYPE, [method]); diff --git a/src/utils/settingsValidation/integrations/common.ts b/src/utils/settingsValidation/integrations/common.ts index 95fa1cd4..5ead4509 100644 --- a/src/utils/settingsValidation/integrations/common.ts +++ b/src/utils/settingsValidation/integrations/common.ts @@ -21,7 +21,7 @@ export function validateIntegrations(settings: { log: ILogger, integrations?: an // Log a warning if at least one item is invalid const invalids = integrations.length - validIntegrations.length; - if (invalids) log.warn(WARN_INTEGRATION_INVALID, [invalids, invalids === 1 ? 'item' : 'items', invalids === 1 ? 'is' : 'are', extraWarning || '']); + if (invalids) log.warn(WARN_INTEGRATION_INVALID, [invalids, extraWarning || '']); return validIntegrations; }