@@ -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' ;
@@ -279,6 +279,37 @@ describe('EPersonDataService', () => {
279279 } ) ;
280280 } ) ;
281281
282+ describe ( 'updateEPerson with non existing metadata' , ( ) => {
283+ beforeEach ( ( ) => {
284+ spyOn ( service , 'findByHref' ) . and . returnValue ( createSuccessfulRemoteDataObject$ ( EPersonMockWithNoName ) ) ;
285+ } ) ;
286+ describe ( 'add name that was not previously set' , ( ) => {
287+ beforeEach ( ( ) => {
288+ const changedEPerson = Object . assign ( new EPerson ( ) , {
289+ id : EPersonMock . id ,
290+ metadata : Object . assign ( EPersonMock . metadata , {
291+ 'eperson.firstname' : [
292+ {
293+ language : null ,
294+ value : 'User' ,
295+ } ,
296+ ] ,
297+ } ) ,
298+ email : EPersonMock . email ,
299+ canLogIn : EPersonMock . canLogIn ,
300+ requireCertificate : EPersonMock . requireCertificate ,
301+ _links : EPersonMock . _links ,
302+ } ) ;
303+ service . updateEPerson ( changedEPerson ) . subscribe ( ) ;
304+ } ) ;
305+ it ( 'should send PatchRequest with add email operation' , ( ) => {
306+ const operations = [ { op : 'add' , path : '/eperson.firstname' , value : [ { language : null , value : 'User' } ] } ] ;
307+ const expected = new PatchRequest ( requestService . generateRequestId ( ) , epersonsEndpoint + '/' + EPersonMock . uuid , operations ) ;
308+ expect ( requestService . send ) . toHaveBeenCalledWith ( expected ) ;
309+ } ) ;
310+ } ) ;
311+ } ) ;
312+
282313 describe ( 'getActiveEPerson' , ( ) => {
283314 it ( 'should retrieve the ePerson currently getting edited, if any' , ( ) => {
284315 service . editEPerson ( EPersonMock ) ;
0 commit comments