Skip to content

Commit b9179e1

Browse files
committed
chore: reverted tests for identity and native sdk, removed unused arguments from mParticleUserCart
1 parent f17a111 commit b9179e1

6 files changed

Lines changed: 187 additions & 17 deletions

File tree

src/identity-user-interfaces.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ export interface IdentityModifyResultBody {
115115
}
116116

117117
export interface mParticleUserCart {
118-
add(product: SDKProduct | SDKProduct[], logEvent: boolean): void;
119-
remove(product: SDKProduct | SDKProduct[], logEvent: boolean): void;
118+
add(): void;
119+
remove(): void;
120120
clear(): void;
121121
getCartProducts(): SDKProduct[];
122122
}

src/identity.interfaces.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,5 +206,5 @@ export interface IIdentity {
206206
/**
207207
* @deprecated
208208
*/
209-
mParticleUserCart(mpid: MPID): mParticleUserCart;
209+
mParticleUserCart(): mParticleUserCart;
210210
}

src/identity.js

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,7 +1215,7 @@ export default function Identity(mpInstance) {
12151215
mpInstance.Logger.warning(
12161216
'Deprecated function Identity.getCurrentUser().getCart() will be removed in future releases'
12171217
);
1218-
return self.mParticleUserCart(mpid);
1218+
return self.mParticleUserCart();
12191219
},
12201220

12211221
/**
@@ -1286,18 +1286,14 @@ export default function Identity(mpInstance) {
12861286
* @class mParticle.Identity.getCurrentUser().getCart()
12871287
* @deprecated
12881288
*/
1289-
// eslint-disable-next-line no-unused-vars
1290-
this.mParticleUserCart = function(mpid) {
1289+
this.mParticleUserCart = function() {
12911290
return {
12921291
/**
12931292
* Adds a cart product to the user cart
12941293
* @method add
1295-
* @param {Object} product the product
1296-
* @param {Boolean} [logEvent] a boolean to log adding of the cart object. If blank, no logging occurs.
12971294
* @deprecated
12981295
*/
1299-
// eslint-disable-next-line no-unused-vars
1300-
add: function(product, logEvent) {
1296+
add: function() {
13011297
mpInstance.Logger.warning(
13021298
generateDeprecationMessage(
13031299
'Identity.getCurrentUser().getCart().add()',
@@ -1310,12 +1306,9 @@ export default function Identity(mpInstance) {
13101306
/**
13111307
* Removes a cart product from the current user cart
13121308
* @method remove
1313-
* @param {Object} product the product
1314-
* @param {Boolean} [logEvent] a boolean to log adding of the cart object. If blank, no logging occurs.
13151309
* @deprecated
13161310
*/
1317-
// eslint-disable-next-line no-unused-vars
1318-
remove: function(product, logEvent) {
1311+
remove: function() {
13191312
mpInstance.Logger.warning(
13201313
generateDeprecationMessage(
13211314
'Identity.getCurrentUser().getCart().remove()',

test/src/tests-eCommerce.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1521,10 +1521,11 @@ describe('eCommerce', function() {
15211521

15221522
bond.called.should.eql(true);
15231523
bond.getCalls()[0].args[0].should.eql(
1524-
'Deprecated function eCommerce.Cart.add()'
1524+
'eCommerce.Cart.add() has been deprecated. Please use the alternate method: eCommerce.logProductAction(). See - https://docs.mparticle.com/developers/sdk/web/commerce-tracking'
15251525
);
15261526
})
15271527
});
1528+
15281529
it('should deprecate remove', function() {
15291530
waitForCondition(hasIdentifyReturned)
15301531
.then(() => {
@@ -1540,7 +1541,7 @@ describe('eCommerce', function() {
15401541

15411542
bond.called.should.eql(true);
15421543
bond.getCalls()[0].args[0].should.eql(
1543-
'Deprecated function eCommerce.Cart.remove()'
1544+
'eCommerce.Cart.remove() has been deprecated. Please use the alternate method: eCommerce.logProductAction(). See - https://docs.mparticle.com/developers/sdk/web/commerce-tracking'
15441545
);
15451546
})
15461547
});
@@ -1554,7 +1555,7 @@ describe('eCommerce', function() {
15541555

15551556
bond.called.should.eql(true);
15561557
bond.getCalls()[0].args[0].should.eql(
1557-
'Deprecated function eCommerce.Cart.clear()'
1558+
'eCommerce.Cart.clear() has been deprecated. See - https://docs.mparticle.com/developers/sdk/web/commerce-tracking'
15581559
);
15591560
})
15601561
});

test/src/tests-identity.ts

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2058,6 +2058,127 @@ describe('identity', function() {
20582058
done();
20592059
});
20602060

2061+
it("should find the related MPID's cookies when given a UI with fewer IDs when passed to login, logout, and identify, and then log events with updated cookies", async () => {
2062+
mParticle._resetForTests(MPConfig);
2063+
fetchMock.restore();
2064+
const user1: IdentityApiData = {
2065+
userIdentities: {
2066+
customerid: 'customerid1',
2067+
},
2068+
};
2069+
2070+
const user1modified: IdentityApiData = {
2071+
userIdentities: {
2072+
email: 'email2@test.com',
2073+
},
2074+
};
2075+
2076+
fetchMockSuccess(urls.events, {});
2077+
fetchMockSuccess(urls.identify, {
2078+
context: null,
2079+
matched_identities: {
2080+
device_application_stamp: 'my-das',
2081+
},
2082+
is_ephemeral: true,
2083+
mpid: testMPID,
2084+
is_logged_in: false,
2085+
});
2086+
2087+
mParticle.config.identifyRequest = user1;
2088+
2089+
mParticle.init(apiKey, window.mParticle.config);
2090+
2091+
fetchMockSuccess(urls.modify, {
2092+
change_results: [
2093+
{
2094+
identity_type: 'email',
2095+
modified_mpid: testMPID,
2096+
},
2097+
],
2098+
});
2099+
2100+
await waitForCondition(hasIdentifyReturned)
2101+
mParticle.Identity.modify(user1modified);
2102+
// Should contain the following calls:
2103+
// 1 for the initial identify
2104+
// 3 for the events (Session Start, UAT and UIC)
2105+
// 1 for the modify
2106+
// 1 for the UIC event
2107+
await waitForCondition(hasIdentityCallInflightReturned)
2108+
expect(fetchMock.calls().length).to.equal(6);
2109+
2110+
// This will add a new UAC Event to the call
2111+
mParticle.Identity.getCurrentUser().setUserAttribute('foo1', 'bar1');
2112+
expect(fetchMock.calls().length).to.equal(7);
2113+
2114+
// This will add a new custom event to the call
2115+
mParticle.logEvent('Test Event 1');
2116+
expect(fetchMock.calls().length).to.equal(8);
2117+
2118+
const testEvent1Batch = JSON.parse(fetchMock.calls()[7][1].body as string);
2119+
2120+
expect(testEvent1Batch.user_attributes).to.deep.equal({ 'foo1': 'bar1' });
2121+
expect(testEvent1Batch.user_identities).to.deep.equal({
2122+
'customer_id': 'customerid1',
2123+
'email': 'email2@test.com'
2124+
});
2125+
2126+
const user2 = {
2127+
userIdentities: {
2128+
customerid: 'customerid2',
2129+
},
2130+
};
2131+
2132+
fetchMockSuccess(urls.logout, {
2133+
mpid: 'logged-out-user',
2134+
is_logged_in: true,
2135+
});
2136+
2137+
mParticle.Identity.logout(user2);
2138+
2139+
await waitForCondition(hasLogOutReturned)
2140+
2141+
// This will add the following new calls:
2142+
// 1 for the logout
2143+
// 1 for the UIC event
2144+
// 1 for Test Event 2
2145+
mParticle.logEvent('Test Event 2');
2146+
2147+
expect(fetchMock.calls().length).to.equal(11);
2148+
2149+
const testEvent2Batch = JSON.parse(fetchMock.calls()[10][1].body as string);
2150+
2151+
Object.keys(testEvent2Batch.user_attributes).length.should.equal(0);
2152+
testEvent2Batch.user_identities.should.have.property(
2153+
'customer_id',
2154+
'customerid2'
2155+
);
2156+
2157+
fetchMockSuccess(urls.login, {
2158+
mpid: 'testMPID',
2159+
is_logged_in: true,
2160+
});
2161+
2162+
mParticle.Identity.login(user1);
2163+
await waitForCondition(() => {
2164+
return mParticle.Identity.getCurrentUser().getMPID() === 'testMPID';
2165+
})
2166+
2167+
// This will add the following new calls:
2168+
// 1 for the login
2169+
// 1 for Test Event 3
2170+
mParticle.logEvent('Test Event 3');
2171+
expect(fetchMock.calls().length).to.equal(13);
2172+
2173+
const testEvent3Batch = JSON.parse(fetchMock.calls()[12][1].body as string);
2174+
2175+
expect(testEvent3Batch.user_attributes).to.deep.equal({'foo1': 'bar1'});
2176+
expect(testEvent3Batch.user_identities).to.deep.equal({
2177+
'customer_id': 'customerid1',
2178+
'email': 'email2@test.com'
2179+
});
2180+
});
2181+
20612182
it('should add new MPIDs to cookie structure when initializing new identity requests, returning an existing mpid when reinitializing with a previous identity', async () => {
20622183
mParticle._resetForTests(MPConfig);
20632184

test/src/tests-native-sdk.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,6 +1105,61 @@ describe('native-sdk methods', function() {
11051105
done();
11061106
});
11071107

1108+
it('should send an event with a product list when calling logPurchase', function(done) {
1109+
const product = mParticle.eCommerce.createProduct(
1110+
'product1',
1111+
'sku',
1112+
10,
1113+
1
1114+
);
1115+
const product2 = mParticle.eCommerce.createProduct(
1116+
'product2',
1117+
'sku',
1118+
10,
1119+
1
1120+
);
1121+
mParticle.eCommerce.logProductAction(mParticle.ProductActionType.AddToCart, [product, product2]);
1122+
1123+
const transactionAttributes = mParticle.eCommerce.createTransactionAttributes(
1124+
'TAid1',
1125+
'aff1',
1126+
'coupon',
1127+
1798,
1128+
10,
1129+
5
1130+
);
1131+
const clearCartBoolean = true;
1132+
const customAttributes = { value: 10 };
1133+
const customFlags = { foo: 'bar' };
1134+
mParticleIOSV2Bridge.data = [];
1135+
mParticle.eCommerce.logPurchase(
1136+
transactionAttributes,
1137+
[product, product2],
1138+
clearCartBoolean,
1139+
customAttributes,
1140+
customFlags
1141+
);
1142+
1143+
JSON.parse(mParticleIOSV2Bridge.data[0]).path.should.equal(
1144+
'logEvent'
1145+
);
1146+
JSON.parse(
1147+
mParticleIOSV2Bridge.data[0]
1148+
).value.ProductAction.ProductList.length.should.equal(2);
1149+
JSON.parse(
1150+
mParticleIOSV2Bridge.data[0]
1151+
).value.ProductAction.ProductList[0].Name.should.equal(
1152+
'product1'
1153+
);
1154+
JSON.parse(
1155+
mParticleIOSV2Bridge.data[0]
1156+
).value.ProductAction.ProductList[1].Name.should.equal(
1157+
'product2'
1158+
);
1159+
1160+
done();
1161+
});
1162+
11081163
it('should invoke upload on iOS SDK', function(done) {
11091164
mParticle.upload();
11101165

0 commit comments

Comments
 (0)