Commits
Giuseppe Digilio authored eb7fb704bd9
333 333 | transactionStartTime: startTimestamp, |
334 334 | commitPending: true, |
335 335 | }), |
336 336 | }); |
337 337 | const newState = jsonPatchOperationsReducer(initState, action); |
338 338 | |
339 339 | expect(newState).toBeNull(); |
340 340 | }); |
341 341 | }); |
342 342 | |
343 + | describe('dedupeOperationEntries', () => { |
344 + | it('should not remove duplicated keys if operations are not sequential', () => { |
345 + | initState = { |
346 + | sections: { |
347 + | children: { |
348 + | publicationStep: { |
349 + | body: [ |
350 + | { |
351 + | operation: { |
352 + | op: 'add', |
353 + | path: '/sections/publicationStep/dc.date.issued', |
354 + | value: [ |
355 + | { |
356 + | value: '2024-06', |
357 + | language: null, |
358 + | authority: null, |
359 + | display: '2024-06', |
360 + | confidence: -1, |
361 + | place: 0, |
362 + | otherInformation: null, |
363 + | }, |
364 + | ], |
365 + | }, |
366 + | timeCompleted: timestampBeforeStart, |
367 + | }, |
368 + | { |
369 + | operation: { |
370 + | op: 'replace', |
371 + | path: '/sections/publicationStep/dc.date.issued/0', |
372 + | value: { |
373 + | value: '2023-06-19', |
374 + | language: null, |
375 + | authority: null, |
376 + | display: '2023-06-19', |
377 + | confidence: -1, |
378 + | place: 0, |
379 + | otherInformation: null, |
380 + | }, |
381 + | }, |
382 + | timeCompleted: timestampBeforeStart, |
383 + | }, |
384 + | ], |
385 + | } as JsonPatchOperationsEntry, |
386 + | }, |
387 + | transactionStartTime: null, |
388 + | commitPending: false, |
389 + | } as JsonPatchOperationsResourceEntry, |
390 + | }; |
391 + | |
392 + | const value = [ |
393 + | { |
394 + | value: '2024-06-19', |
395 + | language: null, |
396 + | authority: null, |
397 + | display: '2024-06-19', |
398 + | confidence: -1, |
399 + | place: 0, |
400 + | otherInformation: null, |
401 + | }, |
402 + | ]; |
403 + | const action = new NewPatchAddOperationAction( |
404 + | 'sections', |
405 + | 'publicationStep', |
406 + | '/sections/publicationStep/dc.date.issued', |
407 + | value); |
408 + | const newState = jsonPatchOperationsReducer(initState, action); |
409 + | |
410 + | const expectedBody: any = [ |
411 + | { |
412 + | 'operation': { |
413 + | 'op': 'add', |
414 + | 'path': '/sections/publicationStep/dc.date.issued', |
415 + | 'value': [ |
416 + | { |
417 + | 'value': '2024-06', |
418 + | 'language': null, |
419 + | 'authority': null, |
420 + | 'display': '2024-06', |
421 + | 'confidence': -1, |
422 + | 'place': 0, |
423 + | 'otherInformation': null, |
424 + | }, |
425 + | ], |
426 + | }, |
427 + | 'timeCompleted': timestampBeforeStart, |
428 + | }, |
429 + | { |
430 + | 'operation': { |
431 + | 'op': 'replace', |
432 + | 'path': '/sections/publicationStep/dc.date.issued/0', |
433 + | 'value': { |
434 + | 'value': '2023-06-19', |
435 + | 'language': null, |
436 + | 'authority': null, |
437 + | 'display': '2023-06-19', |
438 + | 'confidence': -1, |
439 + | 'place': 0, |
440 + | 'otherInformation': null, |
441 + | }, |
442 + | }, |
443 + | 'timeCompleted': timestampBeforeStart, |
444 + | }, |
445 + | { |
446 + | 'operation': { |
447 + | 'op': 'add', |
448 + | 'path': '/sections/publicationStep/dc.date.issued', |
449 + | 'value': [ |
450 + | { |
451 + | 'value': '2024-06-19', |
452 + | 'language': null, |
453 + | 'authority': null, |
454 + | 'display': '2024-06-19', |
455 + | 'confidence': -1, |
456 + | 'place': 0, |
457 + | 'otherInformation': null, |
458 + | }, |
459 + | ], |
460 + | }, |
461 + | 'timeCompleted': timestampBeforeStart, |
462 + | }, |
463 + | ]; |
464 + | |
465 + | expect(newState.sections.children.publicationStep.body).toEqual(expectedBody); |
466 + | |
467 + | }); |
468 + | |
469 + | it('should remove duplicated keys if operations are sequential', () => { |
470 + | initState = { |
471 + | sections: { |
472 + | children: { |
473 + | publicationStep: { |
474 + | body: [ |
475 + | { |
476 + | operation: { |
477 + | op: 'add', |
478 + | path: '/sections/publicationStep/dc.date.issued', |
479 + | value: [ |
480 + | { |
481 + | value: '2024-06', |
482 + | language: null, |
483 + | authority: null, |
484 + | display: '2024-06', |
485 + | confidence: -1, |
486 + | place: 0, |
487 + | otherInformation: null, |
488 + | }, |
489 + | ], |
490 + | }, |
491 + | timeCompleted: timestampBeforeStart, |
492 + | }, |
493 + | { |
494 + | operation: { |
495 + | op: 'replace', |
496 + | path: '/sections/publicationStep/dc.date.issued/0', |
497 + | value: { |
498 + | value: '2023-06-19', |
499 + | language: null, |
500 + | authority: null, |
501 + | display: '2023-06-19', |
502 + | confidence: -1, |
503 + | place: 0, |
504 + | otherInformation: null, |
505 + | }, |
506 + | }, |
507 + | timeCompleted: timestampBeforeStart, |
508 + | }, |
509 + | { |
510 + | 'operation': { |
511 + | 'op': 'add', |
512 + | 'path': '/sections/publicationStep/dc.date.issued', |
513 + | 'value': [ |
514 + | { |
515 + | 'value': '2024-06-19', |
516 + | 'language': null, |
517 + | 'authority': null, |
518 + | 'display': '2024-06-19', |
519 + | 'confidence': -1, |
520 + | 'place': 0, |
521 + | 'otherInformation': null, |
522 + | }, |
523 + | ], |
524 + | }, |
525 + | 'timeCompleted': timestampBeforeStart, |
526 + | }, |
527 + | ], |
528 + | } as JsonPatchOperationsEntry, |
529 + | }, |
530 + | transactionStartTime: null, |
531 + | commitPending: false, |
532 + | } as JsonPatchOperationsResourceEntry, |
533 + | }; |
534 + | |
535 + | const value = [ |
536 + | { |
537 + | value: '2024-06-20', |
538 + | language: null, |
539 + | authority: null, |
540 + | display: '2024-06-20', |
541 + | confidence: -1, |
542 + | place: 0, |
543 + | otherInformation: null, |
544 + | }, |
545 + | ]; |
546 + | const action = new NewPatchAddOperationAction( |
547 + | 'sections', |
548 + | 'publicationStep', |
549 + | '/sections/publicationStep/dc.date.issued', |
550 + | value); |
551 + | const newState = jsonPatchOperationsReducer(initState, action); |
552 + | |
553 + | const expectedBody: any = [ |
554 + | { |
555 + | 'operation': { |
556 + | 'op': 'add', |
557 + | 'path': '/sections/publicationStep/dc.date.issued', |
558 + | 'value': [ |
559 + | { |
560 + | 'value': '2024-06', |
561 + | 'language': null, |
562 + | 'authority': null, |
563 + | 'display': '2024-06', |
564 + | 'confidence': -1, |
565 + | 'place': 0, |
566 + | 'otherInformation': null, |
567 + | }, |
568 + | ], |
569 + | }, |
570 + | 'timeCompleted': timestampBeforeStart, |
571 + | }, |
572 + | { |
573 + | 'operation': { |
574 + | 'op': 'replace', |
575 + | 'path': '/sections/publicationStep/dc.date.issued/0', |
576 + | 'value': { |
577 + | 'value': '2023-06-19', |
578 + | 'language': null, |
579 + | 'authority': null, |
580 + | 'display': '2023-06-19', |
581 + | 'confidence': -1, |
582 + | 'place': 0, |
583 + | 'otherInformation': null, |
584 + | }, |
585 + | }, |
586 + | 'timeCompleted': timestampBeforeStart, |
587 + | }, |
588 + | { |
589 + | 'operation': { |
590 + | 'op': 'add', |
591 + | 'path': '/sections/publicationStep/dc.date.issued', |
592 + | 'value': [ |
593 + | { |
594 + | 'value': '2024-06-20', |
595 + | 'language': null, |
596 + | 'authority': null, |
597 + | 'display': '2024-06-20', |
598 + | 'confidence': -1, |
599 + | 'place': 0, |
600 + | 'otherInformation': null, |
601 + | }, |
602 + | ], |
603 + | }, |
604 + | 'timeCompleted': timestampBeforeStart, |
605 + | }, |
606 + | ]; |
607 + | |
608 + | expect(newState.sections.children.publicationStep.body).toEqual(expectedBody); |
609 + | |
610 + | }); |
611 + | |
612 + | it('should remove duplicated keys if all operations have same key', () => { |
613 + | initState = { |
614 + | sections: { |
615 + | children: { |
616 + | publicationStep: { |
617 + | body: [ |
618 + | { |
619 + | operation: { |
620 + | op: 'add', |
621 + | path: '/sections/publicationStep/dc.date.issued', |
622 + | value: [ |
623 + | { |
624 + | value: '2024', |
625 + | language: null, |
626 + | authority: null, |
627 + | display: '2024-06', |
628 + | confidence: -1, |
629 + | place: 0, |
630 + | otherInformation: null, |
631 + | }, |
632 + | ], |
633 + | }, |
634 + | timeCompleted: timestampBeforeStart, |
635 + | }, |
636 + | { |
637 + | 'operation': { |
638 + | 'op': 'add', |
639 + | 'path': '/sections/publicationStep/dc.date.issued', |
640 + | 'value': [ |
641 + | { |
642 + | 'value': '2024-06', |
643 + | 'language': null, |
644 + | 'authority': null, |
645 + | 'display': '2024-06', |
646 + | 'confidence': -1, |
647 + | 'place': 0, |
648 + | 'otherInformation': null, |
649 + | }, |
650 + | ], |
651 + | }, |
652 + | 'timeCompleted': timestampBeforeStart, |
653 + | }, |
654 + | { |
655 + | 'operation': { |
656 + | 'op': 'add', |
657 + | 'path': '/sections/publicationStep/dc.date.issued', |
658 + | 'value': [ |
659 + | { |
660 + | 'value': '2024-06-19', |
661 + | 'language': null, |
662 + | 'authority': null, |
663 + | 'display': '2024-06-19', |
664 + | 'confidence': -1, |
665 + | 'place': 0, |
666 + | 'otherInformation': null, |
667 + | }, |
668 + | ], |
669 + | }, |
670 + | 'timeCompleted': timestampBeforeStart, |
671 + | }, |
672 + | ], |
673 + | } as JsonPatchOperationsEntry, |
674 + | }, |
675 + | transactionStartTime: null, |
676 + | commitPending: false, |
677 + | } as JsonPatchOperationsResourceEntry, |
678 + | }; |
679 + | |
680 + | const value = [ |
681 + | { |
682 + | value: '2024-06-20', |
683 + | language: null, |
684 + | authority: null, |
685 + | display: '2024-06-20', |
686 + | confidence: -1, |
687 + | place: 0, |
688 + | otherInformation: null, |
689 + | }, |
690 + | ]; |
691 + | const action = new NewPatchAddOperationAction( |
692 + | 'sections', |
693 + | 'publicationStep', |
694 + | '/sections/publicationStep/dc.date.issued', |
695 + | value); |
696 + | const newState = jsonPatchOperationsReducer(initState, action); |
697 + | |
698 + | const expectedBody: any = [ |
699 + | { |
700 + | 'operation': { |
701 + | 'op': 'add', |
702 + | 'path': '/sections/publicationStep/dc.date.issued', |
703 + | 'value': [ |
704 + | { |
705 + | 'value': '2024-06-20', |
706 + | 'language': null, |
707 + | 'authority': null, |
708 + | 'display': '2024-06-20', |
709 + | 'confidence': -1, |
710 + | 'place': 0, |
711 + | 'otherInformation': null, |
712 + | }, |
713 + | ], |
714 + | }, |
715 + | 'timeCompleted': timestampBeforeStart, |
716 + | }, |
717 + | ]; |
718 + | |
719 + | expect(newState.sections.children.publicationStep.body).toEqual(expectedBody); |
720 + | |
721 + | }); |
722 + | }); |
343 723 | }); |