@adobe/spacecat-shared-tokowaka-client 1.3.2 → 1.4.1

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.
@@ -586,7 +586,6 @@ describe('GenericMapper', () => {
586
586
  selector: '#selector',
587
587
  },
588
588
  patchValue: 'Content with tag',
589
- format: 'hast',
590
589
  tag: 'div',
591
590
  url: 'https://example.com/page',
592
591
  }),
@@ -601,7 +600,7 @@ describe('GenericMapper', () => {
601
600
  op: 'insertAfter',
602
601
  selector: '#selector',
603
602
  value: 'Content with tag',
604
- valueFormat: 'hast',
603
+ valueFormat: 'text',
605
604
  tag: 'div',
606
605
  opportunityId: 'opp-tag',
607
606
  suggestionId: 'sugg-with-tag',
@@ -633,6 +632,142 @@ describe('GenericMapper', () => {
633
632
  expect(patch.valueFormat).to.equal('text');
634
633
  });
635
634
 
635
+ it('should parse JSON patchValue when format is hast', () => {
636
+ const hastValue = {
637
+ type: 'element',
638
+ tagName: 'div',
639
+ properties: { className: ['test-class'] },
640
+ children: [{ type: 'text', value: 'Test content' }],
641
+ };
642
+
643
+ const suggestion = {
644
+ getId: () => 'sugg-hast-json',
645
+ getUpdatedAt: () => '2025-01-15T10:00:00.000Z',
646
+ getData: () => ({
647
+ transformRules: {
648
+ action: 'insertAfter',
649
+ selector: '#selector',
650
+ },
651
+ patchValue: JSON.stringify(hastValue),
652
+ format: 'hast',
653
+ url: 'https://example.com/page',
654
+ }),
655
+ };
656
+
657
+ const patches = mapper.suggestionsToPatches('/page', [suggestion], 'opp-hast');
658
+
659
+ expect(patches.length).to.equal(1);
660
+ const patch = patches[0];
661
+
662
+ expect(patch.value).to.deep.equal(hastValue);
663
+ expect(patch.valueFormat).to.equal('hast');
664
+ });
665
+
666
+ it('should parse JSON patchValue when format is json', () => {
667
+ const jsonValue = {
668
+ title: 'Test Title',
669
+ description: 'Test description',
670
+ metadata: { key: 'value' },
671
+ };
672
+
673
+ const suggestion = {
674
+ getId: () => 'sugg-json-format',
675
+ getUpdatedAt: () => '2025-01-15T10:00:00.000Z',
676
+ getData: () => ({
677
+ transformRules: {
678
+ action: 'replace',
679
+ selector: '.content',
680
+ },
681
+ patchValue: JSON.stringify(jsonValue),
682
+ format: 'json',
683
+ url: 'https://example.com/page',
684
+ }),
685
+ };
686
+
687
+ const patches = mapper.suggestionsToPatches('/page', [suggestion], 'opp-json');
688
+
689
+ expect(patches.length).to.equal(1);
690
+ const patch = patches[0];
691
+
692
+ expect(patch.value).to.deep.equal(jsonValue);
693
+ expect(patch.valueFormat).to.equal('json');
694
+ });
695
+
696
+ it('should use raw patchValue when format is not hast', () => {
697
+ const suggestion = {
698
+ getId: () => 'sugg-text',
699
+ getUpdatedAt: () => '2025-01-15T10:00:00.000Z',
700
+ getData: () => ({
701
+ transformRules: {
702
+ action: 'insertAfter',
703
+ selector: '#selector',
704
+ },
705
+ patchValue: 'Plain text content',
706
+ url: 'https://example.com/page',
707
+ }),
708
+ };
709
+
710
+ const patches = mapper.suggestionsToPatches('/page', [suggestion], 'opp-text');
711
+
712
+ expect(patches.length).to.equal(1);
713
+ const patch = patches[0];
714
+
715
+ expect(patch.value).to.equal('Plain text content');
716
+ expect(patch.valueFormat).to.equal('text');
717
+ });
718
+
719
+ it('should parse and include attrs when provided', () => {
720
+ const attrs = {
721
+ id: 'custom-id',
722
+ class: 'custom-class',
723
+ 'data-test': 'test-value',
724
+ };
725
+
726
+ const suggestion = {
727
+ getId: () => 'sugg-with-attrs',
728
+ getUpdatedAt: () => '2025-01-15T10:00:00.000Z',
729
+ getData: () => ({
730
+ transformRules: {
731
+ action: 'insertAfter',
732
+ selector: '#selector',
733
+ },
734
+ patchValue: 'Content with attributes',
735
+ attrs: JSON.stringify(attrs),
736
+ url: 'https://example.com/page',
737
+ }),
738
+ };
739
+
740
+ const patches = mapper.suggestionsToPatches('/page', [suggestion], 'opp-attrs');
741
+
742
+ expect(patches.length).to.equal(1);
743
+ const patch = patches[0];
744
+
745
+ expect(patch.attrs).to.deep.equal(attrs);
746
+ expect(patch.value).to.equal('Content with attributes');
747
+ });
748
+
749
+ it('should not include attrs when not provided', () => {
750
+ const suggestion = {
751
+ getId: () => 'sugg-no-attrs',
752
+ getUpdatedAt: () => '2025-01-15T10:00:00.000Z',
753
+ getData: () => ({
754
+ transformRules: {
755
+ action: 'insertAfter',
756
+ selector: '#selector',
757
+ },
758
+ patchValue: 'Content without attributes',
759
+ url: 'https://example.com/page',
760
+ }),
761
+ };
762
+
763
+ const patches = mapper.suggestionsToPatches('/page', [suggestion], 'opp-no-attrs');
764
+
765
+ expect(patches.length).to.equal(1);
766
+ const patch = patches[0];
767
+
768
+ expect(patch.attrs).to.be.undefined;
769
+ });
770
+
636
771
  it('should not include UI-only fields in patch', () => {
637
772
  const suggestion = {
638
773
  getId: () => 'sugg-ui',