Skip to content

Commit 4eacdfb

Browse files
atarix83tdonohue
authored andcommitted
[DURACOM-282] fix issue with removing duplicated json patch operations, which in some case changed the order in the queue
1 parent fbb9716 commit 4eacdfb

2 files changed

Lines changed: 387 additions & 3 deletions

File tree

src/app/core/json-patch/json-patch-operations.reducer.spec.ts

Lines changed: 380 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,4 +339,384 @@ describe('jsonPatchOperationsReducer test suite', () => {
339339
});
340340
});
341341

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

0 commit comments

Comments
 (0)