|
1 | 1 | /**
|
2 |
| - * Copyright 2016-2017, Optimizely |
| 2 | + * Copyright 2016-2018, 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.
|
@@ -285,6 +285,63 @@ describe('lib/core/event_builder', function() {
|
285 | 285 |
|
286 | 286 | assert.deepEqual(actualParams, expectedParams);
|
287 | 287 | });
|
| 288 | + |
| 289 | + it('should fill in userFeatures for user agent and bot filtering', function() { |
| 290 | + var v4ConfigObj = projectConfig.createProjectConfig(testData.getTestProjectConfigWithFeatures()); |
| 291 | + var expectedParams = { |
| 292 | + url: 'https://logx.optimizely.com/v1/events', |
| 293 | + httpVerb: 'POST', |
| 294 | + params: { |
| 295 | + 'account_id': '572018', |
| 296 | + 'project_id': '594001', |
| 297 | + 'visitors': [{ |
| 298 | + 'attributes': [{ |
| 299 | + 'entity_id': '$opt_user_agent', |
| 300 | + 'key': '$opt_user_agent', |
| 301 | + 'type': 'custom', |
| 302 | + 'value': 'Chrome' |
| 303 | + }, { |
| 304 | + 'entity_id': '$opt_bot_filtering', |
| 305 | + 'key': '$opt_bot_filtering', |
| 306 | + 'type': 'custom', |
| 307 | + 'value': true |
| 308 | + }], |
| 309 | + 'visitor_id': 'testUser', |
| 310 | + 'snapshots': [{ |
| 311 | + 'decisions': [{ |
| 312 | + 'variation_id': '595008', |
| 313 | + 'experiment_id': '595010', |
| 314 | + 'campaign_id': '595005' |
| 315 | + }], |
| 316 | + 'events': [{ |
| 317 | + 'timestamp': Math.round(new Date().getTime()), |
| 318 | + 'entity_id': '595005', |
| 319 | + 'uuid': 'a68cf1ad-0393-4e18-af87-efe8f01a7c9c', |
| 320 | + 'key': 'campaign_activated' |
| 321 | + }] |
| 322 | + }] |
| 323 | + }], |
| 324 | + 'revision': '35', |
| 325 | + 'client_name': 'node-sdk', |
| 326 | + 'client_version': packageJSON.version, |
| 327 | + 'anonymize_ip': true, |
| 328 | + } |
| 329 | + }; |
| 330 | + |
| 331 | + var eventOptions = { |
| 332 | + attributes: {'$opt_user_agent': 'Chrome'}, |
| 333 | + clientEngine: 'node-sdk', |
| 334 | + clientVersion: packageJSON.version, |
| 335 | + configObj: v4ConfigObj, |
| 336 | + experimentId: '595010', |
| 337 | + variationId: '595008', |
| 338 | + userId: 'testUser', |
| 339 | + }; |
| 340 | + |
| 341 | + var actualParams = eventBuilder.getImpressionEvent(eventOptions); |
| 342 | + |
| 343 | + assert.deepEqual(actualParams, expectedParams); |
| 344 | + }); |
288 | 345 | });
|
289 | 346 |
|
290 | 347 | describe('getConversionEvent', function() {
|
@@ -553,6 +610,64 @@ describe('lib/core/event_builder', function() {
|
553 | 610 | assert.deepEqual(actualParams, expectedParams);
|
554 | 611 | });
|
555 | 612 |
|
| 613 | + it('should fill in userFeatures for user agent and bot filtering', function() { |
| 614 | + var v4ConfigObj = projectConfig.createProjectConfig(testData.getTestProjectConfigWithFeatures()); |
| 615 | + var expectedParams = { |
| 616 | + url: 'https://logx.optimizely.com/v1/events', |
| 617 | + httpVerb: 'POST', |
| 618 | + params: { |
| 619 | + 'account_id': '572018', |
| 620 | + 'project_id': '594001', |
| 621 | + 'visitors': [{ |
| 622 | + 'attributes': [{ |
| 623 | + 'entity_id': '$opt_user_agent', |
| 624 | + 'key': '$opt_user_agent', |
| 625 | + 'type': 'custom', |
| 626 | + 'value': 'Chrome' |
| 627 | + }, { |
| 628 | + 'entity_id': '$opt_bot_filtering', |
| 629 | + 'key': '$opt_bot_filtering', |
| 630 | + 'type': 'custom', |
| 631 | + 'value': true |
| 632 | + }], |
| 633 | + 'visitor_id': 'testUser', |
| 634 | + 'snapshots': [{ |
| 635 | + 'decisions': [{ |
| 636 | + 'variation_id': '595008', |
| 637 | + 'experiment_id': '595010', |
| 638 | + 'campaign_id': '595005' |
| 639 | + }], |
| 640 | + 'events': [{ |
| 641 | + 'timestamp': Math.round(new Date().getTime()), |
| 642 | + 'entity_id': '594089', |
| 643 | + 'uuid': 'a68cf1ad-0393-4e18-af87-efe8f01a7c9c', |
| 644 | + 'key': 'item_bought' |
| 645 | + }] |
| 646 | + }] |
| 647 | + }], |
| 648 | + 'revision': '35', |
| 649 | + 'client_name': 'node-sdk', |
| 650 | + 'client_version': packageJSON.version, |
| 651 | + 'anonymize_ip': true, |
| 652 | + } |
| 653 | + }; |
| 654 | + |
| 655 | + var eventOptions = { |
| 656 | + attributes: {'$opt_user_agent': 'Chrome'}, |
| 657 | + clientEngine: 'node-sdk', |
| 658 | + clientVersion: packageJSON.version, |
| 659 | + configObj: v4ConfigObj, |
| 660 | + eventKey: 'item_bought', |
| 661 | + logger: mockLogger, |
| 662 | + experimentsToVariationMap: { '595010': '595008' }, |
| 663 | + userId: 'testUser', |
| 664 | + }; |
| 665 | + |
| 666 | + var actualParams = eventBuilder.getConversionEvent(eventOptions); |
| 667 | + |
| 668 | + assert.deepEqual(actualParams, expectedParams); |
| 669 | + }); |
| 670 | + |
556 | 671 | describe('and event tags are passed it', function() {
|
557 | 672 | it('should create proper params for getConversionEvent with event tags', function() {
|
558 | 673 | var expectedParams = {
|
@@ -851,7 +966,12 @@ describe('lib/core/event_builder', function() {
|
851 | 966 | 'project_id': '111001',
|
852 | 967 | 'visitors': [{
|
853 | 968 | 'visitor_id': 'testUser',
|
854 |
| - 'attributes': [], |
| 969 | + 'attributes': [{ |
| 970 | + 'entity_id': '$opt_bucketing_id', |
| 971 | + 'key': '$opt_bucketing_id', |
| 972 | + 'type': 'custom', |
| 973 | + 'value': 'variation', |
| 974 | + }], |
855 | 975 | 'snapshots': [{
|
856 | 976 | 'decisions': [{
|
857 | 977 | 'variation_id': '111128',
|
@@ -881,7 +1001,7 @@ describe('lib/core/event_builder', function() {
|
881 | 1001 | experimentsToVariationMap: {'111127': '111128'},
|
882 | 1002 | logger: mockLogger,
|
883 | 1003 | userId: 'testUser',
|
884 |
| - attributes: {'Optimizely Bucketing ID': 'variation'}, |
| 1004 | + attributes: {'$opt_bucketing_id': 'variation'}, |
885 | 1005 | };
|
886 | 1006 |
|
887 | 1007 | var actualParams = eventBuilder.getConversionEvent(eventOptions);
|
|
0 commit comments