generated from adobe/aem-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 174
/
wcs.test.js
71 lines (68 loc) · 2.32 KB
/
wcs.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import { ERROR_MESSAGE_OFFER_NOT_FOUND } from '../src/constants.js';
import { Defaults } from '../src/defaults.js';
import { Wcs } from '../src/wcs.js';
import { mockFetch } from './mocks/fetch.js';
import { withWcs } from './mocks/wcs.js';
import { expect } from './utilities.js';
describe('resolveOfferSelectors', () => {
it('falls into fetch-by-one strategy if Wcs responds with 404 to a multi-osi request', async () => {
await mockFetch(withWcs);
// @ts-ignore
const client = Wcs({
// @ts-ignore
settings: {
...Defaults,
locale: 'en_US',
wcsBufferLimit: 4,
},
});
const results = await Promise.allSettled(
client.resolveOfferSelectors({
wcsOsi: ['abm', 'no-offer', 'stock-abm', 'void'],
}),
);
expect(results[0].status).to.equal('fulfilled');
expect(results[1].status).to.equal('rejected');
// @ts-ignore
expect(results[1].reason.message).to.equal(
ERROR_MESSAGE_OFFER_NOT_FOUND,
);
expect(results[2].status).to.equal('fulfilled');
expect(results[3].status).to.equal('rejected');
// @ts-ignore
expect(results[3].reason.message).to.equal(
ERROR_MESSAGE_OFFER_NOT_FOUND,
);
});
it('groups WCS requests by promotion code', async () => {
await mockFetch(withWcs);
const client = Wcs({
// @ts-ignore
settings: {
...Defaults,
locale: 'en_US',
wcsBufferLimit: 2,
},
});
await Promise.allSettled([
...client.resolveOfferSelectors({
wcsOsi: ['abm', 'm2m'],
}),
...client.resolveOfferSelectors({
wcsOsi: ['abm', 'm2m'],
}),
]);
expect(fetch.callCount).to.equal(1);
await Promise.allSettled([
...client.resolveOfferSelectors({
wcsOsi: ['abm-promo', 'm2m-promo'],
promotionCode: 'promo1',
}),
...client.resolveOfferSelectors({
wcsOsi: ['abm-promo', 'm2m-promo'],
promotionCode: 'promo2',
}),
]);
expect(fetch.callCount).to.equal(3);
});
});