@ordergroove/offers 2.21.4-alpha-PR-515-2.0 → 2.21.5

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.21.4-alpha-PR-515-2.0+1882e4f3",
3
+ "version": "2.21.5",
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/js-utils": "^1.0.3",
50
50
  "@ordergroove/offers-templates": "^0.3.16"
51
51
  },
52
- "gitHead": "1882e4f36e522ac54d7d653e996d8ac99613b294"
52
+ "gitHead": "dca90f6c0fd7bea28a04af4fffdea87aefb9f2e1"
53
53
  }
@@ -1,4 +1,4 @@
1
- import { STORE_ROOT, listenLocalStorageChanges, serializeState, saveState } from '../localStorage';
1
+ import { STORE_ROOT, listenLocalStorageChanges, serializeState, saveState, loadState } from '../localStorage';
2
2
  import { LOCAL_STORAGE_CHANGE, LOCAL_STORAGE_CLEAR } from '../constants';
3
3
 
4
4
  describe('serializeState', () => {
@@ -34,6 +34,40 @@ describe('serializeState', () => {
34
34
  );
35
35
  });
36
36
  });
37
+
38
+ describe('loadState', () => {
39
+ let getItemSpy, setItemSpy;
40
+ beforeEach(() => {
41
+ getItemSpy = spyOn(Object.getPrototypeOf(localStorage), 'getItem');
42
+ setItemSpy = spyOn(Object.getPrototypeOf(localStorage), 'setItem');
43
+ });
44
+
45
+ it('should return undefined on empty state', () => {
46
+ expect(loadState()).toBe(undefined);
47
+ });
48
+
49
+ it('should return undefined on empty state', () => {
50
+ const yum = {
51
+ sessionId: 'yum',
52
+ optedin: 'yum2',
53
+ optedout: 'yum3',
54
+ productOffer: 'yum4',
55
+ firstOrderPlaceDate: 'yum5',
56
+ productToSubscribe: 'yum6'
57
+ };
58
+ getItemSpy.and.callFake(() => JSON.stringify(yum));
59
+ expect(loadState()).toEqual(yum);
60
+ expect(getItemSpy).toHaveBeenCalledWith(STORE_ROOT);
61
+ });
62
+
63
+ it('should load empty object if preview mode', () => {
64
+ const tmp = window.og.previewMode;
65
+ window.og.previewMode = true;
66
+ expect(loadState()).toEqual({});
67
+ window.og.previewMode = tmp;
68
+ });
69
+ });
70
+
37
71
  describe('saveState', () => {
38
72
  let getItemSpy, setItemSpy;
39
73
  beforeEach(() => {
@@ -68,6 +68,9 @@ export const fetchDone = initiator => ({
68
68
  */
69
69
  export const fetchAuth = (authResolver = resolveAuth) =>
70
70
  function fetchAuthThunk(dispatch, getState) {
71
+ if (window.og && window.og.previewMode)
72
+ return dispatch(unauthorized({ message: 'Offers are running in preview mode' }));
73
+
71
74
  const { merchantId, authUrl } = getState();
72
75
 
73
76
  const requestAction = requestAuth(authUrl);
@@ -16,7 +16,7 @@ export const safeParseState = serializedState => {
16
16
  };
17
17
  const isPreviewMode = () => window.og && window.og.previewMode;
18
18
 
19
- export const loadState = () => (isPreviewMode ? {} : safeParseState(localStorage.getItem(STORE_ROOT)));
19
+ export const loadState = () => (isPreviewMode() ? {} : safeParseState(localStorage.getItem(STORE_ROOT)));
20
20
 
21
21
  export const serializeState = state => {
22
22
  if (!state || !state.sessionId) {