@ordergroove/offers 2.35.2 → 2.35.4
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/CHANGELOG.md +16 -0
- package/dist/bundle-report.html +10 -10
- package/dist/examples.js +3 -2
- package/dist/examples.js.map +2 -2
- package/dist/offers.js +37 -52
- package/dist/offers.js.map +2 -2
- package/examples/index.html +1 -1
- package/examples/shopify-cart.html +5 -8
- package/examples/shopify-pdp.html +8 -12
- package/karma-functional.conf.js +1 -1
- package/karma-shopify.conf.js +1 -1
- package/karma.conf.js +1 -1
- package/package.json +5 -5
- package/src/components/FrequencyStatus.js +4 -4
- package/src/components/Modal.js +5 -7
- package/src/components/Offer.js +3 -1
- package/src/components/OptinToggle.js +2 -2
- package/src/components/Select.js +2 -1
- package/src/components/TestWizard.js +22 -35
- package/src/components/Tooltip.js +2 -6
- package/src/components/UpsellModal.js +2 -2
- package/src/components/__tests__/FrequencyStatus.spec.js +1 -1
- package/src/components/__tests__/OG.fspec.js +7 -10
- package/src/components/__tests__/Offer.spec.js +17 -17
- package/src/components/__tests__/OptinButton.spec.js +1 -1
- package/src/components/__tests__/PrepaidButton.spec.js +1 -1
- package/src/components/__tests__/PrepaidSelect.spec.js +1 -1
- package/src/components/__tests__/PrepaidToggle.spec.js +1 -1
- package/src/components/__tests__/Price.spec.js +6 -6
- package/src/components/__tests__/Select.spec.js +4 -4
- package/src/components/__tests__/SubscriptionButton.spec.js +1 -1
- package/src/core/__tests__/actions.spec.js +13 -13
- package/src/core/__tests__/connect.spec.js +1 -0
- package/src/core/__tests__/localStorage.spec.js +4 -4
- package/src/core/__tests__/middleware.spec.js +12 -12
- package/src/core/actions-preview.js +1 -1
- package/src/core/actions.js +8 -6
- package/src/core/api.js +5 -13
- package/src/core/connect.js +29 -27
- package/src/core/middleware.js +12 -12
- package/src/core/reducer.js +3 -3
- package/src/core/utils.ts +4 -4
- package/src/run-tests.js +1 -1
- package/src/shopify/__tests__/shopifyReducer.spec.js +7 -7
- package/src/shopify/shopifyMiddleware.ts +2 -2
- package/src/shopify/shopifyReducer.js +1 -7
- package/src/test-mode.js +2 -2
- package/tsconfig.json +1 -4
|
@@ -24,7 +24,7 @@ import {
|
|
|
24
24
|
import * as constants from '../constants';
|
|
25
25
|
import { api } from '../api';
|
|
26
26
|
|
|
27
|
-
describe('redux actions', function() {
|
|
27
|
+
describe('redux actions', function () {
|
|
28
28
|
it('setEnvironment should return dev payload given dev env', () => {
|
|
29
29
|
expect(setEnvironment('dev')).toEqual({
|
|
30
30
|
type: 'SET_ENVIRONMENT_DEV',
|
|
@@ -165,7 +165,7 @@ describe('redux actions', function() {
|
|
|
165
165
|
sessionId: 'the sessionId',
|
|
166
166
|
environment: { apiUrl: 'the environment.apiUrl' }
|
|
167
167
|
});
|
|
168
|
-
const fetchOfferSpy = spyOn(api, 'fetchOffer').and.
|
|
168
|
+
const fetchOfferSpy = spyOn(api, 'fetchOffer').and.resolveTo({ hey: 'ho' });
|
|
169
169
|
await fetchOffer('the product')(this.dispatch, getState);
|
|
170
170
|
expect(fetchOfferSpy).toHaveBeenCalledWith(
|
|
171
171
|
'the environment.apiUrl',
|
|
@@ -177,7 +177,7 @@ describe('redux actions', function() {
|
|
|
177
177
|
});
|
|
178
178
|
|
|
179
179
|
it('should dispatch the receiveOffer if api returns', async () => {
|
|
180
|
-
const fetchOfferSpy = spyOn(api, 'fetchOffer').and.
|
|
180
|
+
const fetchOfferSpy = spyOn(api, 'fetchOffer').and.resolveTo({ hey: 'ho' });
|
|
181
181
|
|
|
182
182
|
await fetchOffer('yum product')(this.dispatch, this.getState);
|
|
183
183
|
|
|
@@ -189,7 +189,7 @@ describe('redux actions', function() {
|
|
|
189
189
|
});
|
|
190
190
|
|
|
191
191
|
it('should dispatch fetchResponseError if api fails', async () => {
|
|
192
|
-
const fetchOfferSpy = spyOn(api, 'fetchOffer').and.
|
|
192
|
+
const fetchOfferSpy = spyOn(api, 'fetchOffer').and.rejectWith(Error({ hey: 'ho' }));
|
|
193
193
|
await fetchOffer('yum product')(this.dispatch, this.getState);
|
|
194
194
|
|
|
195
195
|
expect(this.dispatch.calls.count()).toEqual(3);
|
|
@@ -243,7 +243,7 @@ describe('redux actions', function() {
|
|
|
243
243
|
|
|
244
244
|
it('fetchAuth should dispatch requestOffer if authUrl and call authResolver', async () => {
|
|
245
245
|
const dispatch = jasmine.createSpy('dispatch');
|
|
246
|
-
const authResolver = jasmine.createSpy('authResolver').and.
|
|
246
|
+
const authResolver = jasmine.createSpy('authResolver').and.resolveTo({});
|
|
247
247
|
const getState = jasmine.createSpy('getState').and.returnValue({
|
|
248
248
|
merchantId: 'yum merchant id',
|
|
249
249
|
authUrl: 'some auth url'
|
|
@@ -259,12 +259,12 @@ describe('redux actions', function() {
|
|
|
259
259
|
|
|
260
260
|
it('fetchAuth should dispatch receiveOffer authResolver succed', async () => {
|
|
261
261
|
const dispatch = jasmine.createSpy('dispatch');
|
|
262
|
-
const authResolver = jasmine.createSpy('authResolver').and.
|
|
263
|
-
|
|
262
|
+
const authResolver = jasmine.createSpy('authResolver').and.resolveTo(
|
|
263
|
+
{
|
|
264
264
|
sig_field: 'sig_field',
|
|
265
265
|
sig: 'sig',
|
|
266
266
|
ts: 'ts'
|
|
267
|
-
}
|
|
267
|
+
}
|
|
268
268
|
);
|
|
269
269
|
const getState = jasmine.createSpy('getState').and.returnValue({
|
|
270
270
|
merchantId: 'yum merchant id',
|
|
@@ -277,7 +277,7 @@ describe('redux actions', function() {
|
|
|
277
277
|
|
|
278
278
|
it('fetchAuth should dispatch unauthorized if authResolver reject', async () => {
|
|
279
279
|
const dispatch = jasmine.createSpy('dispatch');
|
|
280
|
-
const authResolver = jasmine.createSpy('authResolver').and.
|
|
280
|
+
const authResolver = jasmine.createSpy('authResolver').and.rejectWith(new Error('some reason'));
|
|
281
281
|
const getState = jasmine.createSpy('getState').and.returnValue({
|
|
282
282
|
merchantId: 'yum merchant id',
|
|
283
283
|
authUrl: 'some auth url'
|
|
@@ -291,7 +291,7 @@ describe('redux actions', function() {
|
|
|
291
291
|
|
|
292
292
|
describe('actions.iu', () => {
|
|
293
293
|
it('createIu should dispatch request and receive actions', async () => {
|
|
294
|
-
const fetchSpy = spyOn(api, 'createOneTime').and.
|
|
294
|
+
const fetchSpy = spyOn(api, 'createOneTime').and.resolveTo({ hey: 'ho' });
|
|
295
295
|
const dispatch = jasmine.createSpy('dispatch');
|
|
296
296
|
const getState = jasmine
|
|
297
297
|
.createSpy('getState')
|
|
@@ -316,7 +316,7 @@ describe('actions.iu', () => {
|
|
|
316
316
|
});
|
|
317
317
|
|
|
318
318
|
it('createIu should not call api if previewMode', async () => {
|
|
319
|
-
const fetchSpy = spyOn(api, 'createOneTime').and.
|
|
319
|
+
const fetchSpy = spyOn(api, 'createOneTime').and.resolveTo({ hey: 'ho' });
|
|
320
320
|
const dispatch = jasmine.createSpy('dispatch');
|
|
321
321
|
const getState = jasmine.createSpy('getState').and.returnValue({
|
|
322
322
|
previewUpsellOffer: true,
|
|
@@ -343,8 +343,8 @@ describe('actions.iu', () => {
|
|
|
343
343
|
});
|
|
344
344
|
|
|
345
345
|
it('createIu should dispatch create subscription', async () => {
|
|
346
|
-
const fetchSpy = spyOn(api, 'createOneTime').and.
|
|
347
|
-
spyOn(api, 'convertOneTimeToSubscription').and.
|
|
346
|
+
const fetchSpy = spyOn(api, 'createOneTime').and.resolveTo({ hey: 'hokk' });
|
|
347
|
+
spyOn(api, 'convertOneTimeToSubscription').and.resolveTo({ hey: 'hwwo' });
|
|
348
348
|
const dispatch = jasmine.createSpy('dispatch').and.returnValue({ the: 'item' });
|
|
349
349
|
const getState = jasmine
|
|
350
350
|
.createSpy('getState')
|
|
@@ -45,7 +45,7 @@ describe('loadState', () => {
|
|
|
45
45
|
expect(loadState()).toBe(undefined);
|
|
46
46
|
});
|
|
47
47
|
|
|
48
|
-
it('should return
|
|
48
|
+
it('should return object for populated state', () => {
|
|
49
49
|
const yum = {
|
|
50
50
|
sessionId: 'yum',
|
|
51
51
|
optedin: 'yum2',
|
|
@@ -74,20 +74,20 @@ describe('saveState', () => {
|
|
|
74
74
|
setItemSpy = spyOn(Object.getPrototypeOf(localStorage), 'setItem');
|
|
75
75
|
});
|
|
76
76
|
|
|
77
|
-
it('should not save empty state', function() {
|
|
77
|
+
it('should not save empty state', function () {
|
|
78
78
|
['', false, {}, null, undefined].forEach(saveState);
|
|
79
79
|
expect(getItemSpy).not.toHaveBeenCalled();
|
|
80
80
|
expect(setItemSpy).not.toHaveBeenCalled();
|
|
81
81
|
});
|
|
82
82
|
|
|
83
|
-
it('should not save if same state', function() {
|
|
83
|
+
it('should not save if same state', function () {
|
|
84
84
|
getItemSpy.and.returnValue(JSON.stringify({ sessionId: 'yum' }));
|
|
85
85
|
saveState({ sessionId: 'yum' });
|
|
86
86
|
expect(getItemSpy).toHaveBeenCalledWith(STORE_ROOT);
|
|
87
87
|
expect(setItemSpy).not.toHaveBeenCalled();
|
|
88
88
|
});
|
|
89
89
|
|
|
90
|
-
it('should save if different state', function() {
|
|
90
|
+
it('should save if different state', function () {
|
|
91
91
|
const payload = { sessionId: 'yum' };
|
|
92
92
|
saveState(payload);
|
|
93
93
|
expect(getItemSpy).toHaveBeenCalledWith(STORE_ROOT);
|
|
@@ -45,29 +45,29 @@ describe('middleware', () => {
|
|
|
45
45
|
|
|
46
46
|
describe('conditionals', () => {
|
|
47
47
|
describe('expression a', () => {
|
|
48
|
-
beforeEach(function() {
|
|
48
|
+
beforeEach(function () {
|
|
49
49
|
this.underTest = conditionals[0].expressions[0];
|
|
50
50
|
});
|
|
51
51
|
|
|
52
|
-
it('should return true given type is constants.OPTIN_PRODUCT', function() {
|
|
52
|
+
it('should return true given type is constants.OPTIN_PRODUCT', function () {
|
|
53
53
|
expect(this.underTest({ type: constants.OPTIN_PRODUCT })).toBe(true);
|
|
54
54
|
});
|
|
55
55
|
|
|
56
|
-
it('should return false given type is not constants.OPTIN_PRODUCT', function() {
|
|
56
|
+
it('should return false given type is not constants.OPTIN_PRODUCT', function () {
|
|
57
57
|
expect(this.underTest({ type: 'not constants.OPTIN_PRODUCT' })).toBe(false);
|
|
58
58
|
});
|
|
59
59
|
|
|
60
|
-
it('should return false given type is not defined', function() {
|
|
60
|
+
it('should return false given type is not defined', function () {
|
|
61
61
|
expect(this.underTest()).toBe(false);
|
|
62
62
|
});
|
|
63
63
|
});
|
|
64
64
|
|
|
65
65
|
describe('expression b', () => {
|
|
66
|
-
beforeEach(function() {
|
|
66
|
+
beforeEach(function () {
|
|
67
67
|
this.underTest = conditionals[0].expressions[1];
|
|
68
68
|
});
|
|
69
69
|
|
|
70
|
-
it('should return false given type is not constants.PRODUCT_CHANGE_FREQUENCY and optedin does not contain same product', function() {
|
|
70
|
+
it('should return false given type is not constants.PRODUCT_CHANGE_FREQUENCY and optedin does not contain same product', function () {
|
|
71
71
|
const action = {
|
|
72
72
|
type: 'not constants.PRODUCT_CHANGE_FREQUENCY',
|
|
73
73
|
payload: {
|
|
@@ -83,7 +83,7 @@ describe('middleware', () => {
|
|
|
83
83
|
expect(this.underTest(action, state)).toBe(false);
|
|
84
84
|
});
|
|
85
85
|
|
|
86
|
-
it('should return false given type is not constants.PRODUCT_CHANGE_FREQUENCY and optedin contains same product', function() {
|
|
86
|
+
it('should return false given type is not constants.PRODUCT_CHANGE_FREQUENCY and optedin contains same product', function () {
|
|
87
87
|
const action = {
|
|
88
88
|
type: 'not constants.PRODUCT_CHANGE_FREQUENCY',
|
|
89
89
|
payload: {
|
|
@@ -103,7 +103,7 @@ describe('middleware', () => {
|
|
|
103
103
|
expect(this.underTest(action, state)).toBe(false);
|
|
104
104
|
});
|
|
105
105
|
|
|
106
|
-
it('should return true given type is constants.PRODUCT_CHANGE_FREQUENCY', function() {
|
|
106
|
+
it('should return true given type is constants.PRODUCT_CHANGE_FREQUENCY', function () {
|
|
107
107
|
const action = {
|
|
108
108
|
type: constants.PRODUCT_CHANGE_FREQUENCY,
|
|
109
109
|
payload: {
|
|
@@ -125,19 +125,19 @@ describe('middleware', () => {
|
|
|
125
125
|
});
|
|
126
126
|
|
|
127
127
|
describe('expression c', () => {
|
|
128
|
-
beforeEach(function() {
|
|
128
|
+
beforeEach(function () {
|
|
129
129
|
this.underTest = conditionals[1].expressions[0];
|
|
130
130
|
});
|
|
131
131
|
|
|
132
|
-
it('should return true given type is constants.OPTOUT_PRODUCT', function() {
|
|
132
|
+
it('should return true given type is constants.OPTOUT_PRODUCT', function () {
|
|
133
133
|
expect(this.underTest({ type: constants.OPTOUT_PRODUCT })).toBe(true);
|
|
134
134
|
});
|
|
135
135
|
|
|
136
|
-
it('should return false given type is not constants.OPTOUT_PRODUCT', function() {
|
|
136
|
+
it('should return false given type is not constants.OPTOUT_PRODUCT', function () {
|
|
137
137
|
expect(this.underTest({ type: 'not constants.OPTOUT_PRODUCT' })).toBe(false);
|
|
138
138
|
});
|
|
139
139
|
|
|
140
|
-
it('should return false given type is not defined', function() {
|
|
140
|
+
it('should return false given type is not defined', function () {
|
|
141
141
|
expect(this.underTest()).toBe(false);
|
|
142
142
|
});
|
|
143
143
|
});
|
|
@@ -264,7 +264,7 @@ export const setPreviewPrepaid = (isPreview, productId, offer) =>
|
|
|
264
264
|
};
|
|
265
265
|
|
|
266
266
|
export const setPreview = (value, oldValue, offer) =>
|
|
267
|
-
async function(dispatch, _getState) {
|
|
267
|
+
async function (dispatch, _getState) {
|
|
268
268
|
await dispatch({ type: constants.LOCAL_STORAGE_CLEAR });
|
|
269
269
|
await dispatch({
|
|
270
270
|
type: constants.SET_PREVIEW_STANDARD_OFFER,
|
package/src/core/actions.js
CHANGED
|
@@ -256,18 +256,20 @@ export const createIu = (product, order, quantity, subscribed = false, initialFr
|
|
|
256
256
|
|
|
257
257
|
dispatch(requestAction);
|
|
258
258
|
|
|
259
|
-
return (
|
|
260
|
-
|
|
261
|
-
|
|
259
|
+
return (
|
|
260
|
+
previewUpsellOffer
|
|
261
|
+
? Promise.resolve({ legoUrl, product, order, quantity, offer })
|
|
262
|
+
: api.createOneTime(legoUrl, auth, product.id, order, quantity, offer)
|
|
262
263
|
)
|
|
263
264
|
.then(
|
|
264
265
|
item => {
|
|
265
266
|
dispatch(receiveCreateOneTime(item));
|
|
266
267
|
if (subscribed) {
|
|
267
268
|
dispatch(requestConvertOneTimeToSubscription(item, frequency));
|
|
268
|
-
return (
|
|
269
|
-
|
|
270
|
-
|
|
269
|
+
return (
|
|
270
|
+
previewUpsellOffer
|
|
271
|
+
? Promise.resolve({ item, frequency })
|
|
272
|
+
: api.convertOneTimeToSubscription(legoUrl, auth, item, frequency, offer)
|
|
271
273
|
).then(
|
|
272
274
|
response => dispatch(receiveConvertOneTime(response, product)),
|
|
273
275
|
err => dispatch(fetchResponseError(err))
|
package/src/core/api.js
CHANGED
|
@@ -2,7 +2,10 @@ import memoize from 'lodash.memoize';
|
|
|
2
2
|
|
|
3
3
|
const memoizeKey = (...args) => JSON.stringify(args);
|
|
4
4
|
|
|
5
|
-
export const withFetchJson =
|
|
5
|
+
export const withFetchJson =
|
|
6
|
+
cb =>
|
|
7
|
+
(...args) =>
|
|
8
|
+
fetch(...cb(...args)).then(res => res.json());
|
|
6
9
|
|
|
7
10
|
export const withHost = cb => {
|
|
8
11
|
return (host, ...extra) => {
|
|
@@ -134,18 +137,7 @@ export const parseFrequency = raw => {
|
|
|
134
137
|
|
|
135
138
|
export const isFrequencyValid = it => it.match(/^\d+_\d$/);
|
|
136
139
|
export const compareFrequencies = (a, b) =>
|
|
137
|
-
String.prototype.localeCompare.call(
|
|
138
|
-
a &&
|
|
139
|
-
a
|
|
140
|
-
.split('_')
|
|
141
|
-
.reverse()
|
|
142
|
-
.join('_'),
|
|
143
|
-
b &&
|
|
144
|
-
b
|
|
145
|
-
.split('_')
|
|
146
|
-
.reverse()
|
|
147
|
-
.join('_')
|
|
148
|
-
);
|
|
140
|
+
String.prototype.localeCompare.call(a && a.split('_').reverse().join('_'), b && b.split('_').reverse().join('_'));
|
|
149
141
|
|
|
150
142
|
export const parseFrequenciesList = value =>
|
|
151
143
|
[...new Set(value && value.split(/\s+/))].filter(isFrequencyValid).sort(compareFrequencies);
|
package/src/core/connect.js
CHANGED
|
@@ -21,41 +21,43 @@ export const createRecalcProps = (mapStateToProps, mapDispatchToProps) => obj =>
|
|
|
21
21
|
* TODO this component can be coded as regular connect function. Instead of making the component
|
|
22
22
|
* tied to stateChanged connect can accept mapStateToProps?, mapDispatchToProps?
|
|
23
23
|
*/
|
|
24
|
-
export const connect =
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
24
|
+
export const connect =
|
|
25
|
+
(mapStateToProps, mapDispatchToProps = defaultMapDispatchToProps) =>
|
|
26
|
+
baseElement => {
|
|
27
|
+
const preparedDispatch =
|
|
28
|
+
typeof mapDispatchToProps === 'function'
|
|
29
|
+
? mapDispatchToProps
|
|
30
|
+
: dispatch => bindActionCreators(mapDispatchToProps, dispatch);
|
|
29
31
|
|
|
30
|
-
|
|
32
|
+
const recalcProps = createRecalcProps(mapStateToProps, preparedDispatch);
|
|
31
33
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
connectedCallback() {
|
|
38
|
-
if (super.connectedCallback) {
|
|
39
|
-
super.connectedCallback();
|
|
34
|
+
return class extends baseElement {
|
|
35
|
+
get store() {
|
|
36
|
+
return storeInstance;
|
|
40
37
|
}
|
|
41
38
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
39
|
+
connectedCallback() {
|
|
40
|
+
if (super.connectedCallback) {
|
|
41
|
+
super.connectedCallback();
|
|
42
|
+
}
|
|
45
43
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
44
|
+
this._storeUnsubscribe = resolveStore(this).subscribe(() => recalcProps(this));
|
|
45
|
+
recalcProps(this);
|
|
46
|
+
}
|
|
50
47
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
super.disconnectedCallback();
|
|
48
|
+
attributeChangedCallback(name, old, value) {
|
|
49
|
+
if (super.attributeChangedCallback) super.attributeChangedCallback(name, old, value);
|
|
50
|
+
if (this._storeUnsubscribe && old !== value) recalcProps(this);
|
|
55
51
|
}
|
|
56
|
-
|
|
52
|
+
|
|
53
|
+
disconnectedCallback() {
|
|
54
|
+
this._storeUnsubscribe();
|
|
55
|
+
if (super.disconnectedCallback) {
|
|
56
|
+
super.disconnectedCallback();
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
};
|
|
57
60
|
};
|
|
58
|
-
};
|
|
59
61
|
/**
|
|
60
62
|
* This api will change asap
|
|
61
63
|
* @deprecated
|
package/src/core/middleware.js
CHANGED
|
@@ -9,18 +9,18 @@ export const dispatchEvent = (name, detail, el = document) =>
|
|
|
9
9
|
})
|
|
10
10
|
);
|
|
11
11
|
|
|
12
|
-
export const dispatchOptinChangedEvent =
|
|
13
|
-
|
|
14
|
-
} = {}) =>
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
12
|
+
export const dispatchOptinChangedEvent =
|
|
13
|
+
optedIn =>
|
|
14
|
+
({ payload: { product: { id: productId, components } = {} } = {} } = {}) =>
|
|
15
|
+
setTimeout(
|
|
16
|
+
() =>
|
|
17
|
+
dispatchEvent('optin-changed', {
|
|
18
|
+
productId,
|
|
19
|
+
components,
|
|
20
|
+
optedIn
|
|
21
|
+
}),
|
|
22
|
+
0
|
|
23
|
+
);
|
|
24
24
|
|
|
25
25
|
export const conditionals = [
|
|
26
26
|
{
|
package/src/core/reducer.js
CHANGED
|
@@ -366,9 +366,9 @@ export const locale = (
|
|
|
366
366
|
upsellModalCancelLabel: 'Cancel',
|
|
367
367
|
defaultFrequencyCopy: '(Most Popular)',
|
|
368
368
|
frequencyPeriods: {
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
369
|
+
1: 'day',
|
|
370
|
+
2: 'week',
|
|
371
|
+
3: 'month'
|
|
372
372
|
},
|
|
373
373
|
prepaidOptInLabel: 'Prepaid Subscription',
|
|
374
374
|
prepaidShipmentsLabel: 'Number of prepaid shipments'
|
package/src/core/utils.ts
CHANGED
|
@@ -149,10 +149,10 @@ export function getOrCreateHidden(parent, name, value) {
|
|
|
149
149
|
* @returns {[any, any[]]} - a two item array where the first item is the matching product and the second is the remaining items from the original state.
|
|
150
150
|
*/
|
|
151
151
|
export function getMatchingProductIfExists(state, product) {
|
|
152
|
-
const [[oldone], rest] = state.reduce(
|
|
153
|
-
[],
|
|
154
|
-
[]
|
|
155
|
-
|
|
152
|
+
const [[oldone], rest] = state.reduce(
|
|
153
|
+
(acc, val) => acc[isSameProduct(product, val) ? 0 : 1].push(val) && acc,
|
|
154
|
+
[[], []]
|
|
155
|
+
);
|
|
156
156
|
|
|
157
157
|
return [oldone || {}, rest || []];
|
|
158
158
|
}
|
package/src/run-tests.js
CHANGED
|
@@ -437,7 +437,7 @@ describe('config', () => {
|
|
|
437
437
|
);
|
|
438
438
|
expect(actual).toEqual({
|
|
439
439
|
prepaidSellingPlans: {
|
|
440
|
-
|
|
440
|
+
43017264201944: [
|
|
441
441
|
{
|
|
442
442
|
numberShipments: 4,
|
|
443
443
|
sellingPlan: '2146042072'
|
|
@@ -479,13 +479,13 @@ describe('config', () => {
|
|
|
479
479
|
const actual = config(
|
|
480
480
|
{
|
|
481
481
|
prepaidSellingPlans: {
|
|
482
|
-
|
|
482
|
+
43017264201946: [
|
|
483
483
|
{
|
|
484
484
|
numberShipments: 1,
|
|
485
485
|
sellingPlan: '2146042072'
|
|
486
486
|
}
|
|
487
487
|
],
|
|
488
|
-
|
|
488
|
+
43017264201944: [
|
|
489
489
|
{
|
|
490
490
|
numberShipments: 4,
|
|
491
491
|
sellingPlan: '2146042071'
|
|
@@ -504,19 +504,19 @@ describe('config', () => {
|
|
|
504
504
|
);
|
|
505
505
|
expect(actual).toEqual({
|
|
506
506
|
prepaidSellingPlans: {
|
|
507
|
-
|
|
507
|
+
43017264201944: [
|
|
508
508
|
{
|
|
509
509
|
numberShipments: 4,
|
|
510
510
|
sellingPlan: '2146042071'
|
|
511
511
|
}
|
|
512
512
|
],
|
|
513
|
-
|
|
513
|
+
43017264201946: [
|
|
514
514
|
{
|
|
515
515
|
numberShipments: 3,
|
|
516
516
|
sellingPlan: '2146042072'
|
|
517
517
|
}
|
|
518
518
|
],
|
|
519
|
-
|
|
519
|
+
43017264201945: [
|
|
520
520
|
{
|
|
521
521
|
numberShipments: 5,
|
|
522
522
|
sellingPlan: '2146042073'
|
|
@@ -2063,7 +2063,7 @@ describe('productPlans', () => {
|
|
|
2063
2063
|
});
|
|
2064
2064
|
});
|
|
2065
2065
|
|
|
2066
|
-
it('should convert product plan values into non-USD currencies given action
|
|
2066
|
+
it('should convert product plan values into non-USD currencies given action SETUP_CART with GBP currency', () => {
|
|
2067
2067
|
const actual = productPlans({}, getSetupCartActionForRegularProduct('GBP'));
|
|
2068
2068
|
|
|
2069
2069
|
expect(actual).toEqual({
|
|
@@ -39,7 +39,7 @@ type SetupCartPayload = ShopifyCart;
|
|
|
39
39
|
const DEFAULT_SHOPIFY_CART_AJAX_SECTIONS =
|
|
40
40
|
'[id^="shopify-section-"][id$=__cart-items], [id^="shopify-section-"][id$="__cart-footer"],#cart-live-region-text,#cart-icon-bubble';
|
|
41
41
|
const makeSyncProductId = offer =>
|
|
42
|
-
debounce(100, false, function(form) {
|
|
42
|
+
debounce(100, false, function (form) {
|
|
43
43
|
const { id } = Object.fromEntries([...new FormData(form).entries()]);
|
|
44
44
|
if (id) {
|
|
45
45
|
offer.setAttribute('product', id);
|
|
@@ -142,7 +142,7 @@ export function guessProductHandle(offer): string {
|
|
|
142
142
|
);
|
|
143
143
|
}
|
|
144
144
|
|
|
145
|
-
const getProduct = memoize(async function(handle: string): Promise<ShopifyProductEntity> {
|
|
145
|
+
const getProduct = memoize(async function (handle: string): Promise<ShopifyProductEntity> {
|
|
146
146
|
return (await fetch(`${PRODUCTS_URL}${handle}.js`)).json();
|
|
147
147
|
});
|
|
148
148
|
|
|
@@ -246,13 +246,7 @@ export const config = (
|
|
|
246
246
|
action
|
|
247
247
|
) => {
|
|
248
248
|
if (constants.RECEIVE_PRODUCT_PLANS === action.type) {
|
|
249
|
-
const frequencies = [
|
|
250
|
-
...new Set(
|
|
251
|
-
Object.values(action.payload)
|
|
252
|
-
.map(Object.keys)
|
|
253
|
-
.flat()
|
|
254
|
-
)
|
|
255
|
-
];
|
|
249
|
+
const frequencies = [...new Set(Object.values(action.payload).map(Object.keys).flat())];
|
|
256
250
|
return {
|
|
257
251
|
...state,
|
|
258
252
|
frequencies
|
package/src/test-mode.js
CHANGED
|
@@ -14,11 +14,11 @@ export const enable = () => {
|
|
|
14
14
|
let keysCounter = 0;
|
|
15
15
|
document.addEventListener(
|
|
16
16
|
'keyup',
|
|
17
|
-
async function(e) {
|
|
17
|
+
async function (e) {
|
|
18
18
|
const key = e.which;
|
|
19
19
|
if (key === keys[keysCounter]) {
|
|
20
20
|
const currentkeys = keys[keysCounter];
|
|
21
|
-
setTimeout(function() {
|
|
21
|
+
setTimeout(function () {
|
|
22
22
|
if (keysCounter <= currentkeys) keysCounter = 0;
|
|
23
23
|
}, 5000);
|
|
24
24
|
keysCounter += 1;
|
package/tsconfig.json
CHANGED