@@ -20,7 +20,7 @@ import { HALEndpointService } from '../shared/hal-endpoint.service';
2020import { Item } from '../shared/item.model' ;
2121import { EPersonDataService } from './eperson-data.service' ;
2222import { EPerson } from './models/eperson.model' ;
23- import { EPersonMock , EPersonMock2 } from '../../shared/testing/eperson.mock' ;
23+ import { EPersonMock , EPersonMock2 , EPersonMockWithNoName } from '../../shared/testing/eperson.mock' ;
2424import { HALEndpointServiceStub } from '../../shared/testing/hal-endpoint-service.stub' ;
2525import { createNoContentRemoteDataObject$ , createSuccessfulRemoteDataObject$ } from '../../shared/remote-data.utils' ;
2626import { 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 ( ) ;
0 commit comments