Skip to content

Commit a2ed8ab

Browse files
committed
Fix tests that were querying the legacy local storage
1 parent 4a7409a commit a2ed8ab

File tree

3 files changed

+25
-49
lines changed

3 files changed

+25
-49
lines changed

src/localstorage.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
* Implement localStorage to support Firefox 2-3 and IE 5-7
55
*/
66

7+
var localStorage; // jshint ignore:line
8+
79
if (!BUILD_COMPAT_LOCAL_STORAGE) {
810
localStorage = window.localStorage;
911
}
1012

1113
if (BUILD_COMPAT_LOCAL_STORAGE) {
12-
var localStorage; // jshint ignore:line
13-
1414
// test that Window.localStorage is available and works
1515
const windowLocalStorageAvailable = () => {
1616
var uid = new Date();

test/amplitude-client.js

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -508,8 +508,8 @@ describe('AmplitudeClient', function() {
508508
'"event_properties":{},"user_properties":{"$set":{"age":30,"city":"San Francisco, CA"}},"uuid":"' +
509509
'c50e1be4-7976-436a-aa25-d9ee38951082","library":{"name":"amplitude-js","version":"2.9.0"},"sequence_number"' +
510510
':131,"groups":{}}]';
511-
localStorage.setItem('amplitude_unsent', existingEvent);
512-
localStorage.setItem('amplitude_unsent_identify', existingIdentify);
511+
localStorage.setItem('amplitude_unsent_' + apiKey, existingEvent);
512+
localStorage.setItem('amplitude_unsent_identify_' + apiKey, existingIdentify);
513513

514514
var amplitude2 = new AmplitudeClient('$default_Instance');
515515
amplitude2.init(apiKey, null, {batchEvents: true});
@@ -535,8 +535,8 @@ describe('AmplitudeClient', function() {
535535
'"event_properties":{},"user_properties":{"$set":{"age":30,"city":"San Francisco, CA"}},"uuid":"' +
536536
'c50e1be4-7976-436a-aa25-d9ee38951082","library":{"name":"amplitude-js","version":"2.9.0"},"sequence_number"' +
537537
':131,"groups":{}}]';
538-
localStorage.setItem('amplitude_unsent_new_app', existingEvent);
539-
localStorage.setItem('amplitude_unsent_identify_new_app', existingIdentify);
538+
localStorage.setItem('amplitude_unsent_' + apiKey + '_new_app', existingEvent);
539+
localStorage.setItem('amplitude_unsent_identify_' + apiKey + '_new_app', existingIdentify);
540540
assert.isNull(localStorage.getItem('amplitude_unsent'));
541541
assert.isNull(localStorage.getItem('amplitude_unsent_identify'));
542542

@@ -565,7 +565,7 @@ describe('AmplitudeClient', function() {
565565
'[0,1,2,"3"],"nested_array":["a",{"key":"value"},["b"]],"object":{"key":"value"},"nested_object":' +
566566
'{"k":"v","l":[0,1],"o":{"k2":"v2","l2":["e2",{"k3":"v3"}]}}},"user_properties":{},"uuid":"650407a1-d705-' +
567567
'47a0-8918-b4530ce51f89","library":{"name":"amplitude-js","version":"2.9.0"},"sequence_number":5}]'
568-
localStorage.setItem('amplitude_unsent', existingEvents);
568+
localStorage.setItem('amplitude_unsent_' + apiKey, existingEvents);
569569

570570
var amplitude2 = new AmplitudeClient('$default_instance');
571571
amplitude2.init(apiKey, null, {batchEvents: true});
@@ -594,7 +594,7 @@ describe('AmplitudeClient', function() {
594594
'[0,1,2,"3"],"nested_array":["a",{"key":"value"},["b"]],"object":{"key":"value"},"nested_object":' +
595595
'{"k":"v","l":[0,1],"o":{"k2":"v2","l2":["e2",{"k3":"v3"}]}}}},"event_properties":{},"uuid":"650407a1-d705-' +
596596
'47a0-8918-b4530ce51f89","library":{"name":"amplitude-js","version":"2.9.0"},"sequence_number":5}]'
597-
localStorage.setItem('amplitude_unsent_identify', existingEvents);
597+
localStorage.setItem('amplitude_unsent_identify_' + apiKey, existingEvents);
598598

599599
var amplitude2 = new AmplitudeClient();
600600
amplitude2.init(apiKey, null, {batchEvents: true});
@@ -625,8 +625,8 @@ describe('AmplitudeClient', function() {
625625
'"event_properties":{},"user_properties":{"$set":{"age":30,"city":"San Francisco, CA"}},"uuid":"' +
626626
'c50e1be4-7976-436a-aa25-d9ee38951082","library":{"name":"amplitude-js","version":"2.9.0"},"sequence_number"' +
627627
':131}]';
628-
localStorage.setItem('amplitude_unsent', existingEvent);
629-
localStorage.setItem('amplitude_unsent_identify', existingIdentify);
628+
localStorage.setItem('amplitude_unsent_' + apiKey, existingEvent);
629+
localStorage.setItem('amplitude_unsent_identify_' + apiKey, existingIdentify);
630630

631631
var amplitude2 = new AmplitudeClient();
632632
amplitude2.init(apiKey, null, {batchEvents: true, eventUploadThreshold: 2});
@@ -661,8 +661,8 @@ it ('should load saved events from localStorage new keys and send events', funct
661661
'"event_properties":{},"user_properties":{"$set":{"age":30,"city":"San Francisco, CA"}},"uuid":"' +
662662
'c50e1be4-7976-436a-aa25-d9ee38951082","library":{"name":"amplitude-js","version":"2.9.0"},"sequence_number"' +
663663
':131}]';
664-
localStorage.setItem('amplitude_unsent_new_app', existingEvent);
665-
localStorage.setItem('amplitude_unsent_identify_new_app', existingIdentify);
664+
localStorage.setItem('amplitude_unsent_' + apiKey + '_new_app', existingEvent);
665+
localStorage.setItem('amplitude_unsent_identify_' + apiKey + '_new_app', existingIdentify);
666666

667667
var amplitude2 = new AmplitudeClient('new_app');
668668
amplitude2.init(apiKey, null, {batchEvents: true, eventUploadThreshold: 2});
@@ -698,7 +698,7 @@ it ('should load saved events from localStorage new keys and send events', funct
698698
'[0,1,2,"3"],"nested_array":["a",{"key":"value"},["b"]],"object":{"key":"value"},"nested_object":' +
699699
'{"k":"v","l":[0,1],"o":{"k2":"v2","l2":["e2",{"k3":"v3"}]}}},"user_properties":{},"uuid":"650407a1-d705-' +
700700
'47a0-8918-b4530ce51f89","library":{"name":"amplitude-js","version":"2.9.0"},"sequence_number":5}]';
701-
localStorage.setItem('amplitude_unsent', existingEvents);
701+
localStorage.setItem('amplitude_unsent_' + apiKey, existingEvents);
702702

703703
var amplitude2 = new AmplitudeClient();
704704
amplitude2.init(apiKey, null, {
@@ -773,11 +773,14 @@ it ('should load saved events from localStorage new keys and send events', funct
773773

774774
var amplitude2 = new AmplitudeClient('new_app');
775775
amplitude2.init(apiKey, null, {trackingOptions: trackingOptions});
776+
console.log(JSON.stringify(amplitude2.options.trackingOptions));
776777

777778
// check config loaded correctly
778779
assert.deepEqual(amplitude2.options.trackingOptions, {
779780
city: false,
780781
country: true,
782+
carrier: true,
783+
device_manufacturer: true,
781784
device_model: true,
782785
dma: true,
783786
ip_address: false,
@@ -2992,8 +2995,8 @@ describe('setVersionName', function() {
29922995
'"event_properties":{},"user_properties":{"$set":{"age":30,"city":"San Francisco, CA"}},"uuid":"' +
29932996
'c50e1be4-7976-436a-aa25-d9ee38951082","library":{"name":"amplitude-js","version":"2.9.0"},"sequence_number"' +
29942997
':131, "groups":{}}]';
2995-
localStorage.setItem('amplitude_unsent', existingEvent);
2996-
localStorage.setItem('amplitude_unsent_identify', existingIdentify);
2998+
localStorage.setItem('amplitude_unsent_' + apiKey, existingEvent);
2999+
localStorage.setItem('amplitude_unsent_identify_' + apiKey, existingIdentify);
29973000

29983001
clock.tick(30 * 60 * 1000 + 1); // force new session
29993002
amplitude.init(apiKey, undefined, {

test/amplitude.js

Lines changed: 7 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -493,33 +493,6 @@ describe('Amplitude', function() {
493493
assert.equal(amplitude2.getInstance()._sequenceNumber, 70);
494494
});
495495

496-
it('should load saved events from legacy localStorage', function() {
497-
var existingEvent = '[{"device_id":"test_device_id","user_id":"test_user_id","timestamp":1453769146589,' +
498-
'"event_id":49,"session_id":1453763315544,"event_type":"clicked","version_name":"Web","platform":"Web"' +
499-
',"os_name":"Chrome","os_version":"47","device_model":"Mac","language":"en-US","api_properties":{},' +
500-
'"event_properties":{},"user_properties":{},"uuid":"3c508faa-a5c9-45fa-9da7-9f4f3b992fb0","library"' +
501-
':{"name":"amplitude-js","version":"2.9.0"},"sequence_number":130,"groups":{}}]';
502-
var existingIdentify = '[{"device_id":"test_device_id","user_id":"test_user_id","timestamp":1453769338995,' +
503-
'"event_id":82,"session_id":1453763315544,"event_type":"$identify","version_name":"Web","platform":"Web"' +
504-
',"os_name":"Chrome","os_version":"47","device_model":"Mac","language":"en-US","api_properties":{},' +
505-
'"event_properties":{},"user_properties":{"$set":{"age":30,"city":"San Francisco, CA"}},"uuid":"' +
506-
'c50e1be4-7976-436a-aa25-d9ee38951082","library":{"name":"amplitude-js","version":"2.9.0"},"sequence_number"' +
507-
':131,"groups":{}}]';
508-
localStorage.setItem('amplitude_unsent', existingEvent);
509-
localStorage.setItem('amplitude_unsent_identify', existingIdentify);
510-
511-
var amplitude2 = new Amplitude();
512-
amplitude2.init(apiKey, null, {batchEvents: true});
513-
514-
// check event loaded into memory
515-
assert.deepEqual(amplitude2.getInstance()._unsentEvents, JSON.parse(existingEvent));
516-
assert.deepEqual(amplitude2.getInstance()._unsentIdentifys, JSON.parse(existingIdentify));
517-
518-
// check local storage keys are still same for default instance
519-
assert.equal(localStorage.getItem('amplitude_unsent_' + apiKey), existingEvent);
520-
assert.equal(localStorage.getItem('amplitude_unsent_identify_' + apiKey), existingIdentify);
521-
});
522-
523496
it('should load saved events from localStorage', function() {
524497
var existingEvent = '[{"device_id":"test_device_id","user_id":"test_user_id","timestamp":1453769146589,' +
525498
'"event_id":49,"session_id":1453763315544,"event_type":"clicked","version_name":"Web","platform":"Web"' +
@@ -532,8 +505,8 @@ describe('Amplitude', function() {
532505
'"event_properties":{},"user_properties":{"$set":{"age":30,"city":"San Francisco, CA"}},"uuid":"' +
533506
'c50e1be4-7976-436a-aa25-d9ee38951082","library":{"name":"amplitude-js","version":"2.9.0"},"sequence_number"' +
534507
':131,"groups":{}}]';
535-
localStorage.setItem('amplitude_unsent', existingEvent);
536-
localStorage.setItem('amplitude_unsent_identify', existingIdentify);
508+
localStorage.setItem('amplitude_unsent_' + apiKey, existingEvent);
509+
localStorage.setItem('amplitude_unsent_identify_' + apiKey, existingIdentify);
537510

538511
var amplitude2 = new Amplitude();
539512
amplitude2.init(apiKey, null, {batchEvents: true});
@@ -560,7 +533,7 @@ describe('Amplitude', function() {
560533
'[0,1,2,"3"],"nested_array":["a",{"key":"value"},["b"]],"object":{"key":"value"},"nested_object":' +
561534
'{"k":"v","l":[0,1],"o":{"k2":"v2","l2":["e2",{"k3":"v3"}]}}},"user_properties":{},"uuid":"650407a1-d705-' +
562535
'47a0-8918-b4530ce51f89","library":{"name":"amplitude-js","version":"2.9.0"},"sequence_number":5}]'
563-
localStorage.setItem('amplitude_unsent', existingEvents);
536+
localStorage.setItem('amplitude_unsent_' + apiKey, existingEvents);
564537

565538
var amplitude2 = new Amplitude();
566539
amplitude2.init(apiKey, null, {batchEvents: true});
@@ -589,7 +562,7 @@ describe('Amplitude', function() {
589562
'[0,1,2,"3"],"nested_array":["a",{"key":"value"},["b"]],"object":{"key":"value"},"nested_object":' +
590563
'{"k":"v","l":[0,1],"o":{"k2":"v2","l2":["e2",{"k3":"v3"}]}}}},"event_properties":{},"uuid":"650407a1-d705-' +
591564
'47a0-8918-b4530ce51f89","library":{"name":"amplitude-js","version":"2.9.0"},"sequence_number":5}]'
592-
localStorage.setItem('amplitude_unsent_identify', existingEvents);
565+
localStorage.setItem('amplitude_unsent_identify_' + apiKey, existingEvents);
593566

594567
var amplitude2 = new Amplitude();
595568
amplitude2.init(apiKey, null, {batchEvents: true});
@@ -620,8 +593,8 @@ describe('Amplitude', function() {
620593
'"event_properties":{},"user_properties":{"$set":{"age":30,"city":"San Francisco, CA"}},"uuid":"' +
621594
'c50e1be4-7976-436a-aa25-d9ee38951082","library":{"name":"amplitude-js","version":"2.9.0"},"sequence_number"' +
622595
':131}]';
623-
localStorage.setItem('amplitude_unsent', existingEvent);
624-
localStorage.setItem('amplitude_unsent_identify', existingIdentify);
596+
localStorage.setItem('amplitude_unsent_' + apiKey, existingEvent);
597+
localStorage.setItem('amplitude_unsent_identify_' + apiKey, existingIdentify);
625598

626599
var amplitude2 = new Amplitude();
627600
amplitude2.init(apiKey, null, {batchEvents: true, eventUploadThreshold: 2});
@@ -657,7 +630,7 @@ describe('Amplitude', function() {
657630
'[0,1,2,"3"],"nested_array":["a",{"key":"value"},["b"]],"object":{"key":"value"},"nested_object":' +
658631
'{"k":"v","l":[0,1],"o":{"k2":"v2","l2":["e2",{"k3":"v3"}]}}},"user_properties":{},"uuid":"650407a1-d705-' +
659632
'47a0-8918-b4530ce51f89","library":{"name":"amplitude-js","version":"2.9.0"},"sequence_number":5}]';
660-
localStorage.setItem('amplitude_unsent', existingEvents);
633+
localStorage.setItem('amplitude_unsent_' + apiKey, existingEvents);
661634

662635
var amplitude2 = new Amplitude();
663636
amplitude2.init(apiKey, null, {

0 commit comments

Comments
 (0)