idosell 0.4.34 → 0.4.41

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.
@@ -0,0 +1,97 @@
1
+ import { utils } from '../dist/index';
2
+ import { PARAMETER_PRODUCT, PARAMETER_PRODUCT_RESULT } from './utilTestData';
3
+
4
+ // mapProductParameters.test.ts
5
+ import { describe, it, expect } from 'vitest';
6
+
7
+ const makeLangData = (langId, name) => ({
8
+ langId,
9
+ parameterName: name,
10
+ parameterDescription: '',
11
+ parameterShopsData: [],
12
+ });
13
+
14
+ const makeValueLangData = (langId, valueName) => ({
15
+ langId,
16
+ parameterValueName: valueName,
17
+ parameterValueDescription: '',
18
+ parameterValueShopsData: [],
19
+ });
20
+
21
+ const makeParam = (id, name, values, langId = 'pol') => ({
22
+ parameterId: id,
23
+ parameterType: 'parameter',
24
+ parameterDescriptionsLangData: [makeLangData(langId, name)],
25
+ parameterValues: values.map((v) => ({
26
+ parameterValueId: v.id,
27
+ parameterValueDescriptionsLangData: [makeValueLangData(langId, v.name)],
28
+ })),
29
+ });
30
+
31
+ describe('mapProductParameters', () => {
32
+ it('returns [] when productParameters is undefined', () => {
33
+ expect(utils.mapProductParameters({})).toEqual([]);
34
+ });
35
+
36
+ it('returns [] when productParameters is empty', () => {
37
+ expect(utils.mapProductParameters({ productParameters: [] })).toEqual([]);
38
+ });
39
+
40
+ it('skips parameters with null parameterValues', () => {
41
+ const product = {
42
+ productParameters: [
43
+ { ...makeParam(1, 'Color', [{ id: 10, name: 'Red' }]), parameterValues: null },
44
+ ],
45
+ };
46
+ expect(utils.mapProductParameters(product)).toEqual([]);
47
+ });
48
+
49
+ it('skips parameters with empty parameterValues', () => {
50
+ const product = {
51
+ productParameters: [{ ...makeParam(1, 'Color', []), parameterValues: [] }],
52
+ };
53
+ expect(utils.mapProductParameters(product)).toEqual([]);
54
+ });
55
+
56
+ it('maps a single parameter with values using default lang (pol)', () => {
57
+ const product = {
58
+ productParameters: [makeParam(1, 'Color', [{ id: 10, name: 'Red' }])],
59
+ };
60
+ expect(utils.mapProductParameters(product)).toEqual([
61
+ { id: 1, name: 'Color', values: [{ valueId: 10, value: 'Red' }] },
62
+ ]);
63
+ });
64
+
65
+ it('maps multiple parameters and multiple values', () => {
66
+ const product = {
67
+ productParameters: [
68
+ makeParam(1, 'Color', [{ id: 10, name: 'Red' }, { id: 11, name: 'Blue' }]),
69
+ makeParam(2, 'Size', [{ id: 20, name: 'M' }, { id: 21, name: 'L' }]),
70
+ ],
71
+ };
72
+ expect(utils.mapProductParameters(product)).toEqual([
73
+ { id: 1, name: 'Color', values: [{ valueId: 10, value: 'Red' }, { valueId: 11, value: 'Blue' }] },
74
+ { id: 2, name: 'Size', values: [{ valueId: 20, value: 'M' }, { valueId: 21, value: 'L' }] },
75
+ ]);
76
+ });
77
+
78
+ it('uses provided langId instead of default', () => {
79
+ const product = {
80
+ productParameters: [makeParam(1, 'Kolor', [{ id: 10, name: 'Czerwony' }], 'eng')],
81
+ };
82
+ expect(utils.mapProductParameters(product, 'eng')).toEqual([
83
+ { id: 1, name: 'Kolor', values: [{ valueId: 10, value: 'Czerwony' }] },
84
+ ]);
85
+ });
86
+
87
+ it('falls back to empty string when langId has no matching entry', () => {
88
+ const product = {
89
+ productParameters: [makeParam(1, 'Color', [{ id: 10, name: 'Red' }], 'pol')],
90
+ };
91
+ expect(utils.mapProductParameters(product, 'deu')).toEqual([
92
+ { id: 1, name: '', values: [{ valueId: 10, value: '' }] },
93
+ ]);
94
+ });
95
+
96
+ expect(utils.mapProductParameters(PARAMETER_PRODUCT)).toEqual(PARAMETER_PRODUCT_RESULT)
97
+ });
@@ -341,4 +341,241 @@ export const STOCK_PRODUCT: SearchProductsResponse['results'][number] = {
341
341
  "sizePanelName": "XL"
342
342
  }
343
343
  ]
344
- }
344
+ }
345
+
346
+ export const PARAMETER_PRODUCT: SearchProductsResponse['results'][number] = {
347
+ "productId": 356,
348
+ "productParameters": [
349
+ {
350
+ "parameterId": 326,
351
+ "parameterType": "parameter",
352
+ "parameterDescriptionsLangData": [
353
+ {
354
+ "langId": "eng",
355
+ "parameterName": "Kolor akcentów",
356
+ "parameterDescription": "",
357
+ "parameterShopsData": []
358
+ },
359
+ {
360
+ "langId": "ger",
361
+ "parameterName": "Kolor akcentów",
362
+ "parameterDescription": "",
363
+ "parameterShopsData": []
364
+ },
365
+ {
366
+ "langId": "pol",
367
+ "parameterName": "Kolor akcentów",
368
+ "parameterDescription": "",
369
+ "parameterShopsData": []
370
+ }
371
+ ],
372
+ "parameterValues": [
373
+ {
374
+ "parameterValueId": 399,
375
+ "parameterValueDescriptionsLangData": [
376
+ {
377
+ "langId": "eng",
378
+ "parameterValueName": "Czarny",
379
+ "parameterValueDescription": "",
380
+ "parameterValueShopsData": []
381
+ },
382
+ {
383
+ "langId": "ger",
384
+ "parameterValueName": "Czarny",
385
+ "parameterValueDescription": "",
386
+ "parameterValueShopsData": []
387
+ },
388
+ {
389
+ "langId": "pol",
390
+ "parameterValueName": "Czarny",
391
+ "parameterValueDescription": "",
392
+ "parameterValueShopsData": []
393
+ }
394
+ ]
395
+ }
396
+ ]
397
+ },
398
+ {
399
+ "parameterId": 173,
400
+ "parameterType": "parameter",
401
+ "parameterDescriptionsLangData": [
402
+ {
403
+ "langId": "eng",
404
+ "parameterName": "Waga całkowita",
405
+ "parameterDescription": "",
406
+ "parameterShopsData": []
407
+ },
408
+ {
409
+ "langId": "ger",
410
+ "parameterName": "Waga całkowita",
411
+ "parameterDescription": "",
412
+ "parameterShopsData": []
413
+ },
414
+ {
415
+ "langId": "pol",
416
+ "parameterName": "Waga całkowita",
417
+ "parameterDescription": "",
418
+ "parameterShopsData": []
419
+ }
420
+ ],
421
+ "parameterValues": [
422
+ {
423
+ "parameterValueId": 522,
424
+ "parameterValueDescriptionsLangData": [
425
+ {
426
+ "langId": "eng",
427
+ "parameterValueName": "100g",
428
+ "parameterValueDescription": "",
429
+ "parameterValueShopsData": []
430
+ },
431
+ {
432
+ "langId": "ger",
433
+ "parameterValueName": "100g",
434
+ "parameterValueDescription": "",
435
+ "parameterValueShopsData": []
436
+ },
437
+ {
438
+ "langId": "pol",
439
+ "parameterValueName": "100g",
440
+ "parameterValueDescription": "",
441
+ "parameterValueShopsData": []
442
+ }
443
+ ]
444
+ }
445
+ ]
446
+ },
447
+ {
448
+ "parameterId": 521,
449
+ "parameterType": "section",
450
+ "parameterDescriptionsLangData": [
451
+ {
452
+ "langId": "eng",
453
+ "parameterName": "XCut",
454
+ "parameterDescription": "",
455
+ "parameterShopsData": []
456
+ },
457
+ {
458
+ "langId": "ger",
459
+ "parameterName": "XCut",
460
+ "parameterDescription": "",
461
+ "parameterShopsData": []
462
+ },
463
+ {
464
+ "langId": "pol",
465
+ "parameterName": "XCut",
466
+ "parameterDescription": "",
467
+ "parameterShopsData": []
468
+ }
469
+ ]
470
+ },
471
+ {
472
+ "parameterId": 26,
473
+ "parameterType": "parameter",
474
+ "parameterDescriptionsLangData": [
475
+ {
476
+ "langId": "eng",
477
+ "parameterName": "Color",
478
+ "parameterDescription": "",
479
+ "parameterShopsData": []
480
+ },
481
+ {
482
+ "langId": "ger",
483
+ "parameterName": "Kolor",
484
+ "parameterDescription": "",
485
+ "parameterShopsData": []
486
+ },
487
+ {
488
+ "langId": "pol",
489
+ "parameterName": "Kolor",
490
+ "parameterDescription": "",
491
+ "parameterShopsData": []
492
+ }
493
+ ],
494
+ "parameterValues": [
495
+ {
496
+ "parameterValueId": 48,
497
+ "parameterValueDescriptionsLangData": [
498
+ {
499
+ "langId": "eng",
500
+ "parameterValueName": "Black",
501
+ "parameterValueDescription": "",
502
+ "parameterValueShopsData": []
503
+ },
504
+ {
505
+ "langId": "ger",
506
+ "parameterValueName": "czarny",
507
+ "parameterValueDescription": "",
508
+ "parameterValueShopsData": []
509
+ },
510
+ {
511
+ "langId": "pol",
512
+ "parameterValueName": "czarny",
513
+ "parameterValueDescription": "",
514
+ "parameterValueShopsData": []
515
+ }
516
+ ]
517
+ },
518
+ {
519
+ "parameterValueId": 96,
520
+ "parameterValueDescriptionsLangData": [
521
+ {
522
+ "langId": "eng",
523
+ "parameterValueName": "red",
524
+ "parameterValueDescription": "",
525
+ "parameterValueShopsData": []
526
+ },
527
+ {
528
+ "langId": "ger",
529
+ "parameterValueName": "czerwony",
530
+ "parameterValueDescription": "",
531
+ "parameterValueShopsData": []
532
+ },
533
+ {
534
+ "langId": "pol",
535
+ "parameterValueName": "czerwony",
536
+ "parameterValueDescription": "",
537
+ "parameterValueShopsData": []
538
+ }
539
+ ]
540
+ }
541
+ ]
542
+ }
543
+ ]
544
+ }
545
+
546
+ export const PARAMETER_PRODUCT_RESULT = [
547
+ {
548
+ "id": 326,
549
+ "name": "Kolor akcentów",
550
+ "values": [
551
+ {
552
+ "valueId": 399,
553
+ "value": "Czarny"
554
+ }
555
+ ]
556
+ },
557
+ {
558
+ "id": 173,
559
+ "name": "Waga całkowita",
560
+ "values": [
561
+ {
562
+ "valueId": 522,
563
+ "value": "100g"
564
+ }
565
+ ]
566
+ },
567
+ {
568
+ "id": 26,
569
+ "name": "Kolor",
570
+ "values": [
571
+ {
572
+ "valueId": 48,
573
+ "value": "czarny"
574
+ },
575
+ {
576
+ "valueId": 96,
577
+ "value": "czerwony"
578
+ }
579
+ ]
580
+ }
581
+ ]