Skip to content

Commit c2e9266

Browse files
Andrea Barbassovins01-4science
authored andcommitted
Merged in task/dspace-cris-2023_02_x/DSC-2189 (pull request DSpace#2825)
[DSC-2189] accept 'add' operations for EPerson patches Approved-by: Francesco Molinaro Approved-by: Vincenzo Mecca
2 parents 1d0db5d + 67d8ecc commit c2e9266

3 files changed

Lines changed: 75 additions & 2 deletions

File tree

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

Lines changed: 33 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';
@@ -264,6 +264,38 @@ describe('EPersonDataService', () => {
264264
});
265265
});
266266

267+
describe('updateEPerson with non existing metadata', () => {
268+
beforeEach(() => {
269+
spyOn(service, 'findByHref').and.returnValue(createSuccessfulRemoteDataObject$(EPersonMockWithNoName));
270+
});
271+
272+
describe('add name that was not previously set', () => {
273+
beforeEach(() => {
274+
const changedEPerson = Object.assign(new EPerson(), {
275+
id: EPersonMock.id,
276+
metadata: Object.assign(EPersonMock.metadata, {
277+
'eperson.firstname': [
278+
{
279+
language: null,
280+
value: 'User',
281+
}
282+
],
283+
}),
284+
email: EPersonMock.email,
285+
canLogIn: EPersonMock.canLogIn,
286+
requireCertificate: EPersonMock.requireCertificate,
287+
_links: EPersonMock._links,
288+
});
289+
service.updateEPerson(changedEPerson).subscribe();
290+
});
291+
it('should send PatchRequest with add email operation', () => {
292+
const operations = [{ op: 'add', path: '/eperson.firstname', value: [{ language: null, value: 'User' }] }];
293+
const expected = new PatchRequest(requestService.generateRequestId(), epersonsEndpoint + '/' + EPersonMock.uuid, operations);
294+
expect(requestService.send).toHaveBeenCalledWith(expected);
295+
});
296+
});
297+
});
298+
267299
describe('clearEPersonRequests', () => {
268300
beforeEach(waitForAsync(() => {
269301
scheduler = getTestScheduler();

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+
netid: 'test@test.com',
99+
lastActive: '2018-05-14T12:25:42.411+0000',
100+
canLogIn: true,
101+
email: 'test@test.com',
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)