Skip to content

Commit 462c3d6

Browse files
committed
test: cover placement denylist helpers
1 parent c65962a commit 462c3d6

3 files changed

Lines changed: 52 additions & 48 deletions

File tree

src/Rokt-Kit.ts

Lines changed: 4 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ import type { IUserIdentities } from '@mparticle/web-sdk';
2121

2222
// BaseEvent not re-exported from @mparticle/web-sdk/internal, so we import directly from @mparticle/event-models.
2323
import { BaseEvent } from '@mparticle/event-models';
24+
import {
25+
isSelectPlacementsAttributePersistenceDenied,
26+
removeSelectPlacementsAttributePersistenceDeniedAttributes,
27+
} from './selectPlacementsAttributePersistence';
2428

2529
interface RoktKitSettings {
2630
accountId: string;
@@ -240,32 +244,6 @@ const ROKT_THANK_YOU_JOURNEY_EXTENSION = 'ThankYouPageJourney';
240244
const ROKT_INTEGRATION_SCRIPT_ID = 'rokt-launcher';
241245
const ROKT_THANK_YOU_ELEMENT_SCRIPT_ID = 'rokt-thank-you-element';
242246
const USER_IDENTIFIED_IN_WORKSPACE_KEY = 'userIdentifiedInWorkspace';
243-
const SELECT_PLACEMENTS_ATTRIBUTE_PERSISTENCE_DENY_LIST = [
244-
'billingaddress1',
245-
'billingaddress2',
246-
'billingcity',
247-
'billingstate',
248-
'billingzipcode',
249-
'cartitems',
250-
'ccbin',
251-
'confirmationref',
252-
'conversiontype',
253-
'country',
254-
'couponcode',
255-
'currency',
256-
'language',
257-
'paymentserviceprovider',
258-
'paymentserviceproviderattribute',
259-
'paymenttype',
260-
'shippingaddress1',
261-
'shippingcity',
262-
'shippingcountry',
263-
'shippingmethod',
264-
'shippingstate',
265-
'shippingzipcode',
266-
'totalprice',
267-
];
268-
const SELECT_PLACEMENTS_ATTRIBUTE_PERSISTENCE_DENY_SET = new Set(SELECT_PLACEMENTS_ATTRIBUTE_PERSISTENCE_DENY_LIST);
269247

270248
// Bound on how long selectPlacements will wait for an in-flight Workspace
271249
// IDSync search before proceeding without the userIdentifiedInWorkspace flag.
@@ -462,27 +440,6 @@ function isString(value: unknown): value is string {
462440
return typeof value === 'string';
463441
}
464442

465-
export function isSelectPlacementsAttributePersistenceDenied(key: string): boolean {
466-
return SELECT_PLACEMENTS_ATTRIBUTE_PERSISTENCE_DENY_SET.has(key.toLowerCase());
467-
}
468-
469-
export function removeSelectPlacementsAttributePersistenceDeniedAttributes(
470-
attributes: Record<string, unknown> | null | undefined,
471-
): Record<string, unknown> {
472-
const filteredAttributes: Record<string, unknown> = {};
473-
const sourceAttributes = attributes || {};
474-
const attributeKeys = Object.keys(sourceAttributes);
475-
476-
for (let i = 0; i < attributeKeys.length; i++) {
477-
const key = attributeKeys[i];
478-
if (!isSelectPlacementsAttributePersistenceDenied(key)) {
479-
filteredAttributes[key] = sourceAttributes[key];
480-
}
481-
}
482-
483-
return filteredAttributes;
484-
}
485-
486443
function generateIntegrationName(customIntegrationName?: string): string {
487444
const coreSdkVersion = mp().getVersion();
488445
const kitVersion = process.env.PACKAGE_VERSION;
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
const SELECT_PLACEMENTS_ATTRIBUTE_PERSISTENCE_DENY_LIST = [
2+
'billingaddress1',
3+
'billingaddress2',
4+
'billingcity',
5+
'billingstate',
6+
'billingzipcode',
7+
'cartitems',
8+
'ccbin',
9+
'confirmationref',
10+
'conversiontype',
11+
'country',
12+
'couponcode',
13+
'currency',
14+
'language',
15+
'paymentserviceprovider',
16+
'paymentserviceproviderattribute',
17+
'paymenttype',
18+
'shippingaddress1',
19+
'shippingcity',
20+
'shippingcountry',
21+
'shippingmethod',
22+
'shippingstate',
23+
'shippingzipcode',
24+
'totalprice',
25+
];
26+
const SELECT_PLACEMENTS_ATTRIBUTE_PERSISTENCE_DENY_SET = new Set(SELECT_PLACEMENTS_ATTRIBUTE_PERSISTENCE_DENY_LIST);
27+
28+
export function isSelectPlacementsAttributePersistenceDenied(key: string): boolean {
29+
return SELECT_PLACEMENTS_ATTRIBUTE_PERSISTENCE_DENY_SET.has(key.toLowerCase());
30+
}
31+
32+
export function removeSelectPlacementsAttributePersistenceDeniedAttributes(
33+
attributes: Record<string, unknown> | null | undefined,
34+
): Record<string, unknown> {
35+
const filteredAttributes: Record<string, unknown> = {};
36+
const sourceAttributes = attributes || {};
37+
const attributeKeys = Object.keys(sourceAttributes);
38+
39+
for (let i = 0; i < attributeKeys.length; i++) {
40+
const key = attributeKeys[i];
41+
if (!isSelectPlacementsAttributePersistenceDenied(key)) {
42+
filteredAttributes[key] = sourceAttributes[key];
43+
}
44+
}
45+
46+
return filteredAttributes;
47+
}

test/src/tests.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import '../../src/Rokt-Kit';
44
import {
55
isSelectPlacementsAttributePersistenceDenied,
66
removeSelectPlacementsAttributePersistenceDeniedAttributes,
7-
} from '../../src/Rokt-Kit';
7+
} from '../../src/selectPlacementsAttributePersistence';
88
import { Batch } from '@mparticle/web-sdk/internal';
99

1010
/* eslint-disable @typescript-eslint/no-explicit-any */

0 commit comments

Comments
 (0)