-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update unit tests and implement identity handling
- Loading branch information
Showing
4 changed files
with
83 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,7 @@ | ||
/* eslint-disable no-undef*/ | ||
describe('ID5 Forwarder', function () { | ||
// -------------------DO NOT EDIT ANYTHING BELOW THIS LINE----------------------- | ||
var MessageType = { | ||
SessionStart: 1, | ||
SessionEnd: 2, | ||
PageView: 3, | ||
PageEvent: 4, | ||
CrashReport: 5, | ||
OptOut: 6, | ||
AppStateTransition: 10, | ||
Profile: 14, | ||
Commerce: 16, | ||
Media: 20, | ||
UserAttributeChange: 17, | ||
UserIdentityChange: 18, | ||
}, | ||
EventType = { | ||
Unknown: 0, | ||
Navigation: 1, | ||
Location: 2, | ||
Search: 3, | ||
Transaction: 4, | ||
UserContent: 5, | ||
UserPreference: 6, | ||
Social: 7, | ||
Other: 8, | ||
Media: 9, | ||
getName: function() { | ||
return 'blahblah'; | ||
} | ||
}, | ||
ProductActionType = { | ||
Unknown: 0, | ||
AddToCart: 1, | ||
RemoveFromCart: 2, | ||
Checkout: 3, | ||
CheckoutOption: 4, | ||
Click: 5, | ||
ViewDetail: 6, | ||
Purchase: 7, | ||
Refund: 8, | ||
AddToWishlist: 9, | ||
RemoveFromWishlist: 10 | ||
}, | ||
IdentityType = { | ||
Other: 0, | ||
CustomerId: 1, | ||
Facebook: 2, | ||
Twitter: 3, | ||
Google: 4, | ||
Microsoft: 5, | ||
Yahoo: 6, | ||
Email: 7, | ||
FacebookCustomAudienceId: 9, | ||
Other2: 10, | ||
Other3: 11, | ||
Other4: 12, | ||
Other5: 13, | ||
Other6: 14, | ||
Other7: 15, | ||
Other8: 16, | ||
Other9: 17, | ||
Other10: 18, | ||
MobileNumber: 19, | ||
PhoneNumber2: 20, | ||
PhoneNumber3: 21, | ||
}, | ||
ReportingService = function () { | ||
var ReportingService = function () { | ||
var self = this; | ||
|
||
this.id = null; | ||
|
@@ -84,7 +19,7 @@ describe('ID5 Forwarder', function () { | |
}, | ||
reportService = new ReportingService(); | ||
|
||
// -------------------DO NOT EDIT ANYTHING ABOVE THIS LINE----------------------- | ||
// -------------------DO NOT EDIT ANYTHING ABOVE THIS LINE----------------------- | ||
// -------------------START EDITING BELOW:----------------------- | ||
// -------------------mParticle stubs - Add any additional stubbing to our methods as needed----------------------- | ||
var userAttributes = {}; | ||
|
@@ -106,14 +41,15 @@ describe('ID5 Forwarder', function () { | |
} | ||
}; | ||
// -------------------START EDITING BELOW:----------------------- | ||
var MockID5Forwarder = function() { | ||
var MockID5 = function() { | ||
var self = this; | ||
|
||
// create properties for each type of event you want tracked, see below for examples | ||
this.trackCustomEventCalled = false; | ||
this.logPurchaseEventCalled = false; | ||
this.isInitialized = false; | ||
this.initCalled = false; | ||
this.numberOfInitsCalled = 0; | ||
this.getUserIdCalled = false; | ||
|
||
this.pd = null; | ||
|
@@ -123,61 +59,86 @@ describe('ID5 Forwarder', function () { | |
// stub your different methods to ensure they are being called properly | ||
this.init = function(id5Options) { | ||
self.initCalled = true; | ||
self.numberOfInitsCalled += 1; | ||
self.partnerId = id5Options.partnerId; | ||
self.pd = id5Options.pd | ||
return this; | ||
}; | ||
|
||
this.onAvailable = function(callback) { | ||
return callback | ||
return callback(self) | ||
}; | ||
|
||
this.getUserId = function() { | ||
self.getUserIdCalled = true; | ||
return 'ID5*testtesttesttest' | ||
} | ||
|
||
return self; | ||
}; | ||
|
||
before(function () { | ||
|
||
}); | ||
|
||
beforeEach(function() { | ||
window.ID5 = new MockID5Forwarder(); | ||
window.ID5 = new MockID5(); | ||
// Include any specific settings that is required for initializing your SDK here | ||
var sdkSettings = { | ||
partnerId: 1234, | ||
}; | ||
// You may require userAttributes or userIdentities to be passed into initialization | ||
var userAttributes = { | ||
color: 'green' | ||
}; | ||
|
||
var userIdentities = [{ | ||
Identity: 'customerId', | ||
Type: IdentityType.CustomerId | ||
}, { | ||
Identity: 'email', | ||
Type: IdentityType.Email | ||
}, { | ||
Identity: 'mobile_number', | ||
Type: IdentityType.MobileNumber | ||
}]; | ||
|
||
|
||
// The third argument here is a boolean to indicate that the integration is in test mode to avoid loading any third party scripts. Do not change this value. | ||
mParticle.forwarder.init(sdkSettings, reportService.cb, true, null, userAttributes, userIdentities); | ||
mParticle.forwarder.init(sdkSettings, reportService.cb, true); | ||
}); | ||
|
||
|
||
it ('should load the script into the document during initialization', function(done) { | ||
window.ID5 = new MockID5Forwarder(); | ||
mParticle.forwarder.init({ | ||
partnerId: 1234, | ||
describe('Initialization', function() { | ||
it('should call ID5.init', function(done) { | ||
window.ID5.initCalled.should.equal(true); | ||
done(); | ||
}); | ||
document.scripts[0].src.should.equal('https://cdn.id5-sync.com/api/1.0/id5-api.js'); | ||
done(); | ||
}); | ||
|
||
it('should call getUserId', function(done) { | ||
window.ID5.getUserIdCalled.should.equal(true); | ||
done(); | ||
}); | ||
}) | ||
|
||
describe('Identity Handling', function() { | ||
it('should call ID5.init twice on userLoginComplete', function(done){ | ||
var user = { | ||
getUserIdentities: function () { | ||
return { | ||
userIdentities: { | ||
email: '[email protected]', | ||
}, | ||
}; | ||
}, | ||
}; | ||
mParticle.forwarder.onLoginComplete(user); | ||
|
||
window.ID5.numberOfInitsCalled.should.equal(2); | ||
done(); | ||
}); | ||
|
||
it('should call ID5.init twice on userLogoutComplete', function(done){ | ||
var user = { | ||
getUserIdentities: function () { | ||
return { | ||
userIdentities: { | ||
email: '[email protected]', | ||
}, | ||
}; | ||
}, | ||
}; | ||
mParticle.forwarder.onLoginComplete(user); | ||
|
||
window.ID5.numberOfInitsCalled.should.equal(2); | ||
done(); | ||
}); | ||
}) | ||
|
||
|
||
describe('Common Functions', function() { | ||
it ('should log a user attribute when logId5 is called', function(done) { | ||
|