Skip to content

Commit 1009e2b

Browse files
authored
fix: items check error when attribute value is undefined or null (#39)
1 parent 761d9ec commit 1009e2b

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

src/provider/EventChecker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ export class EventChecker {
221221
let errorMsg;
222222
let error: EventError;
223223
for (const [key, value] of Object.entries(item)) {
224-
const valueStr = value.toString();
224+
const valueStr = String(value);
225225
if (!EventChecker.itemKeySet.has(key)) {
226226
customKeyNumber += 1;
227227
if (customKeyNumber > MAX_NUM_OF_CUSTOM_ITEM_ATTRIBUTE) {

test/provider/AnalyticsEventBuilder.test.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,17 @@ describe('AnalyticsEventBuilder test', () => {
120120
);
121121
});
122122

123+
test('test check event attribute with invalid value', () => {
124+
let clickstreamAttribute: ClickstreamAttribute = {};
125+
clickstreamAttribute['testUndefinedKey'] = undefined;
126+
clickstreamAttribute['testNullKey'] = null;
127+
clickstreamAttribute =
128+
AnalyticsEventBuilder.getEventAttributesWithCheck(clickstreamAttribute);
129+
expect(
130+
Event.ReservedAttribute.ERROR_CODE in clickstreamAttribute
131+
).toBeFalsy();
132+
});
133+
123134
test('test check event attribute reached max attribute value length', () => {
124135
let clickstreamAttribute: ClickstreamAttribute = {};
125136
let longValue = '';
@@ -280,6 +291,25 @@ describe('AnalyticsEventBuilder test', () => {
280291
);
281292
});
282293

294+
test('test check item value for undefined or null', () => {
295+
const clickstreamAttribute: ClickstreamAttribute = {};
296+
const items: Item[] = [];
297+
const item: Item = {
298+
id: 'item_1',
299+
undefinedKey: undefined,
300+
nullKey: null,
301+
};
302+
items.push(item);
303+
const resultItems = AnalyticsEventBuilder.getEventItemsWithCheck(
304+
items,
305+
clickstreamAttribute
306+
);
307+
expect(resultItems.length).toBe(1);
308+
expect(
309+
Event.ReservedAttribute.ERROR_CODE in clickstreamAttribute
310+
).toBeFalsy();
311+
});
312+
283313
test('test check event attributes will not affect global attributes', () => {
284314
const customAttributes: ClickstreamAttribute = {
285315
testKey: 'testValue',

0 commit comments

Comments
 (0)