diff --git a/packages/event-processor/CHANGELOG.MD b/packages/event-processor/CHANGELOG.MD index 9a4531c71..c0b976f45 100644 --- a/packages/event-processor/CHANGELOG.MD +++ b/packages/event-processor/CHANGELOG.MD @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] Changes that have landed but are not yet released. +### Fixed +- Update `ConversionEvent` interface to allow event `id` type null and `tags` type undefined. + ## [0.8.1] - May 25th, 2021 ### Fixed diff --git a/packages/event-processor/__tests__/buildEventV1.spec.ts b/packages/event-processor/__tests__/buildEventV1.spec.ts index 13a8f5348..67593af0c 100644 --- a/packages/event-processor/__tests__/buildEventV1.spec.ts +++ b/packages/event-processor/__tests__/buildEventV1.spec.ts @@ -1,5 +1,5 @@ /** - * Copyright 2019, Optimizely + * Copyright 2019, 2021, Optimizely * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -224,7 +224,7 @@ describe('buildEventV1', () => { }) describe('buildConversionEventV1', () => { - it('should build an build a ConversionEventV1', () => { + it('should build a ConversionEventV1 when tags object is defined', () => { const conversionEvent: ConversionEvent = { type: 'conversion', timestamp: 69, @@ -311,6 +311,164 @@ describe('buildEventV1', () => { }) }) + it('should build a ConversionEventV1 when tags object is undefined', () => { + const conversionEvent: ConversionEvent = { + type: 'conversion', + timestamp: 69, + uuid: 'uuid', + + context: { + accountId: 'accountId', + projectId: 'projectId', + clientName: 'node-sdk', + clientVersion: '3.0.0', + revision: 'revision', + botFiltering: true, + anonymizeIP: true, + }, + + user: { + id: 'userId', + attributes: [{ entityId: 'attr1-id', key: 'attr1-key', value: 'attr1-value' }], + }, + + event: { + id: 'event-id', + key: 'event-key', + }, + + tags: undefined, + + revenue: 1000, + value: 123, + } + + const result = buildConversionEventV1(conversionEvent) + expect(result).toEqual({ + client_name: 'node-sdk', + client_version: '3.0.0', + account_id: 'accountId', + project_id: 'projectId', + revision: 'revision', + anonymize_ip: true, + enrich_decisions: true, + + visitors: [ + { + snapshots: [ + { + events: [ + { + entity_id: 'event-id', + timestamp: 69, + key: 'event-key', + uuid: 'uuid', + tags: undefined, + revenue: 1000, + value: 123, + }, + ], + }, + ], + visitor_id: 'userId', + attributes: [ + { + entity_id: 'attr1-id', + key: 'attr1-key', + type: 'custom', + value: 'attr1-value', + }, + { + entity_id: '$opt_bot_filtering', + key: '$opt_bot_filtering', + type: 'custom', + value: true, + }, + ], + }, + ], + }) + }) + + it('should build a ConversionEventV1 when event id is null', () => { + const conversionEvent: ConversionEvent = { + type: 'conversion', + timestamp: 69, + uuid: 'uuid', + + context: { + accountId: 'accountId', + projectId: 'projectId', + clientName: 'node-sdk', + clientVersion: '3.0.0', + revision: 'revision', + botFiltering: true, + anonymizeIP: true, + }, + + user: { + id: 'userId', + attributes: [{ entityId: 'attr1-id', key: 'attr1-key', value: 'attr1-value' }], + }, + + event: { + id: null, + key: 'event-key', + }, + + tags: undefined, + + revenue: 1000, + value: 123, + } + + const result = buildConversionEventV1(conversionEvent) + expect(result).toEqual({ + client_name: 'node-sdk', + client_version: '3.0.0', + account_id: 'accountId', + project_id: 'projectId', + revision: 'revision', + anonymize_ip: true, + enrich_decisions: true, + + visitors: [ + { + snapshots: [ + { + events: [ + { + entity_id: null, + timestamp: 69, + key: 'event-key', + uuid: 'uuid', + tags: undefined, + revenue: 1000, + value: 123, + }, + ], + }, + ], + visitor_id: 'userId', + attributes: [ + { + entity_id: 'attr1-id', + key: 'attr1-key', + type: 'custom', + value: 'attr1-value', + }, + { + entity_id: '$opt_bot_filtering', + key: '$opt_bot_filtering', + type: 'custom', + value: true, + }, + ], + }, + ], + }) + }) + it('should include revenue and value if they are 0', () => { const conversionEvent: ConversionEvent = { type: 'conversion', diff --git a/packages/event-processor/src/events.ts b/packages/event-processor/src/events.ts index 9a58423c9..a28d86773 100644 --- a/packages/event-processor/src/events.ts +++ b/packages/event-processor/src/events.ts @@ -73,13 +73,13 @@ export interface ConversionEvent extends BaseEvent { } event: { - id: string + id: string | null key: string } revenue: number | null value: number | null - tags: EventTags + tags: EventTags | undefined } export type EventTags = {