|
1 | | -import { ERROR_NOT_PLAIN_OBJECT, ERROR_SIZE_EXCEEDED, WARN_SETTING_NULL, WARN_TRIMMING_PROPERTIES } from '../../../logger/constants'; |
| 1 | +import { ERROR_NOT_BOOLEAN, ERROR_NOT_PLAIN_OBJECT, ERROR_SIZE_EXCEEDED, WARN_SETTING_NULL, WARN_TRIMMING_PROPERTIES } from '../../../logger/constants'; |
2 | 2 | import { loggerMock } from '../../../logger/__tests__/sdkLogger.mock'; |
3 | 3 |
|
4 | | -import { validateEventProperties } from '../eventProperties'; |
| 4 | +import { validateEventProperties, validateImpressionsDisabled } from '../eventProperties'; |
5 | 5 |
|
6 | 6 | function calculateSize(obj: any) { |
7 | 7 | // we calculate the expected size. |
@@ -193,3 +193,47 @@ describe('INPUT VALIDATION for Event Properties', () => { |
193 | 193 | expect(loggerMock.error).toBeCalledWith(ERROR_SIZE_EXCEEDED, ['some_method_eventProps']); // Should log an error. |
194 | 194 | }); |
195 | 195 | }); |
| 196 | + |
| 197 | +describe('INPUT VALIDATION for Impressions disabled', () => { |
| 198 | + |
| 199 | + afterEach(() => { loggerMock.mockClear(); }); |
| 200 | + |
| 201 | + const impressionsDisabledInvalidValues = [ |
| 202 | + [], |
| 203 | + () => { }, |
| 204 | + 'something', |
| 205 | + NaN, |
| 206 | + -Infinity, |
| 207 | + Infinity, |
| 208 | + new Promise(res => res), |
| 209 | + Symbol('asd'), |
| 210 | + new Map() |
| 211 | + ]; |
| 212 | + |
| 213 | + test('Not setting impressionsDisabled is acceptable', () => { |
| 214 | + expect(validateImpressionsDisabled(loggerMock, undefined, 'some_method_eventProps')).toBeUndefined(); |
| 215 | + |
| 216 | + expect(loggerMock.error).not.toBeCalled(); // Should not log any errors. |
| 217 | + expect(loggerMock.warn).not.toBeCalled(); // It should have not logged any warnings. |
| 218 | + }); |
| 219 | + |
| 220 | + test('When setting a value for impressionsDisabled, only booleans are acceptable', () => { |
| 221 | + |
| 222 | + impressionsDisabledInvalidValues.forEach(val => { |
| 223 | + expect(validateImpressionsDisabled(loggerMock, val, 'some_method_eventProps')).toBeUndefined(); |
| 224 | + expect(loggerMock.error).toBeCalledWith(ERROR_NOT_BOOLEAN, ['some_method_eventProps', 'impressionsDisabled']); // Should log an error. |
| 225 | + loggerMock.error.mockClear(); |
| 226 | + }); |
| 227 | + |
| 228 | + expect(loggerMock.warn).not.toBeCalled(); // It should have not logged any warnings. |
| 229 | + }); |
| 230 | + |
| 231 | + test('It should return the impressionsDisabled value when valid', () => { |
| 232 | + expect(validateImpressionsDisabled(loggerMock, true, 'some_method_eventProps')).toBeTruthy(); |
| 233 | + expect(validateImpressionsDisabled(loggerMock, false, 'some_method_eventProps')).toBeFalsy(); |
| 234 | + |
| 235 | + expect(loggerMock.error).not.toBeCalled(); // Should not log any errors. |
| 236 | + expect(loggerMock.warn).not.toBeCalled(); // It should have not logged any warnings. |
| 237 | + }); |
| 238 | + |
| 239 | +}); |
0 commit comments