@phystack/products 4.3.40-dev

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