Skip to content

Commit

Permalink
Merge pull request DSpace#3138 from 4Science/task/main/DURACOM-282
Browse files Browse the repository at this point in the history
Fix error which prevent submitter to deposit a new item
  • Loading branch information
tdonohue authored Jun 20, 2024
2 parents fb70b58 + 7f8e0a1 commit 4d13e28
Show file tree
Hide file tree
Showing 5 changed files with 411 additions and 17 deletions.
380 changes: 380 additions & 0 deletions src/app/core/json-patch/json-patch-operations.reducer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,4 +340,384 @@ describe('jsonPatchOperationsReducer test suite', () => {
});
});

describe('dedupeOperationEntries', () => {
it('should not remove duplicated keys if operations are not sequential', () => {
initState = {
sections: {
children: {
publicationStep: {
body: [
{
operation: {
op: 'add',
path: '/sections/publicationStep/dc.date.issued',
value: [
{
value: '2024-06',
language: null,
authority: null,
display: '2024-06',
confidence: -1,
place: 0,
otherInformation: null,
},
],
},
timeCompleted: timestampBeforeStart,
},
{
operation: {
op: 'replace',
path: '/sections/publicationStep/dc.date.issued/0',
value: {
value: '2023-06-19',
language: null,
authority: null,
display: '2023-06-19',
confidence: -1,
place: 0,
otherInformation: null,
},
},
timeCompleted: timestampBeforeStart,
},
],
} as JsonPatchOperationsEntry,
},
transactionStartTime: null,
commitPending: false,
} as JsonPatchOperationsResourceEntry,
};

const value = [
{
value: '2024-06-19',
language: null,
authority: null,
display: '2024-06-19',
confidence: -1,
place: 0,
otherInformation: null,
},
];
const action = new NewPatchAddOperationAction(
'sections',
'publicationStep',
'/sections/publicationStep/dc.date.issued',
value);
const newState = jsonPatchOperationsReducer(initState, action);

const expectedBody: any = [
{
'operation': {
'op': 'add',
'path': '/sections/publicationStep/dc.date.issued',
'value': [
{
'value': '2024-06',
'language': null,
'authority': null,
'display': '2024-06',
'confidence': -1,
'place': 0,
'otherInformation': null,
},
],
},
'timeCompleted': timestampBeforeStart,
},
{
'operation': {
'op': 'replace',
'path': '/sections/publicationStep/dc.date.issued/0',
'value': {
'value': '2023-06-19',
'language': null,
'authority': null,
'display': '2023-06-19',
'confidence': -1,
'place': 0,
'otherInformation': null,
},
},
'timeCompleted': timestampBeforeStart,
},
{
'operation': {
'op': 'add',
'path': '/sections/publicationStep/dc.date.issued',
'value': [
{
'value': '2024-06-19',
'language': null,
'authority': null,
'display': '2024-06-19',
'confidence': -1,
'place': 0,
'otherInformation': null,
},
],
},
'timeCompleted': timestampBeforeStart,
},
];

expect(newState.sections.children.publicationStep.body).toEqual(expectedBody);

});

it('should remove duplicated keys if operations are sequential', () => {
initState = {
sections: {
children: {
publicationStep: {
body: [
{
operation: {
op: 'add',
path: '/sections/publicationStep/dc.date.issued',
value: [
{
value: '2024-06',
language: null,
authority: null,
display: '2024-06',
confidence: -1,
place: 0,
otherInformation: null,
},
],
},
timeCompleted: timestampBeforeStart,
},
{
operation: {
op: 'replace',
path: '/sections/publicationStep/dc.date.issued/0',
value: {
value: '2023-06-19',
language: null,
authority: null,
display: '2023-06-19',
confidence: -1,
place: 0,
otherInformation: null,
},
},
timeCompleted: timestampBeforeStart,
},
{
'operation': {
'op': 'add',
'path': '/sections/publicationStep/dc.date.issued',
'value': [
{
'value': '2024-06-19',
'language': null,
'authority': null,
'display': '2024-06-19',
'confidence': -1,
'place': 0,
'otherInformation': null,
},
],
},
'timeCompleted': timestampBeforeStart,
},
],
} as JsonPatchOperationsEntry,
},
transactionStartTime: null,
commitPending: false,
} as JsonPatchOperationsResourceEntry,
};

const value = [
{
value: '2024-06-20',
language: null,
authority: null,
display: '2024-06-20',
confidence: -1,
place: 0,
otherInformation: null,
},
];
const action = new NewPatchAddOperationAction(
'sections',
'publicationStep',
'/sections/publicationStep/dc.date.issued',
value);
const newState = jsonPatchOperationsReducer(initState, action);

const expectedBody: any = [
{
'operation': {
'op': 'add',
'path': '/sections/publicationStep/dc.date.issued',
'value': [
{
'value': '2024-06',
'language': null,
'authority': null,
'display': '2024-06',
'confidence': -1,
'place': 0,
'otherInformation': null,
},
],
},
'timeCompleted': timestampBeforeStart,
},
{
'operation': {
'op': 'replace',
'path': '/sections/publicationStep/dc.date.issued/0',
'value': {
'value': '2023-06-19',
'language': null,
'authority': null,
'display': '2023-06-19',
'confidence': -1,
'place': 0,
'otherInformation': null,
},
},
'timeCompleted': timestampBeforeStart,
},
{
'operation': {
'op': 'add',
'path': '/sections/publicationStep/dc.date.issued',
'value': [
{
'value': '2024-06-20',
'language': null,
'authority': null,
'display': '2024-06-20',
'confidence': -1,
'place': 0,
'otherInformation': null,
},
],
},
'timeCompleted': timestampBeforeStart,
},
];

expect(newState.sections.children.publicationStep.body).toEqual(expectedBody);

});

it('should remove duplicated keys if all operations have same key', () => {
initState = {
sections: {
children: {
publicationStep: {
body: [
{
operation: {
op: 'add',
path: '/sections/publicationStep/dc.date.issued',
value: [
{
value: '2024',
language: null,
authority: null,
display: '2024-06',
confidence: -1,
place: 0,
otherInformation: null,
},
],
},
timeCompleted: timestampBeforeStart,
},
{
'operation': {
'op': 'add',
'path': '/sections/publicationStep/dc.date.issued',
'value': [
{
'value': '2024-06',
'language': null,
'authority': null,
'display': '2024-06',
'confidence': -1,
'place': 0,
'otherInformation': null,
},
],
},
'timeCompleted': timestampBeforeStart,
},
{
'operation': {
'op': 'add',
'path': '/sections/publicationStep/dc.date.issued',
'value': [
{
'value': '2024-06-19',
'language': null,
'authority': null,
'display': '2024-06-19',
'confidence': -1,
'place': 0,
'otherInformation': null,
},
],
},
'timeCompleted': timestampBeforeStart,
},
],
} as JsonPatchOperationsEntry,
},
transactionStartTime: null,
commitPending: false,
} as JsonPatchOperationsResourceEntry,
};

const value = [
{
value: '2024-06-20',
language: null,
authority: null,
display: '2024-06-20',
confidence: -1,
place: 0,
otherInformation: null,
},
];
const action = new NewPatchAddOperationAction(
'sections',
'publicationStep',
'/sections/publicationStep/dc.date.issued',
value);
const newState = jsonPatchOperationsReducer(initState, action);

const expectedBody: any = [
{
'operation': {
'op': 'add',
'path': '/sections/publicationStep/dc.date.issued',
'value': [
{
'value': '2024-06-20',
'language': null,
'authority': null,
'display': '2024-06-20',
'confidence': -1,
'place': 0,
'otherInformation': null,
},
],
},
'timeCompleted': timestampBeforeStart,
},
];

expect(newState.sections.children.publicationStep.body).toEqual(expectedBody);

});
});
});
Loading

0 comments on commit 4d13e28

Please sign in to comment.