Skip to content

Commit c65962a

Browse files
committed
export functions and add unit tests
1 parent 05edbb0 commit c65962a

2 files changed

Lines changed: 50 additions & 2 deletions

File tree

src/Rokt-Kit.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -462,11 +462,11 @@ function isString(value: unknown): value is string {
462462
return typeof value === 'string';
463463
}
464464

465-
function isSelectPlacementsAttributePersistenceDenied(key: string): boolean {
465+
export function isSelectPlacementsAttributePersistenceDenied(key: string): boolean {
466466
return SELECT_PLACEMENTS_ATTRIBUTE_PERSISTENCE_DENY_SET.has(key.toLowerCase());
467467
}
468468

469-
function removeSelectPlacementsAttributePersistenceDeniedAttributes(
469+
export function removeSelectPlacementsAttributePersistenceDeniedAttributes(
470470
attributes: Record<string, unknown> | null | undefined,
471471
): Record<string, unknown> {
472472
const filteredAttributes: Record<string, unknown> = {};

test/src/tests.spec.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import packageJson from '../../package.json';
22
const packageVersion = packageJson.version;
33
import '../../src/Rokt-Kit';
4+
import {
5+
isSelectPlacementsAttributePersistenceDenied,
6+
removeSelectPlacementsAttributePersistenceDeniedAttributes,
7+
} from '../../src/Rokt-Kit';
48
import { Batch } from '@mparticle/web-sdk/internal';
59

610
/* eslint-disable @typescript-eslint/no-explicit-any */
@@ -6107,6 +6111,50 @@ describe('Rokt Forwarder', () => {
61076111
});
61086112
});
61096113

6114+
describe('#isSelectPlacementsAttributePersistenceDenied', () => {
6115+
it('should identify denylisted attributes case-insensitively', () => {
6116+
expect(isSelectPlacementsAttributePersistenceDenied('confirmationref')).toBe(true);
6117+
expect(isSelectPlacementsAttributePersistenceDenied('confirmationRef')).toBe(true);
6118+
expect(isSelectPlacementsAttributePersistenceDenied('CONFIRMATIONREF')).toBe(true);
6119+
expect(isSelectPlacementsAttributePersistenceDenied('paymentServiceProvider')).toBe(true);
6120+
expect(isSelectPlacementsAttributePersistenceDenied('cartItems')).toBe(true);
6121+
expect(isSelectPlacementsAttributePersistenceDenied('conversionType')).toBe(true);
6122+
});
6123+
6124+
it('should return false for attributes that are not denylisted', () => {
6125+
expect(isSelectPlacementsAttributePersistenceDenied('loyaltyTier')).toBe(false);
6126+
expect(isSelectPlacementsAttributePersistenceDenied('favoriteStore')).toBe(false);
6127+
});
6128+
});
6129+
6130+
describe('#removeSelectPlacementsAttributePersistenceDeniedAttributes', () => {
6131+
it('should remove denylisted attributes case-insensitively', () => {
6132+
const attributes = {
6133+
confirmationRef: 'previous-order',
6134+
PaymentServiceProvider: 'test-provider',
6135+
cartItems: [{ sku: 'test-sku' }],
6136+
conversionType: 'purchase',
6137+
loyaltyTier: 'gold',
6138+
};
6139+
6140+
expect(removeSelectPlacementsAttributePersistenceDeniedAttributes(attributes)).toEqual({
6141+
loyaltyTier: 'gold',
6142+
});
6143+
expect(attributes).toEqual({
6144+
confirmationRef: 'previous-order',
6145+
PaymentServiceProvider: 'test-provider',
6146+
cartItems: [{ sku: 'test-sku' }],
6147+
conversionType: 'purchase',
6148+
loyaltyTier: 'gold',
6149+
});
6150+
});
6151+
6152+
it('should return an empty object for null or undefined attributes', () => {
6153+
expect(removeSelectPlacementsAttributePersistenceDeniedAttributes(null)).toEqual({});
6154+
expect(removeSelectPlacementsAttributePersistenceDeniedAttributes(undefined)).toEqual({});
6155+
});
6156+
});
6157+
61106158
describe('#hashEventMessage', () => {
61116159
it('should hash event message using generateHash in the proper order', () => {
61126160
const eventName = 'Test Event';

0 commit comments

Comments
 (0)