@@ -31,6 +31,7 @@ import {
3131import {
3232 EPersonMock ,
3333 EPersonMock2 ,
34+ EPersonMockWithNoName ,
3435} from '../../shared/testing/eperson.mock' ;
3536import { GroupMock } from '../../shared/testing/group-mock' ;
3637import { HALEndpointServiceStub } from '../../shared/testing/hal-endpoint-service.stub' ;
@@ -280,6 +281,37 @@ describe('EPersonDataService', () => {
280281 } ) ;
281282 } ) ;
282283
284+ describe ( 'updateEPerson with non existing metadata' , ( ) => {
285+ beforeEach ( ( ) => {
286+ spyOn ( service , 'findByHref' ) . and . returnValue ( createSuccessfulRemoteDataObject$ ( EPersonMockWithNoName ) ) ;
287+ } ) ;
288+ describe ( 'add name that was not previously set' , ( ) => {
289+ beforeEach ( ( ) => {
290+ const changedEPerson = Object . assign ( new EPerson ( ) , {
291+ id : EPersonMock . id ,
292+ metadata : Object . assign ( EPersonMock . metadata , {
293+ 'eperson.firstname' : [
294+ {
295+ language : null ,
296+ value : 'User' ,
297+ } ,
298+ ] ,
299+ } ) ,
300+ email : EPersonMock . email ,
301+ canLogIn : EPersonMock . canLogIn ,
302+ requireCertificate : EPersonMock . requireCertificate ,
303+ _links : EPersonMock . _links ,
304+ } ) ;
305+ service . updateEPerson ( changedEPerson ) . subscribe ( ) ;
306+ } ) ;
307+ it ( 'should send PatchRequest with add email operation' , ( ) => {
308+ const operations = [ { op : 'add' , path : '/eperson.firstname' , value : [ { language : null , value : 'User' } ] } ] ;
309+ const expected = new PatchRequest ( requestService . generateRequestId ( ) , epersonsEndpoint + '/' + EPersonMock . uuid , operations ) ;
310+ expect ( requestService . send ) . toHaveBeenCalledWith ( expected ) ;
311+ } ) ;
312+ } ) ;
313+ } ) ;
314+
283315 describe ( 'clearEPersonRequests' , ( ) => {
284316 beforeEach ( ( ) => {
285317 spyOn ( halService , 'getEndpoint' ) . and . callFake ( ( linkPath : string ) => {
0 commit comments