Skip to content

Commit 95d8fd8

Browse files
committed
test: updated products persistence test
1 parent 6c0c0c8 commit 95d8fd8

2 files changed

Lines changed: 9 additions & 6 deletions

File tree

src/persistence.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -365,10 +365,13 @@ export default function _Persistence(mpInstance) {
365365
allLocalStorageProducts = allLocalStorageProducts || {};
366366
allLocalStorageProducts[mpid] = currentUserProducts;
367367
try {
368-
window.localStorage.setItem(
369-
encodeURIComponent(mpInstance._Store.prodStorageName),
370-
Base64.encode(JSON.stringify(allLocalStorageProducts))
368+
const encodedKey = encodeURIComponent(
369+
mpInstance._Store.prodStorageName
370+
);
371+
const encodedValue = Base64.encode(
372+
JSON.stringify(allLocalStorageProducts)
371373
);
374+
window.localStorage.setItem(encodedKey, encodedValue);
372375
} catch (e) {
373376
mpInstance.Logger.error(
374377
'Error with setting products on localStorage.'

test/jest/persistence.products.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,21 @@ import {
1313
});
1414

1515
it('should save products to localStorage when noTargeting is false by default', () => {
16-
const product = { Name: 'iphone', Sku: 'iphonesku', Price: 599, Quantity: 1 };
16+
const product: Partial<Product> = { Name: 'iphone', Sku: 'iphonesku', Price: 599, Quantity: 1 };
1717
mpInstance._Persistence.setCartProducts({ [testMPID]: { cp: [product] } } as unknown as Product[]);
1818
expect(mpInstance._Persistence.getCartProducts(testMPID).length).toBe(1);
1919
});
2020

2121
it('should NOT save products to localStorage when noTargeting is true', () => {
2222
mpInstance._Store.setNoTargeting(true);
23-
const product = { Name: 'iphone', Sku: 'iphonesku', Price: 599, Quantity: 1 };
23+
const product: Partial<Product> = { Name: 'iphone', Sku: 'iphonesku', Price: 599, Quantity: 1 };
2424
mpInstance._Persistence.setCartProducts({ [testMPID]: { cp: [product] } } as unknown as Product[]);
2525
expect(mpInstance._Persistence.getCartProducts(testMPID).length).toBe(0);
2626
});
2727

2828
it('should save products to localStorage when noTargeting is false', () => {
2929
mpInstance._Store.setNoTargeting(false);
30-
const product = { Name: 'iphone', Sku: 'iphonesku', Price: 599, Quantity: 1 };
30+
const product: Partial<Product> = { Name: 'iphone', Sku: 'iphonesku', Price: 599, Quantity: 1 };
3131
mpInstance._Persistence.setCartProducts({ [testMPID]: { cp: [product] } } as unknown as Product[]);
3232
expect(mpInstance._Persistence.getCartProducts(testMPID).length).toBe(1);
3333
});

0 commit comments

Comments
 (0)