Skip to content

Commit 03682bd

Browse files
committed
chore: address comment
1 parent 0836057 commit 03682bd

1 file changed

Lines changed: 24 additions & 24 deletions

File tree

  • packages/analytics-js-integrations/__tests__/integrations/Braze

packages/analytics-js-integrations/__tests__/integrations/Braze/browser.test.js

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,8 +1111,8 @@ describe('track - recommended ecommerce events', () => {
11111111
campaign: 'summer',
11121112
});
11131113

1114-
expect(window.braze.logCustomEvent).toHaveBeenCalledTimes(1);
1115-
expect(window.braze.logCustomEvent).toHaveBeenCalledWith('ecommerce.product_viewed', {
1114+
expect(globalThis.braze.logCustomEvent).toHaveBeenCalledTimes(1);
1115+
expect(globalThis.braze.logCustomEvent).toHaveBeenCalledWith('ecommerce.product_viewed', {
11161116
product_id: 'p1',
11171117
product_name: 'Game',
11181118
variant_id: 'v1',
@@ -1141,7 +1141,7 @@ describe('track - recommended ecommerce events', () => {
11411141
list_id: 'wishlist',
11421142
});
11431143

1144-
expect(window.braze.logCustomEvent).toHaveBeenCalledWith('ecommerce.cart_updated', {
1144+
expect(globalThis.braze.logCustomEvent).toHaveBeenCalledWith('ecommerce.cart_updated', {
11451145
cart_id: 'c1',
11461146
currency: 'USD',
11471147
source: 'web',
@@ -1173,7 +1173,7 @@ describe('track - recommended ecommerce events', () => {
11731173
price: 15.99,
11741174
});
11751175

1176-
const [eventName, props] = window.braze.logCustomEvent.mock.calls[0];
1176+
const [eventName, props] = globalThis.braze.logCustomEvent.mock.calls[0];
11771177
expect(eventName).toBe('ecommerce.cart_updated');
11781178
expect(props.action).toBe('remove');
11791179
});
@@ -1189,7 +1189,7 @@ describe('track - recommended ecommerce events', () => {
11891189
products: [{ product_id: 'p1', name: 'Game', variant: 'v1', quantity: 2, price: 15.99 }],
11901190
});
11911191

1192-
const props = window.braze.logCustomEvent.mock.calls[0][1];
1192+
const props = globalThis.braze.logCustomEvent.mock.calls[0][1];
11931193
// array is mapped, not the top-level wrap
11941194
expect(props.products).toEqual([
11951195
{ product_id: 'p1', product_name: 'Game', variant_id: 'v1', quantity: 2, price: 15.99 },
@@ -1211,7 +1211,7 @@ describe('track - recommended ecommerce events', () => {
12111211
action: 'caller-supplied',
12121212
});
12131213

1214-
const props = window.braze.logCustomEvent.mock.calls[0][1];
1214+
const props = globalThis.braze.logCustomEvent.mock.calls[0][1];
12151215
expect(props.action).toBe('add');
12161216
expect(props.metadata).toBeUndefined();
12171217
});
@@ -1226,7 +1226,7 @@ describe('track - recommended ecommerce events', () => {
12261226
products: [{ product_id: 'p1', name: 'Game', variant: 'v1', quantity: 1, price: 15.99 }],
12271227
});
12281228

1229-
expect(window.braze.logCustomEvent.mock.calls[0][1].total_discounts).toBe(3);
1229+
expect(globalThis.braze.logCustomEvent.mock.calls[0][1].total_discounts).toBe(3);
12301230
});
12311231

12321232
it('does not emit an empty product object when cart_updated has no product fields', () => {
@@ -1235,7 +1235,7 @@ describe('track - recommended ecommerce events', () => {
12351235
// single-product wrap must not emit a degenerate `[{}]`.
12361236
trackEvent(braze, 'Product Added', { cart_id: 'c1' });
12371237

1238-
const [eventName, props] = window.braze.logCustomEvent.mock.calls[0];
1238+
const [eventName, props] = globalThis.braze.logCustomEvent.mock.calls[0];
12391239
expect(eventName).toBe('ecommerce.cart_updated');
12401240
// no degenerate `[{}]` — the empty products array is scrubbed off entirely
12411241
expect(props.products).toBeUndefined();
@@ -1264,7 +1264,7 @@ describe('track - recommended ecommerce events', () => {
12641264
],
12651265
});
12661266

1267-
const props = window.braze.logCustomEvent.mock.calls[0][1];
1267+
const props = globalThis.braze.logCustomEvent.mock.calls[0][1];
12681268
expect(props.metadata).toEqual({ campaign: 'spring' });
12691269
expect(props.products[0].metadata).toEqual({ finish: 'matte' });
12701270
});
@@ -1279,7 +1279,7 @@ describe('track - recommended ecommerce events', () => {
12791279
products: [{ product_id: 'p1', name: 'Game', variant: 'v1', quantity: 2, price: 15.99 }],
12801280
});
12811281

1282-
expect(window.braze.logCustomEvent).toHaveBeenCalledWith('ecommerce.checkout_started', {
1282+
expect(globalThis.braze.logCustomEvent).toHaveBeenCalledWith('ecommerce.checkout_started', {
12831283
checkout_id: 'ck1',
12841284
cart_id: 'c1',
12851285
total_value: 31.98,
@@ -1304,8 +1304,8 @@ describe('track - recommended ecommerce events', () => {
13041304
],
13051305
});
13061306

1307-
expect(window.braze.logPurchase).not.toHaveBeenCalled();
1308-
expect(window.braze.logCustomEvent).toHaveBeenCalledWith('ecommerce.order_placed', {
1307+
expect(globalThis.braze.logPurchase).not.toHaveBeenCalled();
1308+
expect(globalThis.braze.logCustomEvent).toHaveBeenCalledWith('ecommerce.order_placed', {
13091309
order_id: 'o1',
13101310
total_value: 31.98,
13111311
currency: 'USD',
@@ -1335,7 +1335,7 @@ describe('track - recommended ecommerce events', () => {
13351335
products: [{ product_id: 'p1', name: 'Game', variant: 'v1', quantity: 2, price: 15.99 }],
13361336
});
13371337

1338-
expect(window.braze.logCustomEvent).toHaveBeenCalledWith('ecommerce.order_refunded', {
1338+
expect(globalThis.braze.logCustomEvent).toHaveBeenCalledWith('ecommerce.order_refunded', {
13391339
order_id: 'o1',
13401340
total_value: 31.98,
13411341
currency: 'USD',
@@ -1359,7 +1359,7 @@ describe('track - recommended ecommerce events', () => {
13591359
products: [{ product_id: 'p1', name: 'Game', variant: 'v1', quantity: 2, price: 15.99 }],
13601360
});
13611361

1362-
const [eventName, props] = window.braze.logCustomEvent.mock.calls[0];
1362+
const [eventName, props] = globalThis.braze.logCustomEvent.mock.calls[0];
13631363
expect(eventName).toBe('ecommerce.order_cancelled');
13641364
expect(props.cancel_reason).toBe('changed mind');
13651365
expect(warnMock).not.toHaveBeenCalled();
@@ -1375,7 +1375,7 @@ describe('track - recommended ecommerce events', () => {
13751375
variant: 'v1',
13761376
});
13771377

1378-
expect(window.braze.logCustomEvent).toHaveBeenCalledTimes(1);
1378+
expect(globalThis.braze.logCustomEvent).toHaveBeenCalledTimes(1);
13791379
expect(warnMock).toHaveBeenCalledTimes(1);
13801380
const warnMessage = warnMock.mock.calls[0][0];
13811381
expect(warnMessage).toContain('ecommerce.cart_updated');
@@ -1393,10 +1393,10 @@ describe('track - recommended ecommerce events', () => {
13931393
products: [],
13941394
});
13951395

1396-
expect(window.braze.logCustomEvent).toHaveBeenCalledTimes(1);
1396+
expect(globalThis.braze.logCustomEvent).toHaveBeenCalledTimes(1);
13971397
expect(warnMock.mock.calls[0][0]).toContain('products');
13981398
// empty products[] is scrubbed before send
1399-
expect(window.braze.logCustomEvent.mock.calls[0][1]).not.toHaveProperty('products');
1399+
expect(globalThis.braze.logCustomEvent.mock.calls[0][1]).not.toHaveProperty('products');
14001400
});
14011401

14021402
it('honors an explicit valid properties.source override', () => {
@@ -1410,7 +1410,7 @@ describe('track - recommended ecommerce events', () => {
14101410
source: 'ios',
14111411
});
14121412

1413-
expect(window.braze.logCustomEvent.mock.calls[0][1].source).toBe('ios');
1413+
expect(globalThis.braze.logCustomEvent.mock.calls[0][1].source).toBe('ios');
14141414
});
14151415

14161416
it('honors an explicit properties.source with surrounding whitespace', () => {
@@ -1424,7 +1424,7 @@ describe('track - recommended ecommerce events', () => {
14241424
source: 'ios ',
14251425
});
14261426

1427-
expect(window.braze.logCustomEvent.mock.calls[0][1].source).toBe('ios');
1427+
expect(globalThis.braze.logCustomEvent.mock.calls[0][1].source).toBe('ios');
14281428
});
14291429

14301430
it('warns and scrubs a required field provided as an empty object', () => {
@@ -1437,19 +1437,19 @@ describe('track - recommended ecommerce events', () => {
14371437
currency: {},
14381438
});
14391439

1440-
expect(window.braze.logCustomEvent).toHaveBeenCalledTimes(1);
1440+
expect(globalThis.braze.logCustomEvent).toHaveBeenCalledTimes(1);
14411441
// empty-object required value is reported as missing...
14421442
expect(warnMock).toHaveBeenCalledTimes(1);
14431443
expect(warnMock.mock.calls[0][0]).toContain('currency');
14441444
// ...and never reaches the sent payload.
1445-
expect(window.braze.logCustomEvent.mock.calls[0][1]).not.toHaveProperty('currency');
1445+
expect(globalThis.braze.logCustomEvent.mock.calls[0][1]).not.toHaveProperty('currency');
14461446
});
14471447

14481448
it('falls through to legacy custom-event path for unmapped events (Cart Updated)', () => {
14491449
const braze = buildBraze();
14501450
trackEvent(braze, 'Cart Updated', { cart_id: 'c1', value: 10 });
14511451

1452-
expect(window.braze.logCustomEvent).toHaveBeenCalledWith('Cart Updated', {
1452+
expect(globalThis.braze.logCustomEvent).toHaveBeenCalledWith('Cart Updated', {
14531453
cart_id: 'c1',
14541454
value: 10,
14551455
});
@@ -1462,8 +1462,8 @@ describe('track - recommended ecommerce events', () => {
14621462
products: [{ product_id: 'p1', price: 15.99, quantity: 1 }],
14631463
});
14641464

1465-
expect(window.braze.logPurchase).toHaveBeenCalledTimes(1);
1466-
expect(window.braze.logCustomEvent).not.toHaveBeenCalled();
1465+
expect(globalThis.braze.logPurchase).toHaveBeenCalledTimes(1);
1466+
expect(globalThis.braze.logCustomEvent).not.toHaveBeenCalled();
14671467
});
14681468
});
14691469

0 commit comments

Comments
 (0)