@truedat/bg 7.12.6 → 7.12.8

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.
@@ -124,6 +124,26 @@ describe("selectors: getParsedEvents", () => {
124
124
  ],
125
125
  };
126
126
 
127
+ const r13 = {
128
+ id: 25,
129
+ event: "update_concept_draft",
130
+ resource_id: 23,
131
+ payload: [
132
+ { msg_key: "changed_field_without_target", msg_params: ["changed_field_1", null] },
133
+ { msg_key: "changed_field", msg_params: ["changed_field_2", "value_2"] },
134
+ ],
135
+ };
136
+
137
+ const r14 = {
138
+ id: 26,
139
+ event: "update_concept_draft",
140
+ resource_id: 24,
141
+ payload: [
142
+ { msg_key: "changed_field_without_target", msg_params: ["changed_field_1", null] },
143
+ { msg_key: "changed_field", msg_params: ["changed_field_2", "value_2"] },
144
+ ],
145
+ };
146
+
127
147
  const events = [
128
148
  {
129
149
  id: 1,
@@ -141,7 +161,7 @@ describe("selectors: getParsedEvents", () => {
141
161
  payload: {
142
162
  content: {
143
163
  removed: {},
144
- changed: { changed_field_1: "value_1", changed_field_2: "value_2" },
164
+ changed: { changed_field_1: { origin: "origin", value: "value_1" }, changed_field_2: { origin: "origin", value: "value_2" } },
145
165
  added: {},
146
166
  },
147
167
  },
@@ -210,7 +230,7 @@ describe("selectors: getParsedEvents", () => {
210
230
  id: 9,
211
231
  event: "update_concept_draft",
212
232
  resource_id: 10,
213
- payload: { content: { changed: { field_1: { id: 1, name: "foo" } } } },
233
+ payload: { content: { changed: { field_1: { origin: "origin", value: { id: 1, name: "foo" } } } } },
214
234
  },
215
235
  {
216
236
  id: 10,
@@ -261,12 +281,36 @@ describe("selectors: getParsedEvents", () => {
261
281
  subscribable_fields: {},
262
282
  },
263
283
  },
284
+ {
285
+ id: 25,
286
+ event: "update_concept_draft",
287
+ resource_id: 23,
288
+ payload: {
289
+ content: {
290
+ removed: {},
291
+ changed: { changed_field_1: { origin: "origin", value: null }, changed_field_2: { origin: "origin", value: "value_2" } },
292
+ added: {},
293
+ },
294
+ },
295
+ },
296
+ {
297
+ id: 26,
298
+ event: "update_concept_draft",
299
+ resource_id: 24,
300
+ payload: {
301
+ content: {
302
+ removed: {},
303
+ changed: { changed_field_1: null, changed_field_2: "value_2" },
304
+ added: {},
305
+ },
306
+ },
307
+ },
264
308
  ];
265
309
 
266
310
  it("should return all the events with the new payload", () => {
267
311
  const res = getParsedEvents({ events, concept });
268
- expect(res).toHaveLength(12);
269
- expect(res).toEqual([r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12]);
312
+ expect(res).toHaveLength(14);
313
+ expect(res).toEqual([r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12, r13, r14]);
270
314
  });
271
315
 
272
316
  it("should return empty array when we have no elements", () => {
@@ -274,4 +318,894 @@ describe("selectors: getParsedEvents", () => {
274
318
  expect(res).toHaveLength(0);
275
319
  expect(res).toEqual(expect.arrayContaining([]));
276
320
  });
321
+
322
+ describe("event_via propagation", () => {
323
+ it("should include msg_via in relation_created events", () => {
324
+ const events = [
325
+ {
326
+ id: 1,
327
+ event: "relation_created",
328
+ resource_id: 100,
329
+ payload: {
330
+ event_via: "single_update",
331
+ target_id: 123,
332
+ target_type: "data_structure",
333
+ target_name: "Test Structure",
334
+ },
335
+ },
336
+ ];
337
+
338
+ const res = getParsedEvents({ events, concept });
339
+
340
+ expect(res).toHaveLength(1);
341
+ expect(res[0].payload).toEqual([
342
+ {
343
+ msg_key: "relation_created_data_structure",
344
+ msg_params: ["Test Structure"],
345
+ msg_via: "single_update",
346
+ },
347
+ ]);
348
+ });
349
+
350
+ it("should include msg_via in relation_deleted events", () => {
351
+ const events = [
352
+ {
353
+ id: 1,
354
+ event: "relation_deleted",
355
+ resource_id: 100,
356
+ payload: {
357
+ event_via: "bulk_upload",
358
+ target_id: 456,
359
+ target_type: "business_concept",
360
+ target_name: "Test Concept",
361
+ },
362
+ },
363
+ ];
364
+
365
+ const res = getParsedEvents({ events, concept });
366
+
367
+ expect(res).toHaveLength(1);
368
+ expect(res[0].payload).toEqual([
369
+ {
370
+ msg_key: "relation_deleted_business_concept",
371
+ msg_params: ["Test Concept"],
372
+ msg_via: "bulk_upload",
373
+ },
374
+ ]);
375
+ });
376
+
377
+ it("should include msg_via in relation_deprecated events", () => {
378
+ const events = [
379
+ {
380
+ id: 1,
381
+ event: "relation_deprecated",
382
+ resource_id: 100,
383
+ payload: {
384
+ event_via: "single_update",
385
+ target_id: 789,
386
+ target_type: "implementation",
387
+ },
388
+ },
389
+ ];
390
+
391
+ const res = getParsedEvents({ events, concept });
392
+
393
+ expect(res).toHaveLength(1);
394
+ expect(res[0].payload).toEqual([
395
+ {
396
+ msg_key: "relation_deprecated_implementation",
397
+ msg_params: [789],
398
+ msg_via: "single_update",
399
+ },
400
+ ]);
401
+ });
402
+
403
+ it("should include msg_via in concept_published events", () => {
404
+ const events = [
405
+ {
406
+ id: 1,
407
+ event: "concept_published",
408
+ resource_id: 100,
409
+ payload: {
410
+ event_via: "single_update",
411
+ },
412
+ },
413
+ ];
414
+
415
+ const res = getParsedEvents({ events, concept });
416
+
417
+ expect(res).toHaveLength(1);
418
+ expect(res[0].payload).toEqual([{ msg_via: "single_update" }]);
419
+ });
420
+
421
+ it("should include msg_via in concept_deprecated events", () => {
422
+ const events = [
423
+ {
424
+ id: 1,
425
+ event: "concept_deprecated",
426
+ resource_id: 100,
427
+ payload: {
428
+ event_via: "bulk_upload",
429
+ },
430
+ },
431
+ ];
432
+
433
+ const res = getParsedEvents({ events, concept });
434
+
435
+ expect(res).toHaveLength(1);
436
+ expect(res[0].payload).toEqual([{ msg_via: "bulk_upload" }]);
437
+ });
438
+
439
+ it("should include msg_via in concept_submitted events", () => {
440
+ const events = [
441
+ {
442
+ id: 1,
443
+ event: "concept_submitted",
444
+ resource_id: 100,
445
+ payload: {
446
+ event_via: "single_update",
447
+ },
448
+ },
449
+ ];
450
+
451
+ const res = getParsedEvents({ events, concept });
452
+
453
+ expect(res).toHaveLength(1);
454
+ expect(res[0].payload).toEqual([{ msg_via: "single_update" }]);
455
+ });
456
+
457
+ it("should include msg_via in create_concept_draft events", () => {
458
+ const events = [
459
+ {
460
+ id: 1,
461
+ event: "create_concept_draft",
462
+ resource_id: 100,
463
+ payload: {
464
+ version: 3,
465
+ event_via: "single_update",
466
+ },
467
+ },
468
+ ];
469
+
470
+ const res = getParsedEvents({ events, concept });
471
+
472
+ expect(res).toHaveLength(1);
473
+ expect(res[0].payload).toEqual([
474
+ {
475
+ msg_key: "created_version",
476
+ msg_params: [3],
477
+ msg_via: "single_update",
478
+ },
479
+ ]);
480
+ });
481
+
482
+ it("should include msg_via in delete_concept_draft events", () => {
483
+ const events = [
484
+ {
485
+ id: 1,
486
+ event: "delete_concept_draft",
487
+ resource_id: 100,
488
+ payload: {
489
+ version: 2,
490
+ event_via: "bulk_upload",
491
+ },
492
+ },
493
+ ];
494
+
495
+ const res = getParsedEvents({ events, concept });
496
+
497
+ expect(res).toHaveLength(1);
498
+ expect(res[0].payload).toEqual([
499
+ {
500
+ msg_key: "deleted_version",
501
+ msg_params: [2],
502
+ msg_via: "bulk_upload",
503
+ },
504
+ ]);
505
+ });
506
+
507
+ it("should handle undefined event_via", () => {
508
+ const events = [
509
+ {
510
+ id: 1,
511
+ event: "concept_published",
512
+ resource_id: 100,
513
+ payload: {},
514
+ },
515
+ ];
516
+
517
+ const res = getParsedEvents({ events, concept });
518
+
519
+ expect(res).toHaveLength(1);
520
+ expect(res[0].payload).toEqual([{ msg_via: undefined }]);
521
+ });
522
+
523
+ it("should use target_name when available, fallback to target_id", () => {
524
+ const eventsWithName = [
525
+ {
526
+ id: 1,
527
+ event: "relation_created",
528
+ resource_id: 100,
529
+ payload: {
530
+ event_via: "single_update",
531
+ target_id: 123,
532
+ target_type: "data_structure",
533
+ target_name: "My Structure",
534
+ },
535
+ },
536
+ ];
537
+
538
+ const eventsWithoutName = [
539
+ {
540
+ id: 2,
541
+ event: "relation_created",
542
+ resource_id: 101,
543
+ payload: {
544
+ event_via: "single_update",
545
+ target_id: 456,
546
+ target_type: "data_structure",
547
+ },
548
+ },
549
+ ];
550
+
551
+ const resWithName = getParsedEvents({ events: eventsWithName, concept });
552
+ const resWithoutName = getParsedEvents({
553
+ events: eventsWithoutName,
554
+ concept,
555
+ });
556
+
557
+ expect(resWithName[0].payload[0].msg_params).toEqual(["My Structure"]);
558
+ expect(resWithoutName[0].payload[0].msg_params).toEqual([456]);
559
+ });
560
+ });
561
+
562
+ describe("field value display for different data types", () => {
563
+ const conceptWithMixedFields = {
564
+ template: {
565
+ content: [
566
+ {
567
+ fields: [
568
+ { type: "string", name: "Checkbox String", label: "Checkbox String" },
569
+ { type: "string", name: "Date", label: "Date" },
570
+ { type: "string", name: "Date Time", label: "Date Time" },
571
+ { type: "domain", name: "Dropdown Domain", label: "Dropdown Domain" },
572
+ { type: "string", name: "Dropdown Key Value", label: "Dropdown Key Value" },
573
+ { type: "string", name: "Dropdown String", label: "Dropdown String" },
574
+ { type: "system", name: "Dropdown System", label: "Dropdown System" },
575
+ { type: "enriched_text", name: "Enrichedtext", label: "Enrichedtext" },
576
+ { type: "string", name: "Extra", label: "Extra" },
577
+ { type: "hierarchy", name: "Hierarchy", label: "Hierarchy" },
578
+ { type: "hierarchy", name: "Hierarchy multiple", label: "Hierarchy multiple" },
579
+ { type: "url", name: "Links", label: "Links" },
580
+ { type: "integer", name: "Number", label: "Number" },
581
+ { type: "string", name: "Radio String", label: "Radio String" },
582
+ { type: "table", name: "Table", label: "Table" },
583
+ { type: "list", name: "Text Input", label: "Text Input" },
584
+ { type: "string", name: "Textarea", label: "Textarea" },
585
+ { type: "image", name: "Image", label: "Image" },
586
+ ],
587
+ },
588
+ ],
589
+ },
590
+ };
591
+
592
+ it("should show values for array fields (checkbox, dropdown, text input)", () => {
593
+ const events = [
594
+ {
595
+ id: 1,
596
+ event: "update_concept_draft",
597
+ resource_id: 443,
598
+ payload: {
599
+ event_via: "single_update",
600
+ content: {
601
+ changed: {
602
+ "Checkbox String": {
603
+ origin: "user",
604
+ value: ["foo", "bar"],
605
+ },
606
+ "Dropdown Domain": {
607
+ origin: "user",
608
+ value: [123, 456],
609
+ },
610
+ "Dropdown String": {
611
+ origin: "user",
612
+ value: ["option_a", "option_b"],
613
+ },
614
+ "Text Input": {
615
+ origin: "user",
616
+ value: ["lorem", "ipsum"],
617
+ },
618
+ "Hierarchy multiple": {
619
+ origin: "user",
620
+ value: ["1_1", "1_2"],
621
+ },
622
+ },
623
+ },
624
+ },
625
+ },
626
+ ];
627
+
628
+ const res = getParsedEvents({ events, concept: conceptWithMixedFields });
629
+
630
+ expect(res).toHaveLength(1);
631
+ expect(res[0].payload).toContainEqual({
632
+ msg_key: "changed_field",
633
+ msg_params: ["Checkbox String", JSON.stringify(["foo", "bar"])],
634
+ msg_via: "single_update",
635
+ });
636
+ expect(res[0].payload).toContainEqual({
637
+ msg_key: "changed_field",
638
+ msg_params: ["Dropdown Domain", JSON.stringify([123, 456])],
639
+ msg_via: "single_update",
640
+ });
641
+ expect(res[0].payload).toContainEqual({
642
+ msg_key: "changed_field",
643
+ msg_params: ["Dropdown String", JSON.stringify(["option_a", "option_b"])],
644
+ msg_via: "single_update",
645
+ });
646
+ expect(res[0].payload).toContainEqual({
647
+ msg_key: "changed_field",
648
+ msg_params: ["Text Input", JSON.stringify(["lorem", "ipsum"])],
649
+ msg_via: "single_update",
650
+ });
651
+ expect(res[0].payload).toContainEqual({
652
+ msg_key: "changed_field",
653
+ msg_params: ["Hierarchy multiple", JSON.stringify(["1_1", "1_2"])],
654
+ msg_via: "single_update",
655
+ });
656
+ });
657
+
658
+ it("should show values for simple scalar fields", () => {
659
+ const events = [
660
+ {
661
+ id: 1,
662
+ event: "update_concept_draft",
663
+ resource_id: 443,
664
+ payload: {
665
+ event_via: "single_update",
666
+ content: {
667
+ changed: {
668
+ Date: {
669
+ origin: "user",
670
+ value: "2024-01-15",
671
+ },
672
+ "Date Time": {
673
+ origin: "user",
674
+ value: "2024-01-15T10:30",
675
+ },
676
+ "Dropdown Key Value": {
677
+ origin: "user",
678
+ value: "key_001",
679
+ },
680
+ Extra: {
681
+ origin: "user",
682
+ value: "lorem ipsum",
683
+ },
684
+ Hierarchy: {
685
+ origin: "user",
686
+ value: "1_2",
687
+ },
688
+ Number: {
689
+ origin: "user",
690
+ value: 123,
691
+ },
692
+ "Radio String": {
693
+ origin: "user",
694
+ value: "option_a",
695
+ },
696
+ Textarea: {
697
+ origin: "user",
698
+ value: "dolor sit amet",
699
+ },
700
+ },
701
+ },
702
+ },
703
+ },
704
+ ];
705
+
706
+ const res = getParsedEvents({ events, concept: conceptWithMixedFields });
707
+
708
+ expect(res).toHaveLength(1);
709
+ expect(res[0].payload).toContainEqual({
710
+ msg_key: "changed_field",
711
+ msg_params: ["Date", "2024-01-15"],
712
+ msg_via: "single_update",
713
+ });
714
+ expect(res[0].payload).toContainEqual({
715
+ msg_key: "changed_field",
716
+ msg_params: ["Date Time", "2024-01-15T10:30"],
717
+ msg_via: "single_update",
718
+ });
719
+ expect(res[0].payload).toContainEqual({
720
+ msg_key: "changed_field",
721
+ msg_params: ["Dropdown Key Value", "key_001"],
722
+ msg_via: "single_update",
723
+ });
724
+ expect(res[0].payload).toContainEqual({
725
+ msg_key: "changed_field",
726
+ msg_params: ["Extra", "lorem ipsum"],
727
+ msg_via: "single_update",
728
+ });
729
+ expect(res[0].payload).toContainEqual({
730
+ msg_key: "changed_field",
731
+ msg_params: ["Hierarchy", "1_2"],
732
+ msg_via: "single_update",
733
+ });
734
+ expect(res[0].payload).toContainEqual({
735
+ msg_key: "changed_field",
736
+ msg_params: ["Number", 123],
737
+ msg_via: "single_update",
738
+ });
739
+ expect(res[0].payload).toContainEqual({
740
+ msg_key: "changed_field",
741
+ msg_params: ["Radio String", "option_a"],
742
+ msg_via: "single_update",
743
+ });
744
+ expect(res[0].payload).toContainEqual({
745
+ msg_key: "changed_field",
746
+ msg_params: ["Textarea", "dolor sit amet"],
747
+ msg_via: "single_update",
748
+ });
749
+ });
750
+
751
+ it("should NOT show values for complex field types (enriched_text, url, table, system, image)", () => {
752
+ const events = [
753
+ {
754
+ id: 1,
755
+ event: "update_concept_draft",
756
+ resource_id: 443,
757
+ payload: {
758
+ event_via: "single_update",
759
+ content: {
760
+ changed: {
761
+ "Dropdown System": {
762
+ origin: "user",
763
+ value: {
764
+ external_id: "system_foo",
765
+ id: 123,
766
+ name: "System Bar",
767
+ },
768
+ },
769
+ Enrichedtext: {
770
+ origin: "user",
771
+ value: {
772
+ document: {
773
+ data: {},
774
+ nodes: [
775
+ {
776
+ data: {},
777
+ nodes: [
778
+ {
779
+ marks: [],
780
+ object: "text",
781
+ text: "Lorem ipsum dolor sit amet",
782
+ },
783
+ ],
784
+ object: "block",
785
+ type: "paragraph",
786
+ },
787
+ ],
788
+ object: "document",
789
+ },
790
+ object: "value",
791
+ },
792
+ },
793
+ Links: {
794
+ origin: "user",
795
+ value: [
796
+ {
797
+ url_name: "Example Link",
798
+ url_value: "https://example.com",
799
+ },
800
+ ],
801
+ },
802
+ Table: {
803
+ origin: "user",
804
+ value: [
805
+ {
806
+ "Col A": "foo",
807
+ "Col B": "bar",
808
+ },
809
+ ],
810
+ },
811
+ Image: {
812
+ origin: "user",
813
+ value: {
814
+ url: "https://example.com/image.png",
815
+ },
816
+ },
817
+ },
818
+ },
819
+ },
820
+ },
821
+ ];
822
+
823
+ const res = getParsedEvents({ events, concept: conceptWithMixedFields });
824
+
825
+ expect(res).toHaveLength(1);
826
+ expect(res[0].payload).toContainEqual({
827
+ msg_key: "changed_field_without_target",
828
+ msg_params: [
829
+ "Dropdown System",
830
+ JSON.stringify({
831
+ external_id: "system_foo",
832
+ id: 123,
833
+ name: "System Bar",
834
+ }),
835
+ ],
836
+ msg_via: "single_update",
837
+ });
838
+ expect(res[0].payload).toContainEqual({
839
+ msg_key: "changed_field_without_target",
840
+ msg_params: [
841
+ "Enrichedtext",
842
+ expect.stringContaining("Lorem ipsum dolor sit amet"),
843
+ ],
844
+ msg_via: "single_update",
845
+ });
846
+ expect(res[0].payload).toContainEqual({
847
+ msg_key: "changed_field_without_target",
848
+ msg_params: [
849
+ "Links",
850
+ JSON.stringify([
851
+ {
852
+ url_name: "Example Link",
853
+ url_value: "https://example.com",
854
+ },
855
+ ]),
856
+ ],
857
+ msg_via: "single_update",
858
+ });
859
+ expect(res[0].payload).toContainEqual({
860
+ msg_key: "changed_field_without_target",
861
+ msg_params: [
862
+ "Table",
863
+ JSON.stringify([
864
+ {
865
+ "Col A": "foo",
866
+ "Col B": "bar",
867
+ },
868
+ ]),
869
+ ],
870
+ msg_via: "single_update",
871
+ });
872
+ expect(res[0].payload).toContainEqual({
873
+ msg_key: "changed_field_without_target",
874
+ msg_params: [
875
+ "Image",
876
+ JSON.stringify({
877
+ url: "https://example.com/image.png",
878
+ }),
879
+ ],
880
+ msg_via: "single_update",
881
+ });
882
+ });
883
+
884
+ it("should NOT show values for null or undefined fields", () => {
885
+ const events = [
886
+ {
887
+ id: 1,
888
+ event: "update_concept_draft",
889
+ resource_id: 443,
890
+ payload: {
891
+ event_via: "single_update",
892
+ content: {
893
+ changed: {
894
+ "Text Input": {
895
+ origin: "user",
896
+ value: null,
897
+ },
898
+ Extra: {
899
+ origin: "user",
900
+ value: undefined,
901
+ },
902
+ },
903
+ },
904
+ },
905
+ },
906
+ ];
907
+
908
+ const res = getParsedEvents({ events, concept: conceptWithMixedFields });
909
+
910
+ expect(res).toHaveLength(1);
911
+ expect(res[0].payload).toContainEqual({
912
+ msg_key: "changed_field_without_target",
913
+ msg_params: ["Text Input", null],
914
+ msg_via: "single_update",
915
+ });
916
+ expect(res[0].payload).toContainEqual({
917
+ msg_key: "changed_field_without_target",
918
+ msg_params: ["Extra", undefined],
919
+ msg_via: "single_update",
920
+ });
921
+ });
922
+ });
923
+
924
+ describe("update_concept specific fields", () => {
925
+ it("should handle confidential field in update_concept", () => {
926
+ const events = [
927
+ {
928
+ id: 1,
929
+ event: "update_concept",
930
+ resource_id: 100,
931
+ payload: {
932
+ confidential: true,
933
+ event_via: "single_update",
934
+ content: {},
935
+ },
936
+ },
937
+ ];
938
+
939
+ const res = getParsedEvents({ events, concept });
940
+
941
+ expect(res).toHaveLength(1);
942
+ expect(res[0].payload).toContainEqual({
943
+ msg_key: "confidential_true",
944
+ msg_via: "single_update",
945
+ });
946
+ });
947
+
948
+ it("should handle confidential false in update_concept", () => {
949
+ const events = [
950
+ {
951
+ id: 1,
952
+ event: "update_concept",
953
+ resource_id: 100,
954
+ payload: {
955
+ confidential: false,
956
+ event_via: "single_update",
957
+ content: {},
958
+ },
959
+ },
960
+ ];
961
+
962
+ const res = getParsedEvents({ events, concept });
963
+
964
+ expect(res).toHaveLength(1);
965
+ expect(res[0].payload).toContainEqual({
966
+ msg_key: "confidential_false",
967
+ msg_via: "single_update",
968
+ });
969
+ });
970
+
971
+ it("should NOT handle confidential field in update_concept_draft", () => {
972
+ const events = [
973
+ {
974
+ id: 1,
975
+ event: "update_concept_draft",
976
+ resource_id: 100,
977
+ payload: {
978
+ confidential: true,
979
+ event_via: "single_update",
980
+ content: {},
981
+ },
982
+ },
983
+ ];
984
+
985
+ const res = getParsedEvents({ events, concept });
986
+
987
+ expect(res).toHaveLength(1);
988
+ expect(res[0].payload).not.toContainEqual(
989
+ expect.objectContaining({
990
+ msg_key: "confidential_true",
991
+ })
992
+ );
993
+ });
994
+ });
995
+
996
+ describe("update_concept_draft specific fields", () => {
997
+ it("should handle name field in update_concept_draft", () => {
998
+ const events = [
999
+ {
1000
+ id: 1,
1001
+ event: "update_concept_draft",
1002
+ resource_id: 100,
1003
+ payload: {
1004
+ name: "New Concept Name",
1005
+ event_via: "single_update",
1006
+ content: {},
1007
+ },
1008
+ },
1009
+ ];
1010
+
1011
+ const res = getParsedEvents({ events, concept });
1012
+
1013
+ expect(res).toHaveLength(1);
1014
+ expect(res[0].payload).toContainEqual({
1015
+ msg_key: "changed_field",
1016
+ msg_params: ["name", "New Concept Name"],
1017
+ msg_via: "single_update",
1018
+ });
1019
+ });
1020
+
1021
+ it("should NOT handle name field in update_concept", () => {
1022
+ const events = [
1023
+ {
1024
+ id: 1,
1025
+ event: "update_concept",
1026
+ resource_id: 100,
1027
+ payload: {
1028
+ name: "New Concept Name",
1029
+ event_via: "single_update",
1030
+ content: {},
1031
+ },
1032
+ },
1033
+ ];
1034
+
1035
+ const res = getParsedEvents({ events, concept });
1036
+
1037
+ expect(res).toHaveLength(1);
1038
+ expect(res[0].payload).not.toContainEqual(
1039
+ expect.objectContaining({
1040
+ msg_key: "changed_field",
1041
+ msg_params: expect.arrayContaining(["name", "New Concept Name"]),
1042
+ })
1043
+ );
1044
+ });
1045
+
1046
+ it("should handle description field in update_concept_draft", () => {
1047
+ const events = [
1048
+ {
1049
+ id: 1,
1050
+ event: "update_concept_draft",
1051
+ resource_id: 100,
1052
+ payload: {
1053
+ description: "New description",
1054
+ event_via: "single_update",
1055
+ content: {},
1056
+ },
1057
+ },
1058
+ ];
1059
+
1060
+ const res = getParsedEvents({ events, concept });
1061
+
1062
+ expect(res).toHaveLength(1);
1063
+ expect(res[0].payload).toContainEqual({
1064
+ msg_key: "changed_field_without_target",
1065
+ msg_params: ["description"],
1066
+ msg_via: "single_update",
1067
+ });
1068
+ });
1069
+
1070
+ it("should NOT handle description field in update_concept", () => {
1071
+ const events = [
1072
+ {
1073
+ id: 1,
1074
+ event: "update_concept",
1075
+ resource_id: 100,
1076
+ payload: {
1077
+ description: "New description",
1078
+ event_via: "single_update",
1079
+ content: {},
1080
+ },
1081
+ },
1082
+ ];
1083
+
1084
+ const res = getParsedEvents({ events, concept });
1085
+
1086
+ expect(res).toHaveLength(1);
1087
+ expect(res[0].payload).not.toContainEqual(
1088
+ expect.objectContaining({
1089
+ msg_key: "changed_field_without_target",
1090
+ msg_params: ["description"],
1091
+ })
1092
+ );
1093
+ });
1094
+
1095
+ it("should return empty payload when update_concept_draft has no content", () => {
1096
+ const events = [
1097
+ {
1098
+ id: 1,
1099
+ event: "update_concept_draft",
1100
+ resource_id: 100,
1101
+ payload: {
1102
+ name: "Test",
1103
+ event_via: "single_update",
1104
+ },
1105
+ },
1106
+ ];
1107
+
1108
+ const res = getParsedEvents({ events, concept });
1109
+
1110
+ expect(res).toHaveLength(1);
1111
+ expect(res[0].payload).toEqual([]);
1112
+ });
1113
+ });
1114
+
1115
+ describe("combined fields processing", () => {
1116
+ it("should process all update_concept fields together", () => {
1117
+ const events = [
1118
+ {
1119
+ id: 1,
1120
+ event: "update_concept",
1121
+ resource_id: 100,
1122
+ payload: {
1123
+ confidential: true,
1124
+ shared_to: [{ id: 1, name: "Domain A" }],
1125
+ domain_id: 42,
1126
+ event_via: "bulk_upload",
1127
+ content: {
1128
+ changed: {
1129
+ field_1: { origin: "origin", value: "new_value" },
1130
+ },
1131
+ },
1132
+ },
1133
+ },
1134
+ ];
1135
+
1136
+ const res = getParsedEvents({ events, concept });
1137
+
1138
+ expect(res).toHaveLength(1);
1139
+ expect(res[0].payload).toContainEqual({
1140
+ msg_key: "confidential_true",
1141
+ msg_via: "bulk_upload",
1142
+ });
1143
+ expect(res[0].payload).toContainEqual({
1144
+ msg_key: "shared_to",
1145
+ msg_params: ["Domain A"],
1146
+ msg_via: "bulk_upload",
1147
+ });
1148
+ expect(res[0].payload).toContainEqual({
1149
+ msg_key: "domain_updated_with_id",
1150
+ msg_params: [42],
1151
+ msg_via: "bulk_upload",
1152
+ });
1153
+ expect(res[0].payload).toContainEqual({
1154
+ msg_key: "changed_field_without_target",
1155
+ msg_params: ["Label", "new_value"],
1156
+ msg_via: "bulk_upload",
1157
+ });
1158
+ });
1159
+
1160
+ it("should process all update_concept_draft fields together", () => {
1161
+ const events = [
1162
+ {
1163
+ id: 1,
1164
+ event: "update_concept_draft",
1165
+ resource_id: 100,
1166
+ payload: {
1167
+ name: "Updated Name",
1168
+ description: "Updated description",
1169
+ shared_to: [{ id: 1, name: "Domain B" }],
1170
+ domain_id: 43,
1171
+ event_via: "single_update",
1172
+ content: {
1173
+ added: {
1174
+ field_1: { origin: "origin", value: "added_value" },
1175
+ },
1176
+ },
1177
+ },
1178
+ },
1179
+ ];
1180
+
1181
+ const res = getParsedEvents({ events, concept });
1182
+
1183
+ expect(res).toHaveLength(1);
1184
+ expect(res[0].payload).toContainEqual({
1185
+ msg_key: "shared_to",
1186
+ msg_params: ["Domain B"],
1187
+ msg_via: "single_update",
1188
+ });
1189
+ expect(res[0].payload).toContainEqual({
1190
+ msg_key: "changed_field_without_target",
1191
+ msg_params: ["description"],
1192
+ msg_via: "single_update",
1193
+ });
1194
+ expect(res[0].payload).toContainEqual({
1195
+ msg_key: "changed_field",
1196
+ msg_params: ["name", "Updated Name"],
1197
+ msg_via: "single_update",
1198
+ });
1199
+ expect(res[0].payload).toContainEqual({
1200
+ msg_key: "domain_updated_with_id",
1201
+ msg_params: [43],
1202
+ msg_via: "single_update",
1203
+ });
1204
+ expect(res[0].payload).toContainEqual({
1205
+ msg_key: "added_field_without_target",
1206
+ msg_params: ["Label", "added_value"],
1207
+ msg_via: "single_update",
1208
+ });
1209
+ });
1210
+ });
277
1211
  });