|
1 | 1 | /**
|
2 |
| - * Copyright 2019, Optimizely |
| 2 | + * Copyright 2019, 2021, Optimizely |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
@@ -224,7 +224,7 @@ describe('buildEventV1', () => {
|
224 | 224 | })
|
225 | 225 |
|
226 | 226 | describe('buildConversionEventV1', () => {
|
227 |
| - it('should build an build a ConversionEventV1', () => { |
| 227 | + it('should build a ConversionEventV1 when tags object is defined', () => { |
228 | 228 | const conversionEvent: ConversionEvent = {
|
229 | 229 | type: 'conversion',
|
230 | 230 | timestamp: 69,
|
@@ -311,6 +311,164 @@ describe('buildEventV1', () => {
|
311 | 311 | })
|
312 | 312 | })
|
313 | 313 |
|
| 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 | + |
314 | 472 | it('should include revenue and value if they are 0', () => {
|
315 | 473 | const conversionEvent: ConversionEvent = {
|
316 | 474 | type: 'conversion',
|
|
0 commit comments