@ordergroove/offers 2.45.3 → 2.45.4-alpha-PR-1235-7.274
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/dist/bundle-report.html +13 -13
- package/dist/examples.js +2 -2
- package/dist/examples.js.map +3 -3
- package/dist/offers.js +2 -2
- package/dist/offers.js.map +3 -3
- package/package.json +5 -5
- package/src/core/__tests__/api.spec.js +71 -48
- package/src/index.js +1 -0
- package/src/shopify/__tests__/shopifyMiddleware.spec.js +13 -11
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ordergroove/offers",
|
|
3
|
-
"version": "2.45.
|
|
3
|
+
"version": "2.45.4-alpha-PR-1235-7.274+a9bcab55",
|
|
4
4
|
"description": "offer state component",
|
|
5
5
|
"author": "Eugenio Lattanzio <eugenio63@gmail.com>",
|
|
6
6
|
"homepage": "https://github.com/ordergroove/plush-toys#readme",
|
|
@@ -35,8 +35,8 @@
|
|
|
35
35
|
}
|
|
36
36
|
],
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@ordergroove/auth": "^2.3.
|
|
39
|
-
"@ordergroove/offers-live-editor": "^0.6.
|
|
38
|
+
"@ordergroove/auth": "^2.3.4-alpha-PR-1235-7.2006+a9bcab55",
|
|
39
|
+
"@ordergroove/offers-live-editor": "^0.6.9-alpha-PR-1235-7.274+a9bcab55",
|
|
40
40
|
"lit-element": "^2.1.0",
|
|
41
41
|
"lodash.memoize": "^4.1.2",
|
|
42
42
|
"logical-expression-parser": "1.0.0",
|
|
@@ -46,8 +46,8 @@
|
|
|
46
46
|
"throttle-debounce": "^2.1.0"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
|
-
"@ordergroove/offers-templates": "^0.9.7",
|
|
49
|
+
"@ordergroove/offers-templates": "^0.9.8-alpha-PR-1235-7.539+a9bcab55",
|
|
50
50
|
"@types/lodash.memoize": "^4.1.9"
|
|
51
51
|
},
|
|
52
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "a9bcab55608940a294cde12e9d678b8daa6ce355"
|
|
53
53
|
}
|
|
@@ -2,12 +2,16 @@ import fetchMock from 'fetch-mock';
|
|
|
2
2
|
|
|
3
3
|
import { api, toQuery, withFetchJson, withAuth, withHost, parseFrequency } from '../api';
|
|
4
4
|
|
|
5
|
-
const MATCHED = fetchMock.MATCHED;
|
|
6
5
|
describe('api.fetchOffer', () => {
|
|
7
6
|
describe('test request', () => {
|
|
8
|
-
beforeEach(() =>
|
|
7
|
+
beforeEach(() => {
|
|
8
|
+
fetchMock.route('*', {}).mockGlobal();
|
|
9
|
+
});
|
|
9
10
|
|
|
10
|
-
afterEach(() =>
|
|
11
|
+
afterEach(() => {
|
|
12
|
+
fetchMock.removeRoutes();
|
|
13
|
+
fetchMock.unmockGlobal();
|
|
14
|
+
});
|
|
11
15
|
|
|
12
16
|
it('should export fetchOffer method', () => {
|
|
13
17
|
expect(typeof api.fetchOffer).toEqual('function');
|
|
@@ -30,7 +34,7 @@ describe('api.fetchOffer', () => {
|
|
|
30
34
|
|
|
31
35
|
it('should call correct merchant endpoint with params', async () => {
|
|
32
36
|
await api.fetchOffer('https://staging.offers.ordergroove.com', 'some-merchant', 'some-session', 'some-product');
|
|
33
|
-
const lastUrl = fetchMock.
|
|
37
|
+
const lastUrl = fetchMock.callHistory.lastCall().url;
|
|
34
38
|
expect(lastUrl).toContain('https://staging.offers.ordergroove.com/offer/some-merchant/pdp');
|
|
35
39
|
expect(lastUrl).toContain('session_id=some-session');
|
|
36
40
|
expect(lastUrl).toContain('page_type=1');
|
|
@@ -47,7 +51,7 @@ describe('api.fetchOffer', () => {
|
|
|
47
51
|
];
|
|
48
52
|
const expected = encodeURIComponent('["yum product"]');
|
|
49
53
|
await api.fetchOffer('some-host', 'some-merchant', 'some-session', mockProducts);
|
|
50
|
-
const lastUrl = fetchMock.
|
|
54
|
+
const lastUrl = fetchMock.callHistory.lastCall().url;
|
|
51
55
|
expect(lastUrl).toContain(expected);
|
|
52
56
|
});
|
|
53
57
|
|
|
@@ -65,22 +69,25 @@ describe('api.fetchOffer', () => {
|
|
|
65
69
|
];
|
|
66
70
|
const expected = encodeURIComponent('["yum product 1","product-as-string","yum product 2"]');
|
|
67
71
|
await api.fetchOffer('some-host', 'some-merchant', 'some-session', mockProducts);
|
|
68
|
-
const lastUrl = fetchMock.
|
|
72
|
+
const lastUrl = fetchMock.callHistory.lastCall().url;
|
|
69
73
|
expect(lastUrl).toContain(expected);
|
|
70
74
|
});
|
|
71
75
|
});
|
|
72
76
|
|
|
73
77
|
describe('test response', () => {
|
|
74
|
-
afterEach(() =>
|
|
78
|
+
afterEach(() => {
|
|
79
|
+
fetchMock.removeRoutes();
|
|
80
|
+
fetchMock.unmockGlobal();
|
|
81
|
+
});
|
|
75
82
|
|
|
76
83
|
it('should handle json response', async () => {
|
|
77
|
-
fetchMock.
|
|
84
|
+
fetchMock.route('*', { status: 200, body: { some: 'object' } }).mockGlobal();
|
|
78
85
|
const response = await api.fetchOffer('some-host', 'yum', 'yum', 'product');
|
|
79
86
|
expect(response).toEqual({ some: 'object' });
|
|
80
87
|
});
|
|
81
88
|
|
|
82
89
|
it('should reject promise if bad response', async () => {
|
|
83
|
-
fetchMock.
|
|
90
|
+
fetchMock.route('*', { status: 200, body: 'invalid json' }).mockGlobal();
|
|
84
91
|
await api.fetchOffer('some-host', 'yum', 'yum', 'another').then(fail, err => {
|
|
85
92
|
expect(err).toBeTruthy();
|
|
86
93
|
});
|
|
@@ -88,14 +95,18 @@ describe('api.fetchOffer', () => {
|
|
|
88
95
|
});
|
|
89
96
|
|
|
90
97
|
describe('memoization', () => {
|
|
91
|
-
afterEach(() =>
|
|
98
|
+
afterEach(() => {
|
|
99
|
+
fetchMock.removeRoutes();
|
|
100
|
+
fetchMock.unmockGlobal();
|
|
101
|
+
});
|
|
92
102
|
|
|
93
103
|
it('should fetch once', async () => {
|
|
94
|
-
fetchMock.
|
|
104
|
+
fetchMock.route('*', { status: 200, body: { some: 'object' } }).mockGlobal();
|
|
105
|
+
fetchMock.callHistory.clear();
|
|
95
106
|
const one = await api.fetchOffer('some-host', 'yum1', 'yum', 'product');
|
|
96
107
|
const two = await api.fetchOffer('some-host', 'yum1', 'yum', 'product');
|
|
97
108
|
expect(one).toEqual(two);
|
|
98
|
-
expect(fetchMock.calls().length).toEqual(1);
|
|
109
|
+
expect(fetchMock.callHistory.calls().length).toEqual(1);
|
|
99
110
|
});
|
|
100
111
|
});
|
|
101
112
|
});
|
|
@@ -106,12 +117,13 @@ describe('helpers', () => {
|
|
|
106
117
|
});
|
|
107
118
|
|
|
108
119
|
it('should fetch and return json', async () => {
|
|
109
|
-
fetchMock.
|
|
120
|
+
fetchMock.route('*', { status: 200, body: { some: 'object' } }).mockGlobal();
|
|
110
121
|
const fn = jasmine.createSpy('fn').and.returnValue(['/foo']);
|
|
111
122
|
const rs = await withFetchJson(fn)();
|
|
112
|
-
expect(fetchMock.
|
|
123
|
+
expect(fetchMock.callHistory.lastCall().url).toContain('/foo');
|
|
113
124
|
expect(rs).toEqual({ some: 'object' });
|
|
114
|
-
fetchMock.
|
|
125
|
+
fetchMock.removeRoutes();
|
|
126
|
+
fetchMock.unmockGlobal();
|
|
115
127
|
});
|
|
116
128
|
});
|
|
117
129
|
|
|
@@ -188,9 +200,14 @@ describe('helpers', () => {
|
|
|
188
200
|
});
|
|
189
201
|
describe('api.fetchOrders', () => {
|
|
190
202
|
describe('test request', () => {
|
|
191
|
-
beforeEach(() =>
|
|
203
|
+
beforeEach(() => {
|
|
204
|
+
fetchMock.route('*', {}).mockGlobal();
|
|
205
|
+
});
|
|
192
206
|
|
|
193
|
-
afterEach(() =>
|
|
207
|
+
afterEach(() => {
|
|
208
|
+
fetchMock.removeRoutes();
|
|
209
|
+
fetchMock.unmockGlobal();
|
|
210
|
+
});
|
|
194
211
|
|
|
195
212
|
const underTest = api.fetchOrders;
|
|
196
213
|
|
|
@@ -210,18 +227,18 @@ describe('api.fetchOrders', () => {
|
|
|
210
227
|
|
|
211
228
|
it('should pass authorization as JSON stringify header', async () => {
|
|
212
229
|
await underTest('https://host.com', { some: 'auth' });
|
|
213
|
-
expect(fetchMock.
|
|
230
|
+
expect(fetchMock.callHistory.lastCall().options).toEqual(
|
|
214
231
|
jasmine.objectContaining({
|
|
215
|
-
headers: {
|
|
216
|
-
|
|
217
|
-
}
|
|
232
|
+
headers: jasmine.objectContaining({
|
|
233
|
+
authorization: '{"some":"auth"}'
|
|
234
|
+
})
|
|
218
235
|
})
|
|
219
236
|
);
|
|
220
237
|
});
|
|
221
238
|
|
|
222
239
|
it('should call endpoint default params', async () => {
|
|
223
240
|
await underTest('https://host.com', { some: 'auth' }, 2, 'foo');
|
|
224
|
-
expect(fetchMock.
|
|
241
|
+
expect(fetchMock.callHistory.lastCall().url).toEqual(
|
|
225
242
|
'https://host.com/orders/?status=2&ordering=foo&exclude_prepaid_orders=true'
|
|
226
243
|
);
|
|
227
244
|
});
|
|
@@ -250,20 +267,23 @@ describe('api.fetchOrders', () => {
|
|
|
250
267
|
});
|
|
251
268
|
|
|
252
269
|
it('should call iu endpoint', async () => {
|
|
253
|
-
fetchMock.
|
|
270
|
+
fetchMock.route('*', { status: 200, body: { some: 'object' } }).mockGlobal();
|
|
254
271
|
await api.createOneTime('https://some-host', { some: 'auth' }, 'yum-product', 'some-order', 1, 'yum-offer');
|
|
255
|
-
expect(fetchMock.
|
|
256
|
-
expect(fetchMock.
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
272
|
+
expect(fetchMock.callHistory.lastCall().url).toEqual('https://some-host/items/iu/');
|
|
273
|
+
expect(fetchMock.callHistory.lastCall().options).toEqual(
|
|
274
|
+
jasmine.objectContaining({
|
|
275
|
+
method: 'post',
|
|
276
|
+
body: JSON.stringify({
|
|
277
|
+
product: 'yum-product',
|
|
278
|
+
order: 'some-order',
|
|
279
|
+
quantity: 1,
|
|
280
|
+
offer: 'yum-offer'
|
|
281
|
+
}),
|
|
282
|
+
headers: jasmine.any(Object)
|
|
283
|
+
})
|
|
284
|
+
);
|
|
285
|
+
fetchMock.removeRoutes();
|
|
286
|
+
fetchMock.unmockGlobal();
|
|
267
287
|
});
|
|
268
288
|
});
|
|
269
289
|
|
|
@@ -303,22 +323,25 @@ describe('api.fetchOrders', () => {
|
|
|
303
323
|
});
|
|
304
324
|
|
|
305
325
|
it('should convertOneTimeToSubscription call iu endpoint', async () => {
|
|
306
|
-
fetchMock.
|
|
326
|
+
fetchMock.route('*', { status: 200, body: { some: 'object' } }).mockGlobal();
|
|
307
327
|
const offer = 'some-offer-id';
|
|
308
328
|
const expected = ['https://some-host', { some: 'auth' }, { public_id: 'yum-item' }, '1_2', offer];
|
|
309
329
|
await api.convertOneTimeToSubscription(...expected);
|
|
310
|
-
expect(fetchMock.
|
|
311
|
-
expect(fetchMock.
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
330
|
+
expect(fetchMock.callHistory.lastCall().url).toEqual('https://some-host/subscriptions/create_from_item/');
|
|
331
|
+
expect(fetchMock.callHistory.lastCall().options).toEqual(
|
|
332
|
+
jasmine.objectContaining({
|
|
333
|
+
method: 'post',
|
|
334
|
+
body: JSON.stringify({
|
|
335
|
+
item: 'yum-item',
|
|
336
|
+
offer,
|
|
337
|
+
every: 1,
|
|
338
|
+
every_period: 2
|
|
339
|
+
}),
|
|
340
|
+
headers: jasmine.any(Object)
|
|
341
|
+
})
|
|
342
|
+
);
|
|
343
|
+
fetchMock.removeRoutes();
|
|
344
|
+
fetchMock.unmockGlobal();
|
|
322
345
|
});
|
|
323
346
|
});
|
|
324
347
|
});
|
package/src/index.js
CHANGED
|
@@ -8,6 +8,7 @@ import { autoInitializeOffers, onReady } from './core/utils';
|
|
|
8
8
|
import { authorizeShopifyCustomer } from './shopify/shopifyBootstrap';
|
|
9
9
|
import shopifyTrackingMiddleware from './shopify/shopifyTrackingMiddleware';
|
|
10
10
|
|
|
11
|
+
console.log('Offers store initializing');
|
|
11
12
|
export const store = makeStore(
|
|
12
13
|
...(platform?.shopify_selling_plans ? [shopifyReducer, shopifyMiddleware] : [defaultReducer]),
|
|
13
14
|
platform.shopify && shopifyTrackingMiddleware
|
|
@@ -106,8 +106,8 @@ describe('synchronizeCartOptin', () => {
|
|
|
106
106
|
frequency = '1234';
|
|
107
107
|
product = { id: '38995975209111:original-hash' };
|
|
108
108
|
|
|
109
|
-
fetchMock.
|
|
110
|
-
'cart.js',
|
|
109
|
+
fetchMock.route(
|
|
110
|
+
'/cart.js',
|
|
111
111
|
{
|
|
112
112
|
attributes: {},
|
|
113
113
|
items: [
|
|
@@ -117,11 +117,11 @@ describe('synchronizeCartOptin', () => {
|
|
|
117
117
|
}
|
|
118
118
|
]
|
|
119
119
|
},
|
|
120
|
-
{ method: 'GET' }
|
|
120
|
+
{ method: 'GET', repeat: 1 }
|
|
121
121
|
);
|
|
122
122
|
|
|
123
|
-
fetchMock.
|
|
124
|
-
'cart/change.js',
|
|
123
|
+
fetchMock.route(
|
|
124
|
+
'/cart/change.js',
|
|
125
125
|
{
|
|
126
126
|
attributes: {},
|
|
127
127
|
items: [
|
|
@@ -131,12 +131,14 @@ describe('synchronizeCartOptin', () => {
|
|
|
131
131
|
}
|
|
132
132
|
]
|
|
133
133
|
},
|
|
134
|
-
{ method: 'POST' }
|
|
134
|
+
{ method: 'POST', repeat: 1 }
|
|
135
135
|
);
|
|
136
|
+
|
|
137
|
+
fetchMock.mockGlobal();
|
|
136
138
|
});
|
|
137
139
|
|
|
138
140
|
afterEach(() => {
|
|
139
|
-
fetchMock.
|
|
141
|
+
fetchMock.removeRoutes().unmockGlobal();
|
|
140
142
|
offer.remove();
|
|
141
143
|
});
|
|
142
144
|
|
|
@@ -171,7 +173,7 @@ describe('synchronizeCartOptin', () => {
|
|
|
171
173
|
document.body.appendChild(sectionDiv);
|
|
172
174
|
|
|
173
175
|
await synchronizeCartOptin({ type: OPTIN_PRODUCT, payload: { offer, frequency, product } }, store);
|
|
174
|
-
expect(fetchMock.
|
|
176
|
+
expect(fetchMock.callHistory.lastCall().options.body).toContain('"sections":["123456789__cart-items"]');
|
|
175
177
|
sectionDiv.remove();
|
|
176
178
|
});
|
|
177
179
|
|
|
@@ -183,7 +185,7 @@ describe('synchronizeCartOptin', () => {
|
|
|
183
185
|
document.body.appendChild(sectionDiv);
|
|
184
186
|
|
|
185
187
|
await synchronizeCartOptin({ type: OPTIN_PRODUCT, payload: { offer, frequency, product } }, store);
|
|
186
|
-
expect(fetchMock.
|
|
188
|
+
expect(fetchMock.callHistory.lastCall().options.body).toContain('"sections":["123456789__cart-footer"]');
|
|
187
189
|
sectionDiv.remove();
|
|
188
190
|
});
|
|
189
191
|
|
|
@@ -221,7 +223,7 @@ describe('synchronizeCartOptin', () => {
|
|
|
221
223
|
}
|
|
222
224
|
});
|
|
223
225
|
|
|
224
|
-
expect(fetchMock.
|
|
226
|
+
expect(fetchMock.callHistory.lastCall().options.body).toContain('"selling_plan":"688815178030"');
|
|
225
227
|
});
|
|
226
228
|
|
|
227
229
|
it('should have no selling plan when product is opted out', async () => {
|
|
@@ -252,7 +254,7 @@ describe('synchronizeCartOptin', () => {
|
|
|
252
254
|
}
|
|
253
255
|
});
|
|
254
256
|
|
|
255
|
-
expect(fetchMock.
|
|
257
|
+
expect(fetchMock.callHistory.lastCall().options.body).toContain('"selling_plan":null');
|
|
256
258
|
});
|
|
257
259
|
});
|
|
258
260
|
|