Skip to content

Commit a079e46

Browse files
committed
test: cover denylisted identity attributes
1 parent 70285bf commit a079e46

2 files changed

Lines changed: 28 additions & 12 deletions

File tree

src/Rokt-Kit.ts

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -468,18 +468,14 @@ function isSelectPlacementsAttributePersistenceDenied(key: string): boolean {
468468
function removeSelectPlacementsAttributePersistenceDeniedAttributes(
469469
attributes: Record<string, unknown> | null | undefined,
470470
): Record<string, unknown> {
471-
const filteredAttributes: Record<string, unknown> = {};
472471
const sourceAttributes = attributes || {};
473-
const attributeKeys = Object.keys(sourceAttributes);
474472

475-
for (let i = 0; i < attributeKeys.length; i++) {
476-
const key = attributeKeys[i];
473+
return Object.keys(sourceAttributes).reduce((filteredAttributes: Record<string, unknown>, key) => {
477474
if (!isSelectPlacementsAttributePersistenceDenied(key)) {
478475
filteredAttributes[key] = sourceAttributes[key];
479476
}
480-
}
481-
482-
return filteredAttributes;
477+
return filteredAttributes;
478+
}, {});
483479
}
484480

485481
function generateIntegrationName(customIntegrationName?: string): string {
@@ -1272,12 +1268,9 @@ class RoktKit implements KitInterface {
12721268
}
12731269

12741270
public setUserAttribute(key: string, value: unknown): string {
1275-
if (isSelectPlacementsAttributePersistenceDenied(key)) {
1276-
this.userAttributes = removeSelectPlacementsAttributePersistenceDeniedAttributes(this.userAttributes);
1277-
return 'Successfully set user attribute for forwarder: ' + name;
1271+
if (!isSelectPlacementsAttributePersistenceDenied(key)) {
1272+
this.userAttributes[key] = value;
12781273
}
1279-
1280-
this.userAttributes[key] = value;
12811274
return 'Successfully set user attribute for forwarder: ' + name;
12821275
}
12831276

test/src/tests.spec.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3106,6 +3106,29 @@ describe('Rokt Forwarder', () => {
31063106
});
31073107
expect((window as any).mParticle.forwarder.filters.filteredUser.getMPID()).toBe('123');
31083108
});
3109+
3110+
it('should not cache denylisted commerce attributes from the filtered user', () => {
3111+
(window as any).mParticle.forwarder.onUserIdentified({
3112+
getAllUserAttributes: function () {
3113+
return {
3114+
confirmationRef: 'previous-order',
3115+
currency: 'USD',
3116+
paymentServiceProvider: 'test-provider',
3117+
'test-attribute': 'test-value',
3118+
};
3119+
},
3120+
getMPID: function () {
3121+
return '123';
3122+
},
3123+
getUserIdentities: function () {
3124+
return { userIdentities: {} };
3125+
},
3126+
});
3127+
3128+
expect((window as any).mParticle.forwarder.userAttributes).toEqual({
3129+
'test-attribute': 'test-value',
3130+
});
3131+
});
31093132
});
31103133

31113134
describe('#workspaceIdSync', () => {

0 commit comments

Comments
 (0)