@phystack/products 4.4.29

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.
Files changed (44) hide show
  1. package/CHANGELOG.md +2736 -0
  2. package/dist/api.d.ts +11 -0
  3. package/dist/api.js +49 -0
  4. package/dist/helpers.d.ts +2 -0
  5. package/dist/helpers.js +11 -0
  6. package/dist/index.d.ts +7 -0
  7. package/dist/index.js +29 -0
  8. package/dist/index.test.d.ts +1 -0
  9. package/dist/index.test.js +1423 -0
  10. package/dist/services/grid-product-service-admin.d.ts +23 -0
  11. package/dist/services/grid-product-service-admin.js +120 -0
  12. package/dist/services/grid-product-service-client.d.ts +80 -0
  13. package/dist/services/grid-product-service-client.js +633 -0
  14. package/dist/services/grid-product-service-interface.d.ts +47 -0
  15. package/dist/services/grid-product-service-interface.js +2 -0
  16. package/dist/services/http-service.d.ts +14 -0
  17. package/dist/services/http-service.js +44 -0
  18. package/dist/types/grid-product.d.ts +458 -0
  19. package/dist/types/grid-product.js +38 -0
  20. package/dist/types/iso-currency-codes.d.ts +182 -0
  21. package/dist/types/iso-currency-codes.js +186 -0
  22. package/dist/types/iso-language-ids.d.ts +170 -0
  23. package/dist/types/iso-language-ids.js +174 -0
  24. package/dist/types/parameters.d.ts +242 -0
  25. package/dist/types/parameters.js +99 -0
  26. package/dist/utils.d.ts +27 -0
  27. package/dist/utils.js +187 -0
  28. package/jest.config.js +10 -0
  29. package/jest.setup.js +1 -0
  30. package/package.json +31 -0
  31. package/src/api.ts +47 -0
  32. package/src/helpers.ts +7 -0
  33. package/src/index.test.ts +1526 -0
  34. package/src/index.ts +8 -0
  35. package/src/services/grid-product-service-admin.ts +123 -0
  36. package/src/services/grid-product-service-client.ts +995 -0
  37. package/src/services/grid-product-service-interface.ts +105 -0
  38. package/src/services/http-service.ts +50 -0
  39. package/src/types/grid-product.ts +548 -0
  40. package/src/types/iso-currency-codes.ts +182 -0
  41. package/src/types/iso-language-ids.ts +170 -0
  42. package/src/types/parameters.ts +231 -0
  43. package/src/utils.ts +325 -0
  44. package/tsconfig.json +20 -0
@@ -0,0 +1,1423 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ // @ts-ignore
16
+ const faker_1 = require("@faker-js/faker");
17
+ const grid_product_service_client_1 = __importDefault(require("./services/grid-product-service-client"));
18
+ const iso_language_ids_1 = require("./types/iso-language-ids");
19
+ const grid_product_1 = require("./types/grid-product");
20
+ jest.mock('./services/http-service');
21
+ const HttpService = require('./services/http-service');
22
+ const mockHttpService = (httpService) => HttpService.default.mockImplementation(() => {
23
+ return httpService;
24
+ });
25
+ const initGridService = (props = {}) => {
26
+ var _a, _b, _c, _d;
27
+ return new grid_product_service_client_1.default({
28
+ tenantId: (_a = props.tenantId) !== null && _a !== void 0 ? _a : faker_1.faker.datatype.uuid(),
29
+ environment: (_b = props.environment) !== null && _b !== void 0 ? _b : 'prod',
30
+ dataResidency: (_c = props.dataResidency) !== null && _c !== void 0 ? _c : grid_product_1.DataResidencyEnum.EU,
31
+ locale: (_d = props.locale) !== null && _d !== void 0 ? _d : iso_language_ids_1.IsoLanguageIds.en_GB,
32
+ fallbackLocale: props.fallbackLocale,
33
+ });
34
+ };
35
+ const buildGridProduct = (props = {}) => {
36
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
37
+ return ({
38
+ productGroupId: (_a = props.productGroupId) !== null && _a !== void 0 ? _a : faker_1.faker.datatype.uuid(),
39
+ spaceIds: (_b = props.spaceIds) !== null && _b !== void 0 ? _b : [],
40
+ productShortDescription: (_c = props.productShortDescription) !== null && _c !== void 0 ? _c : [],
41
+ productName: (_d = props.productName) !== null && _d !== void 0 ? _d : [],
42
+ productDescription: (_e = props.productDescription) !== null && _e !== void 0 ? _e : [],
43
+ variants: (_f = props.variants) !== null && _f !== void 0 ? _f : [],
44
+ brand: (_g = props.brand) !== null && _g !== void 0 ? _g : [],
45
+ productStatus: (_h = props.productStatus) !== null && _h !== void 0 ? _h : [],
46
+ productFeature: (_j = props.productFeature) !== null && _j !== void 0 ? _j : [],
47
+ productPriceList: (_k = props.productPriceList) !== null && _k !== void 0 ? _k : [],
48
+ catalogPageLocationProduct: (_l = props.catalogPageLocationProduct) !== null && _l !== void 0 ? _l : [],
49
+ productType: (_m = props.productType) !== null && _m !== void 0 ? _m : [],
50
+ productLabel: (_o = props.productLabel) !== null && _o !== void 0 ? _o : [],
51
+ productItemQuantity: (_p = props.productItemQuantity) !== null && _p !== void 0 ? _p : [],
52
+ });
53
+ };
54
+ const runTests = ({ testCases, selector }) => {
55
+ testCases.forEach((testCase) => {
56
+ test(testCase.hint, () => __awaiter(void 0, void 0, void 0, function* () {
57
+ mockHttpService({
58
+ get: jest.fn().mockReturnValue(Promise.resolve({ data: testCase.product })),
59
+ });
60
+ const gridService = initGridService(testCase.serviceProps);
61
+ const product = yield gridService.getProductById(faker_1.faker.datatype.uuid(), {});
62
+ const value = selector(product, testCase.props);
63
+ expect(value).toEqual(testCase.expected);
64
+ }));
65
+ });
66
+ };
67
+ beforeEach(() => {
68
+ jest.clearAllMocks();
69
+ });
70
+ describe('Grid product selectors.', () => {
71
+ describe('getShortDescription', () => {
72
+ const testCases = [
73
+ {
74
+ product: buildGridProduct({
75
+ productShortDescription: [
76
+ {
77
+ isoLanguageId: iso_language_ids_1.IsoLanguageIds.en_GB,
78
+ productShortDescription: 'product description',
79
+ },
80
+ {
81
+ isoLanguageId: iso_language_ids_1.IsoLanguageIds.it_IT,
82
+ productShortDescription: faker_1.faker.lorem.paragraph(),
83
+ },
84
+ ],
85
+ }),
86
+ props: undefined,
87
+ expected: 'product description',
88
+ hint: 'Returns localized value.',
89
+ },
90
+ {
91
+ product: buildGridProduct({
92
+ productShortDescription: [
93
+ {
94
+ isoLanguageId: iso_language_ids_1.IsoLanguageIds.en_GB,
95
+ productShortDescription: 'product description',
96
+ },
97
+ {
98
+ isoLanguageId: iso_language_ids_1.IsoLanguageIds.sv_SE,
99
+ productShortDescription: faker_1.faker.lorem.paragraph(),
100
+ },
101
+ ],
102
+ }),
103
+ props: undefined,
104
+ serviceProps: {
105
+ locale: iso_language_ids_1.IsoLanguageIds.it_IT,
106
+ fallbackLocale: iso_language_ids_1.IsoLanguageIds.en_GB,
107
+ },
108
+ expected: 'product description',
109
+ hint: 'Returns english value if there is no localized value.',
110
+ },
111
+ {
112
+ product: buildGridProduct({
113
+ productShortDescription: [
114
+ {
115
+ isoLanguageId: iso_language_ids_1.IsoLanguageIds.it_IT,
116
+ productShortDescription: faker_1.faker.lorem.paragraph(),
117
+ },
118
+ {
119
+ isoLanguageId: iso_language_ids_1.IsoLanguageIds.it_IT,
120
+ productShortDescription: faker_1.faker.lorem.paragraph(),
121
+ },
122
+ ],
123
+ }),
124
+ props: undefined,
125
+ expected: '',
126
+ hint: 'Returns empty string if there is no localized value.',
127
+ },
128
+ {
129
+ product: buildGridProduct({
130
+ productShortDescription: [
131
+ {
132
+ isoLanguageId: iso_language_ids_1.IsoLanguageIds.en_GB,
133
+ productShortDescription: faker_1.faker.lorem.paragraph(),
134
+ },
135
+ {
136
+ isoLanguageId: iso_language_ids_1.IsoLanguageIds.it_IT,
137
+ productShortDescription: 'italian description',
138
+ },
139
+ ],
140
+ }),
141
+ props: { locale: iso_language_ids_1.IsoLanguageIds.it_IT },
142
+ expected: 'italian description',
143
+ hint: 'Returns localized value with custom locale.',
144
+ },
145
+ {
146
+ product: buildGridProduct({
147
+ productShortDescription: [
148
+ {
149
+ isoLanguageId: iso_language_ids_1.IsoLanguageIds.en_GB,
150
+ productShortDescription: 'english description',
151
+ },
152
+ {
153
+ isoLanguageId: iso_language_ids_1.IsoLanguageIds.it_IT,
154
+ productShortDescription: 'italian description',
155
+ },
156
+ ],
157
+ }),
158
+ props: { locale: '*' },
159
+ expected: [
160
+ {
161
+ isoLanguageId: iso_language_ids_1.IsoLanguageIds.en_GB,
162
+ productShortDescription: 'english description',
163
+ },
164
+ {
165
+ isoLanguageId: iso_language_ids_1.IsoLanguageIds.it_IT,
166
+ productShortDescription: 'italian description',
167
+ },
168
+ ],
169
+ hint: 'Returns list of data.',
170
+ },
171
+ ];
172
+ runTests({
173
+ testCases,
174
+ selector: (product, selectorProps) => product.getShortDescription(selectorProps),
175
+ });
176
+ });
177
+ describe('getLabel', () => {
178
+ const testCases = [
179
+ {
180
+ product: buildGridProduct({
181
+ productLabel: [
182
+ {
183
+ isoLanguageId: iso_language_ids_1.IsoLanguageIds.en_GB,
184
+ spaceId: '1',
185
+ productLabel: 'label 1',
186
+ },
187
+ {
188
+ isoLanguageId: iso_language_ids_1.IsoLanguageIds.en_GB,
189
+ spaceId: '1',
190
+ productLabel: 'label 2',
191
+ },
192
+ {
193
+ isoLanguageId: iso_language_ids_1.IsoLanguageIds.it_IT,
194
+ spaceId: '1',
195
+ productLabel: 'label 3',
196
+ },
197
+ ],
198
+ }),
199
+ props: undefined,
200
+ expected: ['label 1', 'label 2'],
201
+ hint: 'Returns list of localized labels.',
202
+ },
203
+ {
204
+ product: buildGridProduct({
205
+ productLabel: [
206
+ {
207
+ isoLanguageId: iso_language_ids_1.IsoLanguageIds.en_GB,
208
+ spaceId: '1',
209
+ productLabel: 'label 1',
210
+ },
211
+ {
212
+ isoLanguageId: iso_language_ids_1.IsoLanguageIds.en_GB,
213
+ spaceId: '1',
214
+ productLabel: 'label 2',
215
+ },
216
+ {
217
+ isoLanguageId: iso_language_ids_1.IsoLanguageIds.sv_SE,
218
+ spaceId: '1',
219
+ productLabel: 'label 3',
220
+ },
221
+ ],
222
+ }),
223
+ props: undefined,
224
+ serviceProps: {
225
+ locale: iso_language_ids_1.IsoLanguageIds.it_IT,
226
+ fallbackLocale: iso_language_ids_1.IsoLanguageIds.en_GB,
227
+ },
228
+ expected: ['label 1', 'label 2'],
229
+ hint: 'Returns list of english labels if there are no localized labels.',
230
+ },
231
+ {
232
+ product: buildGridProduct({
233
+ productLabel: [
234
+ {
235
+ isoLanguageId: iso_language_ids_1.IsoLanguageIds.en_GB,
236
+ spaceId: '1',
237
+ productLabel: 'label 1',
238
+ },
239
+ {
240
+ isoLanguageId: iso_language_ids_1.IsoLanguageIds.en_GB,
241
+ spaceId: '1',
242
+ productLabel: 'label 2',
243
+ },
244
+ {
245
+ isoLanguageId: iso_language_ids_1.IsoLanguageIds.it_IT,
246
+ spaceId: '1',
247
+ productLabel: 'label 3',
248
+ },
249
+ ],
250
+ }),
251
+ props: { locale: '*' },
252
+ expected: ['label 1', 'label 2', 'label 3'],
253
+ hint: 'Returns all labels.',
254
+ },
255
+ {
256
+ product: buildGridProduct({
257
+ productLabel: [
258
+ {
259
+ isoLanguageId: iso_language_ids_1.IsoLanguageIds.en_GB,
260
+ spaceId: '1',
261
+ productLabel: 'label 1',
262
+ },
263
+ {
264
+ isoLanguageId: iso_language_ids_1.IsoLanguageIds.en_GB,
265
+ spaceId: '1',
266
+ productLabel: 'label 2',
267
+ },
268
+ {
269
+ isoLanguageId: iso_language_ids_1.IsoLanguageIds.en_GB,
270
+ spaceId: '2',
271
+ productLabel: 'label 3',
272
+ },
273
+ {
274
+ isoLanguageId: iso_language_ids_1.IsoLanguageIds.it_IT,
275
+ spaceId: '3',
276
+ productLabel: 'label 4',
277
+ },
278
+ ],
279
+ }),
280
+ props: { filter: (item) => item.spaceId === '1' },
281
+ expected: ['label 1', 'label 2'],
282
+ hint: 'Returns localized space specific labels.',
283
+ },
284
+ {
285
+ product: buildGridProduct({
286
+ productLabel: [
287
+ {
288
+ isoLanguageId: iso_language_ids_1.IsoLanguageIds.en_GB,
289
+ spaceId: '1',
290
+ productLabel: 'label 1',
291
+ },
292
+ {
293
+ isoLanguageId: iso_language_ids_1.IsoLanguageIds.en_GB,
294
+ spaceId: '1',
295
+ productLabel: 'label 2',
296
+ },
297
+ {
298
+ isoLanguageId: iso_language_ids_1.IsoLanguageIds.it_IT,
299
+ spaceId: '1',
300
+ productLabel: 'label 3',
301
+ },
302
+ ],
303
+ }),
304
+ props: { locale: '*', filter: (item) => item.spaceId === '1' },
305
+ expected: ['label 1', 'label 2', 'label 3'],
306
+ hint: 'Returns all space specific labels.',
307
+ },
308
+ {
309
+ product: buildGridProduct({
310
+ productLabel: [
311
+ {
312
+ isoLanguageId: iso_language_ids_1.IsoLanguageIds.en_GB,
313
+ spaceId: '1',
314
+ productLabel: 'label 1',
315
+ },
316
+ {
317
+ isoLanguageId: iso_language_ids_1.IsoLanguageIds.en_GB,
318
+ spaceId: '1',
319
+ productLabel: 'label 2',
320
+ },
321
+ {
322
+ isoLanguageId: iso_language_ids_1.IsoLanguageIds.en_GB,
323
+ spaceId: '2',
324
+ productLabel: 'label 3',
325
+ },
326
+ ],
327
+ }),
328
+ props: {
329
+ filter: (item) => ['1', '2'].includes(item.spaceId),
330
+ },
331
+ expected: ['label 1', 'label 2', 'label 3'],
332
+ hint: 'Returns all localized space specific labels. Several conditions used.',
333
+ },
334
+ ];
335
+ runTests({
336
+ testCases,
337
+ selector: (product, selectorProps) => product.getLabel(selectorProps),
338
+ });
339
+ });
340
+ describe('getLabelBySpace', () => {
341
+ const testCases = [
342
+ {
343
+ product: buildGridProduct({
344
+ productLabel: [
345
+ {
346
+ isoLanguageId: iso_language_ids_1.IsoLanguageIds.en_GB,
347
+ spaceId: '1',
348
+ productLabel: 'label 1',
349
+ },
350
+ {
351
+ isoLanguageId: iso_language_ids_1.IsoLanguageIds.en_GB,
352
+ spaceId: '1',
353
+ productLabel: 'label 2',
354
+ },
355
+ {
356
+ isoLanguageId: iso_language_ids_1.IsoLanguageIds.it_IT,
357
+ spaceId: '1',
358
+ productLabel: 'label 3',
359
+ },
360
+ ],
361
+ }),
362
+ props: { spaceId: '1' },
363
+ expected: ['label 1', 'label 2'],
364
+ hint: 'Returns space localized labels.',
365
+ },
366
+ {
367
+ product: buildGridProduct({
368
+ productLabel: [
369
+ {
370
+ isoLanguageId: iso_language_ids_1.IsoLanguageIds.en_GB,
371
+ spaceId: '1',
372
+ productLabel: 'label 1',
373
+ },
374
+ {
375
+ isoLanguageId: iso_language_ids_1.IsoLanguageIds.en_GB,
376
+ spaceId: '1',
377
+ productLabel: 'label 2',
378
+ },
379
+ {
380
+ isoLanguageId: iso_language_ids_1.IsoLanguageIds.it_IT,
381
+ spaceId: '1',
382
+ productLabel: 'label 3',
383
+ },
384
+ ],
385
+ }),
386
+ props: { spaceId: '1' },
387
+ serviceProps: {
388
+ locale: iso_language_ids_1.IsoLanguageIds.sv_SE,
389
+ fallbackLocale: iso_language_ids_1.IsoLanguageIds.en_GB,
390
+ },
391
+ expected: ['label 1', 'label 2'],
392
+ hint: 'Returns space english labels if there are no localized labels.',
393
+ },
394
+ {
395
+ product: buildGridProduct({
396
+ productLabel: [
397
+ {
398
+ isoLanguageId: iso_language_ids_1.IsoLanguageIds.en_GB,
399
+ spaceId: '1',
400
+ productLabel: 'label 1',
401
+ },
402
+ {
403
+ isoLanguageId: iso_language_ids_1.IsoLanguageIds.en_GB,
404
+ spaceId: '1',
405
+ productLabel: 'label 2',
406
+ },
407
+ {
408
+ isoLanguageId: iso_language_ids_1.IsoLanguageIds.it_IT,
409
+ spaceId: '1',
410
+ productLabel: 'label 3',
411
+ },
412
+ ],
413
+ }),
414
+ props: { spaceId: '1', locale: '*' },
415
+ expected: ['label 1', 'label 2', 'label 3'],
416
+ hint: 'Returns space all labels.',
417
+ },
418
+ {
419
+ product: buildGridProduct({
420
+ productLabel: [],
421
+ }),
422
+ props: { spaceId: '1' },
423
+ expected: [],
424
+ hint: 'Returns empty list of labels.',
425
+ },
426
+ ];
427
+ runTests({
428
+ testCases,
429
+ selector: (product, selectorProps) => product.getLabelBySpace(selectorProps),
430
+ });
431
+ });
432
+ describe('getPriceList', () => {
433
+ const testCases = [
434
+ {
435
+ product: buildGridProduct({
436
+ productPriceList: [
437
+ {
438
+ productId: '1',
439
+ spaceId: '1',
440
+ priceListType: grid_product_1.PriceListTypeEnum.Standard,
441
+ isoCurrencyCode: 'EUR',
442
+ listPrice: 100,
443
+ },
444
+ {
445
+ productId: '2',
446
+ spaceId: '1',
447
+ priceListType: grid_product_1.PriceListTypeEnum.Standard,
448
+ isoCurrencyCode: 'EUR',
449
+ listPrice: 200,
450
+ },
451
+ ],
452
+ }),
453
+ props: undefined,
454
+ expected: [
455
+ {
456
+ productId: '1',
457
+ spaceId: '1',
458
+ priceListType: grid_product_1.PriceListTypeEnum.Standard,
459
+ isoCurrencyCode: 'EUR',
460
+ listPrice: 100,
461
+ },
462
+ {
463
+ productId: '2',
464
+ spaceId: '1',
465
+ priceListType: grid_product_1.PriceListTypeEnum.Standard,
466
+ isoCurrencyCode: 'EUR',
467
+ listPrice: 200,
468
+ },
469
+ ],
470
+ hint: 'Returns all product prices.',
471
+ },
472
+ {
473
+ product: buildGridProduct({
474
+ productPriceList: [
475
+ {
476
+ productId: '1',
477
+ spaceId: '1',
478
+ priceListType: grid_product_1.PriceListTypeEnum.Standard,
479
+ isoCurrencyCode: 'EUR',
480
+ listPrice: 100,
481
+ },
482
+ {
483
+ productId: '2',
484
+ spaceId: '1',
485
+ priceListType: grid_product_1.PriceListTypeEnum.Standard,
486
+ isoCurrencyCode: 'EUR',
487
+ listPrice: 200,
488
+ },
489
+ ],
490
+ }),
491
+ props: {
492
+ filter: (item) => item.productId === '1' &&
493
+ item.spaceId === '1' &&
494
+ item.priceListType === grid_product_1.PriceListTypeEnum.Standard,
495
+ },
496
+ expected: [
497
+ {
498
+ productId: '1',
499
+ spaceId: '1',
500
+ priceListType: grid_product_1.PriceListTypeEnum.Standard,
501
+ isoCurrencyCode: 'EUR',
502
+ listPrice: 100,
503
+ },
504
+ ],
505
+ hint: 'Returns product standard price.',
506
+ },
507
+ {
508
+ product: buildGridProduct({
509
+ productPriceList: [
510
+ {
511
+ productId: '1',
512
+ spaceId: '1',
513
+ priceListType: grid_product_1.PriceListTypeEnum.Standard,
514
+ isoCurrencyCode: 'EUR',
515
+ listPrice: 100,
516
+ },
517
+ {
518
+ productId: '2',
519
+ spaceId: '1',
520
+ priceListType: grid_product_1.PriceListTypeEnum.Promotional,
521
+ isoCurrencyCode: 'EUR',
522
+ listPrice: 200,
523
+ },
524
+ ],
525
+ }),
526
+ props: {
527
+ filter: (item) => item.productId === '2' &&
528
+ item.spaceId === '1' &&
529
+ item.priceListType === grid_product_1.PriceListTypeEnum.Promotional,
530
+ },
531
+ expected: [
532
+ {
533
+ productId: '2',
534
+ spaceId: '1',
535
+ priceListType: grid_product_1.PriceListTypeEnum.Promotional,
536
+ isoCurrencyCode: 'EUR',
537
+ listPrice: 200,
538
+ },
539
+ ],
540
+ hint: 'Returns product promotional price.',
541
+ },
542
+ {
543
+ product: buildGridProduct({
544
+ productPriceList: [
545
+ {
546
+ productId: '1',
547
+ spaceId: '1',
548
+ priceListType: grid_product_1.PriceListTypeEnum.Standard,
549
+ isoCurrencyCode: 'EUR',
550
+ listPrice: 100,
551
+ },
552
+ {
553
+ productId: '2',
554
+ spaceId: '1',
555
+ priceListType: grid_product_1.PriceListTypeEnum.Promotional,
556
+ isoCurrencyCode: 'EUR',
557
+ listPrice: 200,
558
+ },
559
+ ],
560
+ }),
561
+ props: {
562
+ filter: (item) => item.productId === '2' &&
563
+ item.spaceId === '1' &&
564
+ item.priceListType === grid_product_1.PriceListTypeEnum.Standard,
565
+ },
566
+ expected: [],
567
+ hint: 'Returns empty list.',
568
+ },
569
+ ];
570
+ runTests({
571
+ testCases,
572
+ selector: (product, selectorProps) => product.getPriceList(selectorProps),
573
+ });
574
+ });
575
+ describe('getStandardPrice', () => {
576
+ const testCases = [
577
+ {
578
+ product: buildGridProduct({
579
+ productPriceList: [
580
+ {
581
+ productId: '1',
582
+ spaceId: '1',
583
+ priceListType: grid_product_1.PriceListTypeEnum.Standard,
584
+ isoCurrencyCode: 'EUR',
585
+ listPrice: 100,
586
+ },
587
+ {
588
+ productId: '2',
589
+ spaceId: '1',
590
+ priceListType: grid_product_1.PriceListTypeEnum.Standard,
591
+ isoCurrencyCode: 'EUR',
592
+ listPrice: 200,
593
+ },
594
+ ],
595
+ }),
596
+ props: { spaceId: '1' },
597
+ expected: { amount: 100, currencyCode: 'EUR' },
598
+ hint: 'Returns first available standard price.',
599
+ },
600
+ {
601
+ product: buildGridProduct({
602
+ productPriceList: [
603
+ {
604
+ productId: '1',
605
+ spaceId: '1',
606
+ priceListType: grid_product_1.PriceListTypeEnum.Promotional,
607
+ isoCurrencyCode: 'EUR',
608
+ listPrice: 100,
609
+ },
610
+ {
611
+ productId: '2',
612
+ spaceId: '2',
613
+ priceListType: grid_product_1.PriceListTypeEnum.Promotional,
614
+ isoCurrencyCode: 'EUR',
615
+ listPrice: 200,
616
+ },
617
+ ],
618
+ }),
619
+ props: { spaceId: '3' },
620
+ expected: undefined,
621
+ hint: 'Returns undefined.',
622
+ },
623
+ ];
624
+ runTests({
625
+ testCases,
626
+ selector: (product, selectorProps) => product.getStandardPrice(selectorProps),
627
+ });
628
+ });
629
+ describe('getPromotionalPrice', () => {
630
+ const testCases = [
631
+ {
632
+ product: buildGridProduct({
633
+ productPriceList: [
634
+ {
635
+ productId: '1',
636
+ spaceId: '1',
637
+ priceListType: grid_product_1.PriceListTypeEnum.Promotional,
638
+ isoCurrencyCode: 'EUR',
639
+ listPrice: 100,
640
+ },
641
+ {
642
+ productId: '2',
643
+ spaceId: '1',
644
+ priceListType: grid_product_1.PriceListTypeEnum.Promotional,
645
+ isoCurrencyCode: 'EUR',
646
+ listPrice: 200,
647
+ },
648
+ ],
649
+ }),
650
+ props: { spaceId: '1' },
651
+ expected: { amount: 100, currencyCode: 'EUR' },
652
+ hint: 'Returns first available promotional price.',
653
+ },
654
+ {
655
+ product: buildGridProduct({
656
+ productPriceList: [
657
+ {
658
+ productId: '1',
659
+ spaceId: '1',
660
+ priceListType: grid_product_1.PriceListTypeEnum.Standard,
661
+ isoCurrencyCode: 'EUR',
662
+ listPrice: 100,
663
+ },
664
+ {
665
+ productId: '2',
666
+ spaceId: '1',
667
+ priceListType: grid_product_1.PriceListTypeEnum.Standard,
668
+ isoCurrencyCode: 'EUR',
669
+ listPrice: 200,
670
+ },
671
+ ],
672
+ }),
673
+ props: { spaceId: '3' },
674
+ expected: undefined,
675
+ hint: 'Returns undefined.',
676
+ },
677
+ ];
678
+ runTests({
679
+ testCases,
680
+ selector: (product, selectorProps) => product.getPromotionalPrice(selectorProps),
681
+ });
682
+ });
683
+ describe('getName', () => {
684
+ const testCases = [
685
+ {
686
+ product: buildGridProduct({
687
+ productName: [
688
+ {
689
+ isoLanguageId: iso_language_ids_1.IsoLanguageIds.en_GB,
690
+ productName: 'product name',
691
+ },
692
+ {
693
+ isoLanguageId: iso_language_ids_1.IsoLanguageIds.it_IT,
694
+ productName: faker_1.faker.lorem.paragraph(),
695
+ },
696
+ ],
697
+ }),
698
+ props: undefined,
699
+ expected: 'product name',
700
+ hint: 'Returns localized value.',
701
+ },
702
+ {
703
+ product: buildGridProduct({
704
+ productName: [
705
+ {
706
+ isoLanguageId: iso_language_ids_1.IsoLanguageIds.en_GB,
707
+ productName: 'product name',
708
+ },
709
+ {
710
+ isoLanguageId: iso_language_ids_1.IsoLanguageIds.ar_BH,
711
+ productName: faker_1.faker.lorem.paragraph(),
712
+ },
713
+ ],
714
+ }),
715
+ props: undefined,
716
+ serviceProps: {
717
+ locale: iso_language_ids_1.IsoLanguageIds.it_IT,
718
+ fallbackLocale: iso_language_ids_1.IsoLanguageIds.en_GB,
719
+ },
720
+ expected: 'product name',
721
+ hint: 'Returns english value if there is no localized value.',
722
+ },
723
+ {
724
+ product: buildGridProduct({
725
+ productName: [
726
+ {
727
+ isoLanguageId: iso_language_ids_1.IsoLanguageIds.it_IT,
728
+ productName: faker_1.faker.lorem.paragraph(),
729
+ },
730
+ {
731
+ isoLanguageId: iso_language_ids_1.IsoLanguageIds.it_IT,
732
+ productName: faker_1.faker.lorem.paragraph(),
733
+ },
734
+ ],
735
+ }),
736
+ props: undefined,
737
+ expected: '',
738
+ hint: 'Returns empty string if there is no localized value.',
739
+ },
740
+ {
741
+ product: buildGridProduct({
742
+ productName: [
743
+ {
744
+ isoLanguageId: iso_language_ids_1.IsoLanguageIds.en_GB,
745
+ productName: faker_1.faker.lorem.paragraph(),
746
+ },
747
+ {
748
+ isoLanguageId: iso_language_ids_1.IsoLanguageIds.it_IT,
749
+ productName: 'italian name',
750
+ },
751
+ ],
752
+ }),
753
+ props: { locale: iso_language_ids_1.IsoLanguageIds.it_IT },
754
+ expected: 'italian name',
755
+ hint: 'Returns localized value with custom locale.',
756
+ },
757
+ {
758
+ product: buildGridProduct({
759
+ productName: [
760
+ {
761
+ isoLanguageId: iso_language_ids_1.IsoLanguageIds.en_GB,
762
+ productName: 'english name',
763
+ },
764
+ {
765
+ isoLanguageId: iso_language_ids_1.IsoLanguageIds.it_IT,
766
+ productName: 'italian name',
767
+ },
768
+ ],
769
+ }),
770
+ props: { locale: '*' },
771
+ expected: [
772
+ {
773
+ isoLanguageId: iso_language_ids_1.IsoLanguageIds.en_GB,
774
+ productName: 'english name',
775
+ },
776
+ {
777
+ isoLanguageId: iso_language_ids_1.IsoLanguageIds.it_IT,
778
+ productName: 'italian name',
779
+ },
780
+ ],
781
+ hint: 'Returns list of data.',
782
+ },
783
+ ];
784
+ runTests({
785
+ testCases,
786
+ selector: (product, selectorProps) => product.getName(selectorProps),
787
+ });
788
+ });
789
+ describe('getDescription', () => {
790
+ const testCases = [
791
+ {
792
+ product: buildGridProduct({
793
+ productDescription: [
794
+ {
795
+ isoLanguageId: iso_language_ids_1.IsoLanguageIds.en_GB,
796
+ productDescription: 'product description',
797
+ },
798
+ {
799
+ isoLanguageId: iso_language_ids_1.IsoLanguageIds.it_IT,
800
+ productDescription: faker_1.faker.lorem.paragraph(),
801
+ },
802
+ ],
803
+ }),
804
+ props: undefined,
805
+ expected: 'product description',
806
+ hint: 'Returns localized value.',
807
+ },
808
+ {
809
+ product: buildGridProduct({
810
+ productDescription: [
811
+ {
812
+ isoLanguageId: iso_language_ids_1.IsoLanguageIds.en_GB,
813
+ productDescription: 'product description',
814
+ },
815
+ {
816
+ isoLanguageId: iso_language_ids_1.IsoLanguageIds.sv_SE,
817
+ productDescription: faker_1.faker.lorem.paragraph(),
818
+ },
819
+ ],
820
+ }),
821
+ props: undefined,
822
+ serviceProps: {
823
+ locale: iso_language_ids_1.IsoLanguageIds.it_IT,
824
+ fallbackLocale: iso_language_ids_1.IsoLanguageIds.en_GB,
825
+ },
826
+ expected: 'product description',
827
+ hint: 'Returns english value if there is no localized value.',
828
+ },
829
+ {
830
+ product: buildGridProduct({
831
+ productDescription: [
832
+ {
833
+ isoLanguageId: iso_language_ids_1.IsoLanguageIds.it_IT,
834
+ productDescription: faker_1.faker.lorem.paragraph(),
835
+ },
836
+ {
837
+ isoLanguageId: iso_language_ids_1.IsoLanguageIds.it_IT,
838
+ productDescription: faker_1.faker.lorem.paragraph(),
839
+ },
840
+ ],
841
+ }),
842
+ props: undefined,
843
+ expected: '',
844
+ hint: 'Returns empty string if there is no localized value.',
845
+ },
846
+ {
847
+ product: buildGridProduct({
848
+ productDescription: [
849
+ {
850
+ isoLanguageId: iso_language_ids_1.IsoLanguageIds.en_GB,
851
+ productDescription: faker_1.faker.lorem.paragraph(),
852
+ },
853
+ {
854
+ isoLanguageId: iso_language_ids_1.IsoLanguageIds.it_IT,
855
+ productDescription: 'italian description',
856
+ },
857
+ ],
858
+ }),
859
+ props: { locale: iso_language_ids_1.IsoLanguageIds.it_IT },
860
+ expected: 'italian description',
861
+ hint: 'Returns localized value with custom locale.',
862
+ },
863
+ {
864
+ product: buildGridProduct({
865
+ productDescription: [
866
+ {
867
+ isoLanguageId: iso_language_ids_1.IsoLanguageIds.en_GB,
868
+ productDescription: 'english description',
869
+ },
870
+ {
871
+ isoLanguageId: iso_language_ids_1.IsoLanguageIds.it_IT,
872
+ productDescription: 'italian description',
873
+ },
874
+ ],
875
+ }),
876
+ props: { locale: '*' },
877
+ expected: [
878
+ {
879
+ isoLanguageId: iso_language_ids_1.IsoLanguageIds.en_GB,
880
+ productDescription: 'english description',
881
+ },
882
+ {
883
+ isoLanguageId: iso_language_ids_1.IsoLanguageIds.it_IT,
884
+ productDescription: 'italian description',
885
+ },
886
+ ],
887
+ hint: 'Returns list of data.',
888
+ },
889
+ ];
890
+ runTests({
891
+ testCases,
892
+ selector: (product, selectorProps) => product.getDescription(selectorProps),
893
+ });
894
+ });
895
+ describe('getBrandName', () => {
896
+ const testCases = [
897
+ {
898
+ product: buildGridProduct({
899
+ brand: [
900
+ {
901
+ isoLanguageId: iso_language_ids_1.IsoLanguageIds.en_GB,
902
+ brandName: 'brand name',
903
+ },
904
+ {
905
+ isoLanguageId: iso_language_ids_1.IsoLanguageIds.it_IT,
906
+ brandName: faker_1.faker.lorem.paragraph(),
907
+ },
908
+ ],
909
+ }),
910
+ props: undefined,
911
+ expected: 'brand name',
912
+ hint: 'Returns localized value.',
913
+ },
914
+ {
915
+ product: buildGridProduct({
916
+ brand: [
917
+ {
918
+ isoLanguageId: iso_language_ids_1.IsoLanguageIds.en_GB,
919
+ brandName: 'brand name',
920
+ },
921
+ {
922
+ isoLanguageId: iso_language_ids_1.IsoLanguageIds.sv_SE,
923
+ brandName: faker_1.faker.lorem.paragraph(),
924
+ },
925
+ ],
926
+ }),
927
+ props: undefined,
928
+ serviceProps: {
929
+ locale: iso_language_ids_1.IsoLanguageIds.it_IT,
930
+ fallbackLocale: iso_language_ids_1.IsoLanguageIds.en_GB,
931
+ },
932
+ expected: 'brand name',
933
+ hint: 'Returns english value if there is no localized value.',
934
+ },
935
+ {
936
+ product: buildGridProduct({
937
+ brand: [
938
+ {
939
+ isoLanguageId: iso_language_ids_1.IsoLanguageIds.it_IT,
940
+ brandName: faker_1.faker.lorem.paragraph(),
941
+ },
942
+ {
943
+ isoLanguageId: iso_language_ids_1.IsoLanguageIds.it_IT,
944
+ brandName: faker_1.faker.lorem.paragraph(),
945
+ },
946
+ ],
947
+ }),
948
+ props: undefined,
949
+ expected: '',
950
+ hint: 'Returns empty string if there is no localized value.',
951
+ },
952
+ {
953
+ product: buildGridProduct({
954
+ brand: [
955
+ {
956
+ isoLanguageId: iso_language_ids_1.IsoLanguageIds.en_GB,
957
+ brandName: faker_1.faker.lorem.paragraph(),
958
+ },
959
+ {
960
+ isoLanguageId: iso_language_ids_1.IsoLanguageIds.it_IT,
961
+ brandName: 'italian brand name',
962
+ },
963
+ ],
964
+ }),
965
+ props: { locale: iso_language_ids_1.IsoLanguageIds.it_IT },
966
+ expected: 'italian brand name',
967
+ hint: 'Returns localized value with custom locale.',
968
+ },
969
+ {
970
+ product: buildGridProduct({
971
+ brand: [
972
+ {
973
+ isoLanguageId: iso_language_ids_1.IsoLanguageIds.en_GB,
974
+ brandName: 'english brand name',
975
+ },
976
+ {
977
+ isoLanguageId: iso_language_ids_1.IsoLanguageIds.it_IT,
978
+ brandName: 'italian brand name',
979
+ },
980
+ ],
981
+ }),
982
+ props: { locale: '*' },
983
+ expected: [
984
+ {
985
+ isoLanguageId: iso_language_ids_1.IsoLanguageIds.en_GB,
986
+ brandName: 'english brand name',
987
+ },
988
+ {
989
+ isoLanguageId: iso_language_ids_1.IsoLanguageIds.it_IT,
990
+ brandName: 'italian brand name',
991
+ },
992
+ ],
993
+ hint: 'Returns list of data.',
994
+ },
995
+ ];
996
+ runTests({
997
+ testCases,
998
+ selector: (product, selectorProps) => product.getBrandName(selectorProps),
999
+ });
1000
+ });
1001
+ describe('getImages', () => {
1002
+ const testCases = [
1003
+ {
1004
+ product: buildGridProduct({
1005
+ catalogPageLocationProduct: [
1006
+ {
1007
+ productId: '1',
1008
+ productGroupId: '1',
1009
+ catalogType: faker_1.faker.lorem.word(),
1010
+ catalogPageLocationProduct: 'image 1',
1011
+ },
1012
+ {
1013
+ productId: '1',
1014
+ productGroupId: '1',
1015
+ catalogType: faker_1.faker.lorem.word(),
1016
+ catalogPageLocationProduct: 'image 2',
1017
+ },
1018
+ {
1019
+ productId: '2',
1020
+ productGroupId: '2',
1021
+ catalogType: faker_1.faker.lorem.word(),
1022
+ catalogPageLocationProduct: 'image 3',
1023
+ },
1024
+ ],
1025
+ }),
1026
+ props: undefined,
1027
+ expected: ['image 1', 'image 2', 'image 3'],
1028
+ hint: 'Returns product images.',
1029
+ },
1030
+ {
1031
+ product: buildGridProduct({
1032
+ catalogPageLocationProduct: [],
1033
+ }),
1034
+ props: undefined,
1035
+ expected: [],
1036
+ hint: 'Returns empty list of product images.',
1037
+ },
1038
+ ];
1039
+ runTests({
1040
+ testCases,
1041
+ selector: (products) => products.getImages(),
1042
+ });
1043
+ });
1044
+ describe('getImage', () => {
1045
+ const testCases = [
1046
+ {
1047
+ product: buildGridProduct({
1048
+ catalogPageLocationProduct: [
1049
+ {
1050
+ productId: '1',
1051
+ productGroupId: '1',
1052
+ catalogType: faker_1.faker.lorem.word(),
1053
+ catalogPageLocationProduct: 'image 1',
1054
+ },
1055
+ {
1056
+ productId: '1',
1057
+ productGroupId: '1',
1058
+ catalogType: faker_1.faker.lorem.word(),
1059
+ catalogPageLocationProduct: 'image 2',
1060
+ },
1061
+ {
1062
+ productId: '2',
1063
+ productGroupId: '2',
1064
+ catalogType: faker_1.faker.lorem.word(),
1065
+ catalogPageLocationProduct: 'image 3',
1066
+ },
1067
+ ],
1068
+ }),
1069
+ props: undefined,
1070
+ expected: 'image 1',
1071
+ hint: 'Returns first image.',
1072
+ },
1073
+ {
1074
+ product: buildGridProduct({
1075
+ catalogPageLocationProduct: [],
1076
+ }),
1077
+ props: undefined,
1078
+ expected: '',
1079
+ hint: 'Returns empty string.',
1080
+ },
1081
+ ];
1082
+ runTests({
1083
+ testCases,
1084
+ selector: (products) => products.getImage(),
1085
+ });
1086
+ });
1087
+ describe('getFirstVariant', () => {
1088
+ const testCases = [
1089
+ {
1090
+ product: buildGridProduct({
1091
+ variants: [
1092
+ {
1093
+ productId: '1',
1094
+ productGroupId: '1',
1095
+ },
1096
+ {
1097
+ productId: '2',
1098
+ productGroupId: '1',
1099
+ },
1100
+ ],
1101
+ }),
1102
+ props: undefined,
1103
+ expected: { productId: '1', productGroupId: '1' },
1104
+ hint: 'Returns first variant.',
1105
+ },
1106
+ ];
1107
+ runTests({
1108
+ testCases,
1109
+ selector: (products) => products.getFirstVariant(),
1110
+ });
1111
+ });
1112
+ describe('getVariantFeature', () => {
1113
+ const testCases = [
1114
+ {
1115
+ product: buildGridProduct({
1116
+ productFeature: [
1117
+ {
1118
+ productId: '1',
1119
+ isoLanguageId: iso_language_ids_1.IsoLanguageIds.en_GB,
1120
+ productFeatureType: 'type 1',
1121
+ productFeatureValue: 'value 1',
1122
+ },
1123
+ {
1124
+ productId: '1',
1125
+ isoLanguageId: iso_language_ids_1.IsoLanguageIds.en_GB,
1126
+ productFeatureType: 'type 2',
1127
+ productFeatureValue: 'value 2',
1128
+ },
1129
+ {
1130
+ productId: '1',
1131
+ isoLanguageId: iso_language_ids_1.IsoLanguageIds.it_IT,
1132
+ productFeatureType: 'type 3',
1133
+ productFeatureValue: 'value 3',
1134
+ },
1135
+ ],
1136
+ }),
1137
+ props: { productId: '1' },
1138
+ expected: [
1139
+ {
1140
+ productId: '1',
1141
+ isoLanguageId: iso_language_ids_1.IsoLanguageIds.en_GB,
1142
+ productFeatureType: 'type 1',
1143
+ productFeatureValue: 'value 1',
1144
+ },
1145
+ {
1146
+ productId: '1',
1147
+ isoLanguageId: iso_language_ids_1.IsoLanguageIds.en_GB,
1148
+ productFeatureType: 'type 2',
1149
+ productFeatureValue: 'value 2',
1150
+ },
1151
+ ],
1152
+ hint: 'Returns localized list of product features.',
1153
+ },
1154
+ {
1155
+ product: buildGridProduct({
1156
+ productFeature: [
1157
+ {
1158
+ productId: '1',
1159
+ isoLanguageId: iso_language_ids_1.IsoLanguageIds.en_GB,
1160
+ productFeatureType: 'type 1',
1161
+ productFeatureValue: 'value 1',
1162
+ },
1163
+ {
1164
+ productId: '1',
1165
+ isoLanguageId: iso_language_ids_1.IsoLanguageIds.en_GB,
1166
+ productFeatureType: 'type 2',
1167
+ productFeatureValue: 'value 2',
1168
+ },
1169
+ {
1170
+ productId: '1',
1171
+ isoLanguageId: iso_language_ids_1.IsoLanguageIds.sv_SE,
1172
+ productFeatureType: 'type 3',
1173
+ productFeatureValue: 'value 3',
1174
+ },
1175
+ ],
1176
+ }),
1177
+ props: { productId: '1' },
1178
+ serviceProps: {
1179
+ locale: iso_language_ids_1.IsoLanguageIds.it_IT,
1180
+ fallbackLocale: iso_language_ids_1.IsoLanguageIds.en_GB,
1181
+ },
1182
+ expected: [
1183
+ {
1184
+ productId: '1',
1185
+ isoLanguageId: iso_language_ids_1.IsoLanguageIds.en_GB,
1186
+ productFeatureType: 'type 1',
1187
+ productFeatureValue: 'value 1',
1188
+ },
1189
+ {
1190
+ productId: '1',
1191
+ isoLanguageId: iso_language_ids_1.IsoLanguageIds.en_GB,
1192
+ productFeatureType: 'type 2',
1193
+ productFeatureValue: 'value 2',
1194
+ },
1195
+ ],
1196
+ hint: 'Returns english list of product features if there are no localized list.',
1197
+ },
1198
+ {
1199
+ product: buildGridProduct({
1200
+ productFeature: [
1201
+ {
1202
+ productId: '1',
1203
+ isoLanguageId: iso_language_ids_1.IsoLanguageIds.en_GB,
1204
+ productFeatureType: 'type 1',
1205
+ productFeatureValue: 'value 1',
1206
+ },
1207
+ {
1208
+ productId: '1',
1209
+ isoLanguageId: iso_language_ids_1.IsoLanguageIds.en_GB,
1210
+ productFeatureType: 'type 2',
1211
+ productFeatureValue: 'value 2',
1212
+ },
1213
+ {
1214
+ productId: '1',
1215
+ isoLanguageId: iso_language_ids_1.IsoLanguageIds.it_IT,
1216
+ productFeatureType: 'type 3',
1217
+ productFeatureValue: 'value 3',
1218
+ },
1219
+ ],
1220
+ }),
1221
+ props: { productId: '1', locale: '*' },
1222
+ expected: [
1223
+ {
1224
+ productId: '1',
1225
+ isoLanguageId: iso_language_ids_1.IsoLanguageIds.en_GB,
1226
+ productFeatureType: 'type 1',
1227
+ productFeatureValue: 'value 1',
1228
+ },
1229
+ {
1230
+ productId: '1',
1231
+ isoLanguageId: iso_language_ids_1.IsoLanguageIds.en_GB,
1232
+ productFeatureType: 'type 2',
1233
+ productFeatureValue: 'value 2',
1234
+ },
1235
+ {
1236
+ productId: '1',
1237
+ isoLanguageId: iso_language_ids_1.IsoLanguageIds.it_IT,
1238
+ productFeatureType: 'type 3',
1239
+ productFeatureValue: 'value 3',
1240
+ },
1241
+ ],
1242
+ hint: 'Returns all products features.',
1243
+ },
1244
+ ];
1245
+ runTests({
1246
+ testCases,
1247
+ selector: (products, selectorProps) => products.getVariantFeature(selectorProps),
1248
+ });
1249
+ });
1250
+ describe('getVariantStandardPrice', () => {
1251
+ const testCases = [
1252
+ {
1253
+ product: buildGridProduct({
1254
+ productPriceList: [
1255
+ {
1256
+ productId: '1',
1257
+ spaceId: '1',
1258
+ priceListType: grid_product_1.PriceListTypeEnum.Standard,
1259
+ isoCurrencyCode: 'EUR',
1260
+ listPrice: 100,
1261
+ },
1262
+ {
1263
+ productId: '2',
1264
+ spaceId: '1',
1265
+ priceListType: grid_product_1.PriceListTypeEnum.Standard,
1266
+ isoCurrencyCode: 'EUR',
1267
+ listPrice: 200,
1268
+ },
1269
+ ],
1270
+ }),
1271
+ props: { variantId: '1', spaceId: '1' },
1272
+ expected: { amount: 100, currencyCode: 'EUR' },
1273
+ hint: 'Returns variant standard price.',
1274
+ },
1275
+ {
1276
+ product: buildGridProduct({
1277
+ productPriceList: [
1278
+ {
1279
+ productId: '1',
1280
+ spaceId: '1',
1281
+ priceListType: grid_product_1.PriceListTypeEnum.Promotional,
1282
+ isoCurrencyCode: 'EUR',
1283
+ listPrice: 100,
1284
+ },
1285
+ {
1286
+ productId: '2',
1287
+ spaceId: '2',
1288
+ priceListType: grid_product_1.PriceListTypeEnum.Promotional,
1289
+ isoCurrencyCode: 'EUR',
1290
+ listPrice: 200,
1291
+ },
1292
+ ],
1293
+ }),
1294
+ props: { variantId: '1', spaceId: '2' },
1295
+ expected: undefined,
1296
+ hint: 'Returns undefined.',
1297
+ },
1298
+ ];
1299
+ runTests({
1300
+ testCases,
1301
+ selector: (product, selectorProps) => product.getVariantStandardPrice(selectorProps),
1302
+ });
1303
+ });
1304
+ describe('getVariantPromotionalPrice', () => {
1305
+ const testCases = [
1306
+ {
1307
+ product: buildGridProduct({
1308
+ productPriceList: [
1309
+ {
1310
+ productId: '1',
1311
+ spaceId: '1',
1312
+ priceListType: grid_product_1.PriceListTypeEnum.Promotional,
1313
+ isoCurrencyCode: 'EUR',
1314
+ listPrice: 100,
1315
+ },
1316
+ {
1317
+ productId: '2',
1318
+ spaceId: '1',
1319
+ priceListType: grid_product_1.PriceListTypeEnum.Promotional,
1320
+ isoCurrencyCode: 'EUR',
1321
+ listPrice: 200,
1322
+ },
1323
+ ],
1324
+ }),
1325
+ props: { variantId: '1', spaceId: '1' },
1326
+ expected: { amount: 100, currencyCode: 'EUR' },
1327
+ hint: 'Returns variant promotional price.',
1328
+ },
1329
+ {
1330
+ product: buildGridProduct({
1331
+ productPriceList: [
1332
+ {
1333
+ productId: '1',
1334
+ spaceId: '1',
1335
+ priceListType: grid_product_1.PriceListTypeEnum.Standard,
1336
+ isoCurrencyCode: 'EUR',
1337
+ listPrice: 100,
1338
+ },
1339
+ {
1340
+ productId: '2',
1341
+ spaceId: '1',
1342
+ priceListType: grid_product_1.PriceListTypeEnum.Standard,
1343
+ isoCurrencyCode: 'EUR',
1344
+ listPrice: 200,
1345
+ },
1346
+ ],
1347
+ }),
1348
+ props: { variantId: '1', spaceId: '1' },
1349
+ expected: undefined,
1350
+ hint: 'Returns undefined.',
1351
+ },
1352
+ ];
1353
+ runTests({
1354
+ testCases,
1355
+ selector: (product, selectorProps) => product.getVariantPromotionalPrice(selectorProps),
1356
+ });
1357
+ });
1358
+ describe('getVariantQuantity', () => {
1359
+ const testCases = [
1360
+ {
1361
+ product: buildGridProduct({
1362
+ productItemQuantity: [
1363
+ {
1364
+ productId: '1',
1365
+ spaceId: '1',
1366
+ productItemQuantity: 2,
1367
+ },
1368
+ {
1369
+ productId: '1',
1370
+ spaceId: '2',
1371
+ productItemQuantity: 4,
1372
+ },
1373
+ ],
1374
+ }),
1375
+ props: { variantId: '1' },
1376
+ expected: 6,
1377
+ hint: 'Returns products quantity within all spaces.',
1378
+ },
1379
+ {
1380
+ product: buildGridProduct({
1381
+ productItemQuantity: [
1382
+ {
1383
+ productId: '1',
1384
+ spaceId: '1',
1385
+ productItemQuantity: 2,
1386
+ },
1387
+ {
1388
+ productId: '1',
1389
+ spaceId: '2',
1390
+ productItemQuantity: 4,
1391
+ },
1392
+ ],
1393
+ }),
1394
+ props: { variantId: '1', spaceId: '1' },
1395
+ expected: 2,
1396
+ hint: 'Returns products quantity within specific spaces.',
1397
+ },
1398
+ {
1399
+ product: buildGridProduct({
1400
+ productItemQuantity: [
1401
+ {
1402
+ productId: '1',
1403
+ spaceId: '1',
1404
+ productItemQuantity: 2,
1405
+ },
1406
+ {
1407
+ productId: '1',
1408
+ spaceId: '2',
1409
+ productItemQuantity: 4,
1410
+ },
1411
+ ],
1412
+ }),
1413
+ props: { variantId: '1', spaceId: '10' },
1414
+ expected: 0,
1415
+ hint: 'Returns 0 quantity if there are no products.',
1416
+ },
1417
+ ];
1418
+ runTests({
1419
+ testCases,
1420
+ selector: (products, selectorProps) => products.getVariantQuantity(selectorProps),
1421
+ });
1422
+ });
1423
+ });