@@ -7,6 +7,32 @@ const getLocalStorage = Utils.getLocalStorage,
77 mParticleAndroid = Utils . mParticleAndroid ,
88 HTTPCodes = Constants . HTTPCodes ;
99
10+ // Alias request test fixtures
11+ const aliasRequestFixture = {
12+ destinationMpid : '101' ,
13+ sourceMpid : '202' ,
14+ startTime : 300 ,
15+ endTime : 400 ,
16+ scope : 'device' ,
17+ } ;
18+
19+ const expectedAliasPayload = {
20+ DestinationMpid : '101' ,
21+ SourceMpid : '202' ,
22+ StartUnixtimeMs : 300 ,
23+ EndUnixtimeMs : 400 ,
24+ } ;
25+
26+ const expectedAliasPayloadWithDeviceScope = JSON . stringify ( {
27+ ...expectedAliasPayload ,
28+ Scope : 'device' ,
29+ } ) ;
30+
31+ const expectedAliasPayloadWithMpidScope = JSON . stringify ( {
32+ ...expectedAliasPayload ,
33+ Scope : 'mpid' ,
34+ } ) ;
35+
1036describe ( 'native-sdk methods' , function ( ) {
1137 beforeEach ( function ( ) {
1238 mParticle . _resetForTests ( MPConfig ) ;
@@ -649,20 +675,36 @@ describe('native-sdk methods', function() {
649675 mParticleAndroidV2Bridge . modifyData . should . equal ( JSONData ) ;
650676 } ) ;
651677
652- it ( 'should send a JSON object to the Android\'s Alias method' , ( ) => {
678+ it ( "should send a JSON object to the Android's Alias method" , ( ) => {
679+ let callbackResult ;
680+
681+ mParticle . Identity . aliasUsers ( aliasRequestFixture , function ( callback ) {
682+ callbackResult = callback ;
683+ } ) ;
684+ mParticleAndroidV2Bridge . aliasUsers . should . equal (
685+ expectedAliasPayloadWithDeviceScope
686+ ) ;
687+
688+ callbackResult . httpCode . should . equal (
689+ HTTPCodes . nativeIdentityRequest
690+ ) ;
691+ callbackResult . message . should . equal (
692+ 'Alias request sent to native sdk'
693+ ) ;
694+ } ) ;
695+
696+ it ( "should send a JSON object with scope to the Android's Alias method when scope is provided" , ( ) => {
653697 let callbackResult ;
654- const aliasRequest = {
655- destinationMpid : '101' ,
656- sourceMpid : '202' ,
657- startTime : 300 ,
658- endTime : 400 ,
698+ const aliasRequestWithMPIDScope = {
699+ ...aliasRequestFixture ,
700+ scope : 'mpid' ,
659701 } ;
660702
661- mParticle . Identity . aliasUsers ( aliasRequest , function ( callback ) {
703+ mParticle . Identity . aliasUsers ( aliasRequestWithMPIDScope , function ( callback ) {
662704 callbackResult = callback ;
663705 } ) ;
664706 mParticleAndroidV2Bridge . aliasUsers . should . equal (
665- '{"DestinationMpid":"101","SourceMpid":"202","StartUnixtimeMs":300,"EndUnixtimeMs":400}'
707+ expectedAliasPayloadWithMpidScope
666708 ) ;
667709
668710 callbackResult . httpCode . should . equal (
@@ -960,16 +1002,10 @@ describe('native-sdk methods', function() {
9601002 mParticleIOSV2Bridge . reset ( ) ;
9611003 } ) ;
9621004
963- it ( ' should send a JSON object to the iOS SDK\ 's Alias method' , ( ) => {
1005+ it ( " should send a JSON object to the iOS SDK's Alias method" , ( ) => {
9641006 let callbackResult ;
965- const aliasRequest = {
966- destinationMpid : '101' ,
967- sourceMpid : '202' ,
968- startTime : 300 ,
969- endTime : 400 ,
970- } ;
9711007
972- mParticle . Identity . aliasUsers ( aliasRequest , function ( callback ) {
1008+ mParticle . Identity . aliasUsers ( aliasRequestFixture , function ( callback ) {
9731009 callbackResult = callback ;
9741010 } ) ;
9751011
@@ -981,9 +1017,37 @@ describe('native-sdk methods', function() {
9811017 ) ;
9821018 JSON . stringify (
9831019 JSON . parse ( mParticleIOSV2Bridge . data [ 0 ] ) . value
984- ) . should . equal (
985- '{"DestinationMpid":"101","SourceMpid":"202","StartUnixtimeMs":300,"EndUnixtimeMs":400}'
1020+ ) . should . equal ( expectedAliasPayloadWithDeviceScope ) ;
1021+ mParticleIOSV2Bridge . reset ( ) ;
1022+
1023+ callbackResult . httpCode . should . equal (
1024+ HTTPCodes . nativeIdentityRequest
1025+ ) ;
1026+ callbackResult . message . should . equal (
1027+ 'Alias request sent to native sdk'
1028+ ) ;
1029+ } ) ;
1030+
1031+ it ( "should send a JSON object with scope to the iOS SDK's Alias method when scope is provided" , ( ) => {
1032+ let callbackResult ;
1033+ const aliasRequestWithMPIDScope = {
1034+ ...aliasRequestFixture ,
1035+ scope : 'mpid' ,
1036+ } ;
1037+
1038+ mParticle . Identity . aliasUsers ( aliasRequestWithMPIDScope , function ( callback ) {
1039+ callbackResult = callback ;
1040+ } ) ;
1041+
1042+ JSON . parse ( mParticleIOSV2Bridge . data [ 0 ] ) . should . have . properties (
1043+ [ 'path' , 'value' ]
9861044 ) ;
1045+ JSON . parse ( mParticleIOSV2Bridge . data [ 0 ] ) . path . should . equal (
1046+ 'aliasUsers'
1047+ ) ;
1048+ JSON . stringify (
1049+ JSON . parse ( mParticleIOSV2Bridge . data [ 0 ] ) . value
1050+ ) . should . equal ( expectedAliasPayloadWithMpidScope ) ;
9871051 mParticleIOSV2Bridge . reset ( ) ;
9881052
9891053 callbackResult . httpCode . should . equal (
0 commit comments