|
1 | 1 | import packageJson from '../../package.json'; |
2 | 2 | const packageVersion = packageJson.version; |
3 | 3 | import '../../src/Rokt-Kit'; |
| 4 | +import { |
| 5 | + isSelectPlacementsAttributePersistenceDenied, |
| 6 | + removeSelectPlacementsAttributePersistenceDeniedAttributes, |
| 7 | +} from '../../src/selectPlacementsAttributePersistence'; |
4 | 8 | import { Batch } from '@mparticle/web-sdk/internal'; |
5 | 9 |
|
6 | 10 | /* eslint-disable @typescript-eslint/no-explicit-any */ |
@@ -1098,6 +1102,126 @@ describe('Rokt Forwarder', () => { |
1098 | 1102 | }, |
1099 | 1103 | }); |
1100 | 1104 | }); |
| 1105 | + |
| 1106 | + it('should not send denylisted commerce attributes from the cached user attributes', async () => { |
| 1107 | + await (window as any).mParticle.forwarder.init( |
| 1108 | + { |
| 1109 | + accountId: '123456', |
| 1110 | + }, |
| 1111 | + reportService.cb, |
| 1112 | + true, |
| 1113 | + null, |
| 1114 | + { |
| 1115 | + confirmationRef: 'previous-order', |
| 1116 | + conversionType: 'purchase', |
| 1117 | + PaymentServiceProviderAttribute: 'cached-provider', |
| 1118 | + totalPrice: '10.00', |
| 1119 | + couponCode: 'SAVE10', |
| 1120 | + shippingMethod: 'ground', |
| 1121 | + loyaltyTier: 'gold', |
| 1122 | + }, |
| 1123 | + ); |
| 1124 | + |
| 1125 | + await (window as any).mParticle.forwarder.selectPlacements({ |
| 1126 | + identifier: 'test-placement', |
| 1127 | + attributes: { |
| 1128 | + page: 'checkout', |
| 1129 | + }, |
| 1130 | + }); |
| 1131 | + |
| 1132 | + expect((window as any).Rokt.selectPlacementsCalled).toBe(true); |
| 1133 | + expect((window as any).Rokt.selectPlacementsOptions).toEqual({ |
| 1134 | + identifier: 'test-placement', |
| 1135 | + attributes: { |
| 1136 | + loyaltyTier: 'gold', |
| 1137 | + page: 'checkout', |
| 1138 | + mpid: '123', |
| 1139 | + }, |
| 1140 | + }); |
| 1141 | + expect((window as any).mParticle.forwarder.userAttributes).toEqual({ |
| 1142 | + loyaltyTier: 'gold', |
| 1143 | + page: 'checkout', |
| 1144 | + }); |
| 1145 | + }); |
| 1146 | + |
| 1147 | + it('should allow explicit commerce attributes for the current call without caching them', async () => { |
| 1148 | + await (window as any).mParticle.forwarder.init( |
| 1149 | + { |
| 1150 | + accountId: '123456', |
| 1151 | + }, |
| 1152 | + reportService.cb, |
| 1153 | + true, |
| 1154 | + null, |
| 1155 | + { |
| 1156 | + loyaltyTier: 'gold', |
| 1157 | + }, |
| 1158 | + ); |
| 1159 | + |
| 1160 | + await (window as any).mParticle.forwarder.selectPlacements({ |
| 1161 | + identifier: 'test-placement', |
| 1162 | + attributes: { |
| 1163 | + confirmationRef: 'current-order', |
| 1164 | + conversionType: 'purchase', |
| 1165 | + paymentServiceProviderAttribute: 'current-provider', |
| 1166 | + totalPrice: '10.00', |
| 1167 | + couponCode: 'SAVE10', |
| 1168 | + shippingMethod: 'ground', |
| 1169 | + page: 'checkout', |
| 1170 | + }, |
| 1171 | + }); |
| 1172 | + |
| 1173 | + expect((window as any).Rokt.selectPlacementsCalled).toBe(true); |
| 1174 | + expect((window as any).Rokt.selectPlacementsOptions).toEqual({ |
| 1175 | + identifier: 'test-placement', |
| 1176 | + attributes: { |
| 1177 | + loyaltyTier: 'gold', |
| 1178 | + confirmationRef: 'current-order', |
| 1179 | + conversionType: 'purchase', |
| 1180 | + paymentServiceProviderAttribute: 'current-provider', |
| 1181 | + totalPrice: '10.00', |
| 1182 | + couponCode: 'SAVE10', |
| 1183 | + shippingMethod: 'ground', |
| 1184 | + page: 'checkout', |
| 1185 | + mpid: '123', |
| 1186 | + }, |
| 1187 | + }); |
| 1188 | + expect((window as any).mParticle.forwarder.userAttributes).toEqual({ |
| 1189 | + loyaltyTier: 'gold', |
| 1190 | + page: 'checkout', |
| 1191 | + }); |
| 1192 | + }); |
| 1193 | + |
| 1194 | + it('should not cache denylisted commerce attributes set through setUserAttribute', async () => { |
| 1195 | + await (window as any).mParticle.forwarder.init( |
| 1196 | + { |
| 1197 | + accountId: '123456', |
| 1198 | + }, |
| 1199 | + reportService.cb, |
| 1200 | + true, |
| 1201 | + null, |
| 1202 | + {}, |
| 1203 | + ); |
| 1204 | + |
| 1205 | + (window as any).mParticle.forwarder.setUserAttribute('paymentServiceProviderAttribute', 'cached-provider'); |
| 1206 | + (window as any).mParticle.forwarder.setUserAttribute('favoriteStore', 'test-store'); |
| 1207 | + |
| 1208 | + await (window as any).mParticle.forwarder.selectPlacements({ |
| 1209 | + identifier: 'test-placement', |
| 1210 | + attributes: {}, |
| 1211 | + }); |
| 1212 | + |
| 1213 | + expect((window as any).Rokt.selectPlacementsCalled).toBe(true); |
| 1214 | + expect((window as any).Rokt.selectPlacementsOptions).toEqual({ |
| 1215 | + identifier: 'test-placement', |
| 1216 | + attributes: { |
| 1217 | + favoriteStore: 'test-store', |
| 1218 | + mpid: '123', |
| 1219 | + }, |
| 1220 | + }); |
| 1221 | + expect((window as any).mParticle.forwarder.userAttributes).toEqual({ |
| 1222 | + favoriteStore: 'test-store', |
| 1223 | + }); |
| 1224 | + }); |
1101 | 1225 | }); |
1102 | 1226 |
|
1103 | 1227 | describe('Identity handling', () => { |
@@ -2989,6 +3113,30 @@ describe('Rokt Forwarder', () => { |
2989 | 3113 | }); |
2990 | 3114 | expect((window as any).mParticle.forwarder.filters.filteredUser.getMPID()).toBe('123'); |
2991 | 3115 | }); |
| 3116 | + |
| 3117 | + it('should not cache denylisted commerce attributes from the filtered user', () => { |
| 3118 | + (window as any).mParticle.forwarder.onUserIdentified({ |
| 3119 | + getAllUserAttributes: function () { |
| 3120 | + return { |
| 3121 | + confirmationRef: 'previous-order', |
| 3122 | + conversionType: 'purchase', |
| 3123 | + currency: 'USD', |
| 3124 | + paymentServiceProvider: 'test-provider', |
| 3125 | + 'test-attribute': 'test-value', |
| 3126 | + }; |
| 3127 | + }, |
| 3128 | + getMPID: function () { |
| 3129 | + return '123'; |
| 3130 | + }, |
| 3131 | + getUserIdentities: function () { |
| 3132 | + return { userIdentities: {} }; |
| 3133 | + }, |
| 3134 | + }); |
| 3135 | + |
| 3136 | + expect((window as any).mParticle.forwarder.userAttributes).toEqual({ |
| 3137 | + 'test-attribute': 'test-value', |
| 3138 | + }); |
| 3139 | + }); |
2992 | 3140 | }); |
2993 | 3141 |
|
2994 | 3142 | describe('#workspaceIdSync', () => { |
@@ -6189,6 +6337,50 @@ describe('Rokt Forwarder', () => { |
6189 | 6337 | }); |
6190 | 6338 | }); |
6191 | 6339 |
|
| 6340 | + describe('#isSelectPlacementsAttributePersistenceDenied', () => { |
| 6341 | + it('should identify denylisted attributes case-insensitively', () => { |
| 6342 | + expect(isSelectPlacementsAttributePersistenceDenied('confirmationref')).toBe(true); |
| 6343 | + expect(isSelectPlacementsAttributePersistenceDenied('confirmationRef')).toBe(true); |
| 6344 | + expect(isSelectPlacementsAttributePersistenceDenied('CONFIRMATIONREF')).toBe(true); |
| 6345 | + expect(isSelectPlacementsAttributePersistenceDenied('paymentServiceProvider')).toBe(true); |
| 6346 | + expect(isSelectPlacementsAttributePersistenceDenied('cartItems')).toBe(true); |
| 6347 | + expect(isSelectPlacementsAttributePersistenceDenied('conversionType')).toBe(true); |
| 6348 | + }); |
| 6349 | + |
| 6350 | + it('should return false for attributes that are not denylisted', () => { |
| 6351 | + expect(isSelectPlacementsAttributePersistenceDenied('loyaltyTier')).toBe(false); |
| 6352 | + expect(isSelectPlacementsAttributePersistenceDenied('favoriteStore')).toBe(false); |
| 6353 | + }); |
| 6354 | + }); |
| 6355 | + |
| 6356 | + describe('#removeSelectPlacementsAttributePersistenceDeniedAttributes', () => { |
| 6357 | + it('should remove denylisted attributes case-insensitively', () => { |
| 6358 | + const attributes = { |
| 6359 | + confirmationRef: 'previous-order', |
| 6360 | + PaymentServiceProvider: 'test-provider', |
| 6361 | + cartItems: [{ sku: 'test-sku' }], |
| 6362 | + conversionType: 'purchase', |
| 6363 | + loyaltyTier: 'gold', |
| 6364 | + }; |
| 6365 | + |
| 6366 | + expect(removeSelectPlacementsAttributePersistenceDeniedAttributes(attributes)).toEqual({ |
| 6367 | + loyaltyTier: 'gold', |
| 6368 | + }); |
| 6369 | + expect(attributes).toEqual({ |
| 6370 | + confirmationRef: 'previous-order', |
| 6371 | + PaymentServiceProvider: 'test-provider', |
| 6372 | + cartItems: [{ sku: 'test-sku' }], |
| 6373 | + conversionType: 'purchase', |
| 6374 | + loyaltyTier: 'gold', |
| 6375 | + }); |
| 6376 | + }); |
| 6377 | + |
| 6378 | + it('should return an empty object for null or undefined attributes', () => { |
| 6379 | + expect(removeSelectPlacementsAttributePersistenceDeniedAttributes(null)).toEqual({}); |
| 6380 | + expect(removeSelectPlacementsAttributePersistenceDeniedAttributes(undefined)).toEqual({}); |
| 6381 | + }); |
| 6382 | + }); |
| 6383 | + |
6192 | 6384 | describe('#hashEventMessage', () => { |
6193 | 6385 | it('should hash event message using generateHash in the proper order', () => { |
6194 | 6386 | const eventName = 'Test Event'; |
|
0 commit comments