Skip to content

Commit 004e22a

Browse files
authored
fix:(event processor): Update ConversionEvent interface (#681)
* Edit ConversionEvent interface * Clean up * Update changelog * Update year
1 parent 6e954b7 commit 004e22a

File tree

3 files changed

+165
-4
lines changed

3 files changed

+165
-4
lines changed

packages/event-processor/CHANGELOG.MD

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
77
## [Unreleased]
88
Changes that have landed but are not yet released.
99

10+
### Fixed
11+
- Update `ConversionEvent` interface to allow event `id` type null and `tags` type undefined.
12+
1013
## [0.8.1] - May 25th, 2021
1114

1215
### Fixed

packages/event-processor/__tests__/buildEventV1.spec.ts

Lines changed: 160 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2019, Optimizely
2+
* Copyright 2019, 2021, Optimizely
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -224,7 +224,7 @@ describe('buildEventV1', () => {
224224
})
225225

226226
describe('buildConversionEventV1', () => {
227-
it('should build an build a ConversionEventV1', () => {
227+
it('should build a ConversionEventV1 when tags object is defined', () => {
228228
const conversionEvent: ConversionEvent = {
229229
type: 'conversion',
230230
timestamp: 69,
@@ -311,6 +311,164 @@ describe('buildEventV1', () => {
311311
})
312312
})
313313

314+
it('should build a ConversionEventV1 when tags object is undefined', () => {
315+
const conversionEvent: ConversionEvent = {
316+
type: 'conversion',
317+
timestamp: 69,
318+
uuid: 'uuid',
319+
320+
context: {
321+
accountId: 'accountId',
322+
projectId: 'projectId',
323+
clientName: 'node-sdk',
324+
clientVersion: '3.0.0',
325+
revision: 'revision',
326+
botFiltering: true,
327+
anonymizeIP: true,
328+
},
329+
330+
user: {
331+
id: 'userId',
332+
attributes: [{ entityId: 'attr1-id', key: 'attr1-key', value: 'attr1-value' }],
333+
},
334+
335+
event: {
336+
id: 'event-id',
337+
key: 'event-key',
338+
},
339+
340+
tags: undefined,
341+
342+
revenue: 1000,
343+
value: 123,
344+
}
345+
346+
const result = buildConversionEventV1(conversionEvent)
347+
expect(result).toEqual({
348+
client_name: 'node-sdk',
349+
client_version: '3.0.0',
350+
account_id: 'accountId',
351+
project_id: 'projectId',
352+
revision: 'revision',
353+
anonymize_ip: true,
354+
enrich_decisions: true,
355+
356+
visitors: [
357+
{
358+
snapshots: [
359+
{
360+
events: [
361+
{
362+
entity_id: 'event-id',
363+
timestamp: 69,
364+
key: 'event-key',
365+
uuid: 'uuid',
366+
tags: undefined,
367+
revenue: 1000,
368+
value: 123,
369+
},
370+
],
371+
},
372+
],
373+
visitor_id: 'userId',
374+
attributes: [
375+
{
376+
entity_id: 'attr1-id',
377+
key: 'attr1-key',
378+
type: 'custom',
379+
value: 'attr1-value',
380+
},
381+
{
382+
entity_id: '$opt_bot_filtering',
383+
key: '$opt_bot_filtering',
384+
type: 'custom',
385+
value: true,
386+
},
387+
],
388+
},
389+
],
390+
})
391+
})
392+
393+
it('should build a ConversionEventV1 when event id is null', () => {
394+
const conversionEvent: ConversionEvent = {
395+
type: 'conversion',
396+
timestamp: 69,
397+
uuid: 'uuid',
398+
399+
context: {
400+
accountId: 'accountId',
401+
projectId: 'projectId',
402+
clientName: 'node-sdk',
403+
clientVersion: '3.0.0',
404+
revision: 'revision',
405+
botFiltering: true,
406+
anonymizeIP: true,
407+
},
408+
409+
user: {
410+
id: 'userId',
411+
attributes: [{ entityId: 'attr1-id', key: 'attr1-key', value: 'attr1-value' }],
412+
},
413+
414+
event: {
415+
id: null,
416+
key: 'event-key',
417+
},
418+
419+
tags: undefined,
420+
421+
revenue: 1000,
422+
value: 123,
423+
}
424+
425+
const result = buildConversionEventV1(conversionEvent)
426+
expect(result).toEqual({
427+
client_name: 'node-sdk',
428+
client_version: '3.0.0',
429+
account_id: 'accountId',
430+
project_id: 'projectId',
431+
revision: 'revision',
432+
anonymize_ip: true,
433+
enrich_decisions: true,
434+
435+
visitors: [
436+
{
437+
snapshots: [
438+
{
439+
events: [
440+
{
441+
entity_id: null,
442+
timestamp: 69,
443+
key: 'event-key',
444+
uuid: 'uuid',
445+
tags: undefined,
446+
revenue: 1000,
447+
value: 123,
448+
},
449+
],
450+
},
451+
],
452+
visitor_id: 'userId',
453+
attributes: [
454+
{
455+
entity_id: 'attr1-id',
456+
key: 'attr1-key',
457+
type: 'custom',
458+
value: 'attr1-value',
459+
},
460+
{
461+
entity_id: '$opt_bot_filtering',
462+
key: '$opt_bot_filtering',
463+
type: 'custom',
464+
value: true,
465+
},
466+
],
467+
},
468+
],
469+
})
470+
})
471+
314472
it('should include revenue and value if they are 0', () => {
315473
const conversionEvent: ConversionEvent = {
316474
type: 'conversion',

packages/event-processor/src/events.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,13 @@ export interface ConversionEvent extends BaseEvent {
7373
}
7474

7575
event: {
76-
id: string
76+
id: string | null
7777
key: string
7878
}
7979

8080
revenue: number | null
8181
value: number | null
82-
tags: EventTags
82+
tags: EventTags | undefined
8383
}
8484

8585
export type EventTags = {

0 commit comments

Comments
 (0)