Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions src/app/core/eperson/eperson-data.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
import {
EPersonMock,
EPersonMock2,
EPersonMockWithNoName,
} from '../../shared/testing/eperson.mock';
import { GroupMock } from '../../shared/testing/group-mock';
import { HALEndpointServiceStub } from '../../shared/testing/hal-endpoint-service.stub';
Expand Down Expand Up @@ -280,6 +281,37 @@ describe('EPersonDataService', () => {
});
});

describe('updateEPerson with non existing metadata', () => {
beforeEach(() => {
spyOn(service, 'findByHref').and.returnValue(createSuccessfulRemoteDataObject$(EPersonMockWithNoName));
});
describe('add name that was not previously set', () => {
beforeEach(() => {
const changedEPerson = Object.assign(new EPerson(), {
id: EPersonMock.id,
metadata: Object.assign(EPersonMock.metadata, {
'eperson.firstname': [
{
language: null,
value: 'User',
},
],
}),
email: EPersonMock.email,
canLogIn: EPersonMock.canLogIn,
requireCertificate: EPersonMock.requireCertificate,
_links: EPersonMock._links,
});
service.updateEPerson(changedEPerson).subscribe();
});
it('should send PatchRequest with add email operation', () => {
const operations = [{ op: 'add', path: '/eperson.firstname', value: [{ language: null, value: 'User' }] }];
const expected = new PatchRequest(requestService.generateRequestId(), epersonsEndpoint + '/' + EPersonMock.uuid, operations);
expect(requestService.send).toHaveBeenCalledWith(expected);
});
});
});

describe('clearEPersonRequests', () => {
beforeEach(() => {
spyOn(halService, 'getEndpoint').and.callFake((linkPath: string) => {
Expand Down
3 changes: 2 additions & 1 deletion src/app/core/eperson/eperson-data.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,8 @@ export class EPersonDataService extends IdentifiableDataService<EPerson> impleme
* @param newEPerson
*/
private generateOperations(oldEPerson: EPerson, newEPerson: EPerson): Operation[] {
let operations = this.comparator.diff(oldEPerson, newEPerson).filter((operation: Operation) => operation.op === 'replace');
let operations = this.comparator.diff(oldEPerson, newEPerson)
.filter((operation: Operation) => ['replace', 'add'].includes(operation.op));
if (hasValue(oldEPerson.email) && oldEPerson.email !== newEPerson.email) {
operations = [...operations, {
op: 'replace', path: '/email', value: newEPerson.email,
Expand Down
40 changes: 40 additions & 0 deletions src/app/shared/testing/eperson.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,43 @@ export const EPersonMock2: EPerson = Object.assign(new EPerson(), {
],
},
});

export const EPersonMockWithNoName: EPerson = Object.assign(new EPerson(), {
handle: null,
groups: [],
netid: 'test@test.com',
lastActive: '2018-05-14T12:25:42.411+0000',
canLogIn: true,
email: 'test@test.com',
requireCertificate: false,
selfRegistered: false,
_links: {
self: {
href: 'https://rest.api/dspace-spring-rest/api/eperson/epersons/testid',
},
groups: { href: 'https://rest.api/dspace-spring-rest/api/eperson/epersons/testid/groups' },
},
id: 'testid',
uuid: 'testid',
type: 'eperson',
metadata: {
'dc.title': [
{
language: null,
value: 'User Test',
},
],
'eperson.lastname': [
{
language: null,
value: 'Test',
},
],
'eperson.language': [
{
language: null,
value: 'en',
},
],
},
});
Loading