mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
[DURACOM-326] fix possible issue on missing value for eperson patch
This commit is contained in:
@@ -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';
|
||||
@@ -281,6 +282,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) => {
|
||||
|
@@ -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,
|
||||
|
@@ -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',
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
|
Reference in New Issue
Block a user