mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
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
This commit is contained in:
@@ -20,7 +20,7 @@ import { HALEndpointService } from '../shared/hal-endpoint.service';
|
||||
import { Item } from '../shared/item.model';
|
||||
import { EPersonDataService } from './eperson-data.service';
|
||||
import { EPerson } from './models/eperson.model';
|
||||
import { EPersonMock, EPersonMock2 } from '../../shared/testing/eperson.mock';
|
||||
import { EPersonMock, EPersonMock2, EPersonMockWithNoName } from '../../shared/testing/eperson.mock';
|
||||
import { HALEndpointServiceStub } from '../../shared/testing/hal-endpoint-service.stub';
|
||||
import { createNoContentRemoteDataObject$, createSuccessfulRemoteDataObject$ } from '../../shared/remote-data.utils';
|
||||
import { getMockRemoteDataBuildServiceHrefMap } from '../../shared/mocks/remote-data-build.service.mock';
|
||||
@@ -279,6 +279,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('getActiveEPerson', () => {
|
||||
it('should retrieve the ePerson currently getting edited, if any', () => {
|
||||
service.editEPerson(EPersonMock);
|
||||
|
@@ -233,7 +233,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