Skip to content

Commit f9f3d18

Browse files
authored
Merge pull request #4305 from 4Science/task/dspace-7_x/DURACOM-326
[Port dspace-7_x] [DURACOM-326] fix possible issue on missing value for eperson patch #4289
2 parents 3635bf4 + 05e1fc3 commit f9f3d18

File tree

3 files changed

+74
-2
lines changed

3 files changed

+74
-2
lines changed

src/app/core/eperson/eperson-data.service.spec.ts

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { HALEndpointService } from '../shared/hal-endpoint.service';
2020
import { Item } from '../shared/item.model';
2121
import { EPersonDataService } from './eperson-data.service';
2222
import { EPerson } from './models/eperson.model';
23-
import { EPersonMock, EPersonMock2 } from '../../shared/testing/eperson.mock';
23+
import { EPersonMock, EPersonMock2, EPersonMockWithNoName } from '../../shared/testing/eperson.mock';
2424
import { HALEndpointServiceStub } from '../../shared/testing/hal-endpoint-service.stub';
2525
import { createNoContentRemoteDataObject$, createSuccessfulRemoteDataObject$ } from '../../shared/remote-data.utils';
2626
import { getMockRemoteDataBuildServiceHrefMap } from '../../shared/mocks/remote-data-build.service.mock';
@@ -279,6 +279,37 @@ describe('EPersonDataService', () => {
279279
});
280280
});
281281

282+
describe('updateEPerson with non existing metadata', () => {
283+
beforeEach(() => {
284+
spyOn(service, 'findByHref').and.returnValue(createSuccessfulRemoteDataObject$(EPersonMockWithNoName));
285+
});
286+
describe('add name that was not previously set', () => {
287+
beforeEach(() => {
288+
const changedEPerson = Object.assign(new EPerson(), {
289+
id: EPersonMock.id,
290+
metadata: Object.assign(EPersonMock.metadata, {
291+
'eperson.firstname': [
292+
{
293+
language: null,
294+
value: 'User',
295+
},
296+
],
297+
}),
298+
email: EPersonMock.email,
299+
canLogIn: EPersonMock.canLogIn,
300+
requireCertificate: EPersonMock.requireCertificate,
301+
_links: EPersonMock._links,
302+
});
303+
service.updateEPerson(changedEPerson).subscribe();
304+
});
305+
it('should send PatchRequest with add email operation', () => {
306+
const operations = [{ op: 'add', path: '/eperson.firstname', value: [{ language: null, value: 'User' }] }];
307+
const expected = new PatchRequest(requestService.generateRequestId(), epersonsEndpoint + '/' + EPersonMock.uuid, operations);
308+
expect(requestService.send).toHaveBeenCalledWith(expected);
309+
});
310+
});
311+
});
312+
282313
describe('getActiveEPerson', () => {
283314
it('should retrieve the ePerson currently getting edited, if any', () => {
284315
service.editEPerson(EPersonMock);

src/app/core/eperson/eperson-data.service.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,8 @@ export class EPersonDataService extends IdentifiableDataService<EPerson> impleme
233233
* @param newEPerson
234234
*/
235235
private generateOperations(oldEPerson: EPerson, newEPerson: EPerson): Operation[] {
236-
let operations = this.comparator.diff(oldEPerson, newEPerson).filter((operation: Operation) => operation.op === 'replace');
236+
let operations = this.comparator.diff(oldEPerson, newEPerson)
237+
.filter((operation: Operation) => ['replace', 'add'].includes(operation.op));
237238
if (hasValue(oldEPerson.email) && oldEPerson.email !== newEPerson.email) {
238239
operations = [...operations, {
239240
op: 'replace', path: '/email', value: newEPerson.email

src/app/shared/testing/eperson.mock.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,43 @@ export const EPersonMock2: EPerson = Object.assign(new EPerson(), {
9191
]
9292
}
9393
});
94+
95+
export const EPersonMockWithNoName: EPerson = Object.assign(new EPerson(), {
96+
handle: null,
97+
groups: [],
98+
99+
lastActive: '2018-05-14T12:25:42.411+0000',
100+
canLogIn: true,
101+
102+
requireCertificate: false,
103+
selfRegistered: false,
104+
_links: {
105+
self: {
106+
href: 'https://rest.api/dspace-spring-rest/api/eperson/epersons/testid',
107+
},
108+
groups: { href: 'https://rest.api/dspace-spring-rest/api/eperson/epersons/testid/groups' },
109+
},
110+
id: 'testid',
111+
uuid: 'testid',
112+
type: 'eperson',
113+
metadata: {
114+
'dc.title': [
115+
{
116+
language: null,
117+
value: 'User Test',
118+
},
119+
],
120+
'eperson.lastname': [
121+
{
122+
language: null,
123+
value: 'Test',
124+
},
125+
],
126+
'eperson.language': [
127+
{
128+
language: null,
129+
value: 'en',
130+
},
131+
],
132+
},
133+
});

0 commit comments

Comments
 (0)