@ordergroove/offers 2.40.2 → 2.40.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ordergroove/offers",
3
- "version": "2.40.2",
3
+ "version": "2.40.3",
4
4
  "description": "offer state component",
5
5
  "author": "Eugenio Lattanzio <eugenio63@gmail.com>",
6
6
  "homepage": "https://github.com/ordergroove/plush-toys#readme",
@@ -49,5 +49,5 @@
49
49
  "@ordergroove/offers-templates": "^0.9.6",
50
50
  "@types/lodash.memoize": "^4.1.9"
51
51
  },
52
- "gitHead": "d2b9d0b60d78396e064037cffebf1cb2a494cd5f"
52
+ "gitHead": "46f1b45441b87946e459a29d8f503895e4e3f0de"
53
53
  }
@@ -60,6 +60,7 @@ describe('loadState', () => {
60
60
  });
61
61
 
62
62
  it('should load empty object if preview mode', () => {
63
+ window.og = window.og || {};
63
64
  const tmp = window.og.previewMode;
64
65
  window.og.previewMode = true;
65
66
  expect(loadState()).toEqual({});
@@ -68,10 +69,21 @@ describe('loadState', () => {
68
69
  });
69
70
 
70
71
  describe('saveState', () => {
72
+ let cookieSpy;
71
73
  let getItemSpy, setItemSpy;
72
74
  beforeEach(() => {
73
75
  getItemSpy = spyOn(Object.getPrototypeOf(localStorage), 'getItem');
74
76
  setItemSpy = spyOn(Object.getPrototypeOf(localStorage), 'setItem');
77
+ cookieSpy = '';
78
+ Object.defineProperty(document, 'cookie', {
79
+ get: function () {
80
+ return cookieSpy;
81
+ },
82
+ set: function (value) {
83
+ cookieSpy = value;
84
+ },
85
+ configurable: true // Ensure property can be redefined in future tests
86
+ });
75
87
  });
76
88
 
77
89
  it('should not save empty state', function () {
@@ -83,6 +95,7 @@ describe('saveState', () => {
83
95
  it('should not save if same state', function () {
84
96
  getItemSpy.and.returnValue(JSON.stringify({ sessionId: 'yum' }));
85
97
  saveState({ sessionId: 'yum' });
98
+ expect(cookieSpy).toEqual('og_session_id=yum; path=/; expires=Fri, 31 Dec 9999 23:59:59 GMT; SameSite=Lax');
86
99
  expect(getItemSpy).toHaveBeenCalledWith(STORE_ROOT);
87
100
  expect(setItemSpy).not.toHaveBeenCalled();
88
101
  });
@@ -90,6 +103,7 @@ describe('saveState', () => {
90
103
  it('should save if different state', function () {
91
104
  const payload = { sessionId: 'yum' };
92
105
  saveState(payload);
106
+ expect(cookieSpy).toEqual('og_session_id=yum; path=/; expires=Fri, 31 Dec 9999 23:59:59 GMT; SameSite=Lax');
93
107
  expect(getItemSpy).toHaveBeenCalledWith(STORE_ROOT);
94
108
  expect(setItemSpy).toHaveBeenCalledWith(STORE_ROOT, JSON.stringify({ sessionId: 'yum' }));
95
109
  });
@@ -39,6 +39,13 @@ export const serializeState = state => {
39
39
 
40
40
  export const saveState = state => {
41
41
  if (isPreviewMode()) return;
42
+ if (state && state.sessionId) {
43
+ document.cookie =
44
+ 'og_session_id=' +
45
+ encodeURIComponent(state.sessionId) +
46
+ '; path=/; expires=Fri, 31 Dec 9999 23:59:59 GMT; SameSite=Lax';
47
+ }
48
+
42
49
  const serializedState = serializeState(state);
43
50
  if (serializedState && localStorage.getItem(STORE_ROOT) !== serializedState) {
44
51
  localStorage.setItem(STORE_ROOT, serializedState);