@@ -11,10 +11,16 @@ import { RelationshipService } from './relationship.service';
1111import { RequestService } from './request.service' ;
1212import { RequestEntry } from './request.reducer' ;
1313import { HALEndpointServiceStub } from '../../shared/testing/hal-endpoint-service.stub' ;
14- import { createSuccessfulRemoteDataObject , createSuccessfulRemoteDataObject$ } from '../../shared/remote-data.utils' ;
14+ import {
15+ createFailedRemoteDataObject$ ,
16+ createSuccessfulRemoteDataObject ,
17+ createSuccessfulRemoteDataObject$
18+ } from '../../shared/remote-data.utils' ;
1519import { getMockRemoteDataBuildServiceHrefMap } from '../../shared/mocks/remote-data-build.service.mock' ;
1620import { getMockRequestService } from '../../shared/mocks/request.service.mock' ;
1721import { createPaginatedList } from '../../shared/testing/utils.test' ;
22+ import { MetadataValue } from '../shared/metadata.models' ;
23+ import { MetadataRepresentationType } from '../shared/metadata-representation/metadata-representation.model' ;
1824
1925describe ( 'RelationshipService' , ( ) => {
2026 let service : RelationshipService ;
@@ -228,4 +234,152 @@ describe('RelationshipService', () => {
228234 } ) ;
229235 } ) ;
230236 } ) ;
237+
238+ describe ( 'resolveMetadataRepresentation' , ( ) => {
239+ const parentItem : Item = Object . assign ( new Item ( ) , {
240+ id : 'parent-item' ,
241+ metadata : {
242+ 'dc.contributor.author' : [
243+ Object . assign ( new MetadataValue ( ) , {
244+ language : null ,
245+ value : 'Related Author with authority' ,
246+ authority : 'virtual::related-author' ,
247+ place : 2
248+ } ) ,
249+ Object . assign ( new MetadataValue ( ) , {
250+ language : null ,
251+ value : 'Author without authority' ,
252+ place : 1
253+ } ) ,
254+ ] ,
255+ 'dc.creator' : [
256+ Object . assign ( new MetadataValue ( ) , {
257+ language : null ,
258+ value : 'Related Creator with authority' ,
259+ authority : 'virtual::related-creator' ,
260+ place : 3 ,
261+ } ) ,
262+ Object . assign ( new MetadataValue ( ) , {
263+ language : null ,
264+ value : 'Related Creator with authority - unauthorized' ,
265+ authority : 'virtual::related-creator-unauthorized' ,
266+ place : 4 ,
267+ } ) ,
268+ ] ,
269+ 'dc.title' : [
270+ Object . assign ( new MetadataValue ( ) , {
271+ language : null ,
272+ value : 'Parent Item'
273+ } ) ,
274+ ]
275+ }
276+ } ) ;
277+ const relatedAuthor : Item = Object . assign ( new Item ( ) , {
278+ id : 'related-author' ,
279+ metadata : {
280+ 'dc.title' : [
281+ Object . assign ( new MetadataValue ( ) , {
282+ language : null ,
283+ value : 'Related Author'
284+ } ) ,
285+ ]
286+ }
287+ } ) ;
288+ const relatedCreator : Item = Object . assign ( new Item ( ) , {
289+ id : 'related-creator' ,
290+ metadata : {
291+ 'dc.title' : [
292+ Object . assign ( new MetadataValue ( ) , {
293+ language : null ,
294+ value : 'Related Creator'
295+ } ) ,
296+ ] ,
297+ 'dspace.entity.type' : 'Person' ,
298+ }
299+ } ) ;
300+ const authorRelation : Relationship = Object . assign ( new Relationship ( ) , {
301+ leftItem : createSuccessfulRemoteDataObject$ ( parentItem ) ,
302+ rightItem : createSuccessfulRemoteDataObject$ ( relatedAuthor )
303+ } ) ;
304+ const creatorRelation : Relationship = Object . assign ( new Relationship ( ) , {
305+ leftItem : createSuccessfulRemoteDataObject$ ( parentItem ) ,
306+ rightItem : createSuccessfulRemoteDataObject$ ( relatedCreator ) ,
307+ } ) ;
308+ const creatorRelationUnauthorized : Relationship = Object . assign ( new Relationship ( ) , {
309+ leftItem : createSuccessfulRemoteDataObject$ ( parentItem ) ,
310+ rightItem : createFailedRemoteDataObject$ ( 'Unauthorized' , 401 ) ,
311+ } ) ;
312+
313+ let metadatum : MetadataValue ;
314+
315+ beforeEach ( ( ) => {
316+ service . findById = ( id : string ) => {
317+ if ( id === 'related-author' ) {
318+ return createSuccessfulRemoteDataObject$ ( authorRelation ) ;
319+ }
320+ if ( id === 'related-creator' ) {
321+ return createSuccessfulRemoteDataObject$ ( creatorRelation ) ;
322+ }
323+ if ( id === 'related-creator-unauthorized' ) {
324+ return createSuccessfulRemoteDataObject$ ( creatorRelationUnauthorized ) ;
325+ }
326+ } ;
327+ } ) ;
328+
329+ describe ( 'when the metadata isn\'t virtual' , ( ) => {
330+ beforeEach ( ( ) => {
331+ metadatum = parentItem . metadata [ 'dc.contributor.author' ] [ 1 ] ;
332+ } ) ;
333+
334+ it ( 'should return a plain text MetadatumRepresentation' , ( done ) => {
335+ service . resolveMetadataRepresentation ( metadatum , parentItem , 'Person' ) . subscribe ( ( result ) => {
336+ expect ( result . representationType ) . toEqual ( MetadataRepresentationType . PlainText ) ;
337+ done ( ) ;
338+ } ) ;
339+ } ) ;
340+ } ) ;
341+
342+ describe ( 'when the metadata is a virtual author' , ( ) => {
343+ beforeEach ( ( ) => {
344+ metadatum = parentItem . metadata [ 'dc.contributor.author' ] [ 0 ] ;
345+ } ) ;
346+
347+ it ( 'should return a ItemMetadataRepresentation with the correct value' , ( done ) => {
348+ service . resolveMetadataRepresentation ( metadatum , parentItem , 'Person' ) . subscribe ( ( result ) => {
349+ expect ( result . representationType ) . toEqual ( MetadataRepresentationType . Item ) ;
350+ expect ( result . getValue ( ) ) . toEqual ( metadatum . value ) ;
351+ expect ( ( result as any ) . id ) . toEqual ( relatedAuthor . id ) ;
352+ done ( ) ;
353+ } ) ;
354+ } ) ;
355+ } ) ;
356+
357+ describe ( 'when the metadata is a virtual creator' , ( ) => {
358+ beforeEach ( ( ) => {
359+ metadatum = parentItem . metadata [ 'dc.creator' ] [ 0 ] ;
360+ } ) ;
361+
362+ it ( 'should return a ItemMetadataRepresentation with the correct value' , ( done ) => {
363+ service . resolveMetadataRepresentation ( metadatum , parentItem , 'Person' ) . subscribe ( ( result ) => {
364+ expect ( result . representationType ) . toEqual ( MetadataRepresentationType . Item ) ;
365+ expect ( result . getValue ( ) ) . toEqual ( metadatum . value ) ;
366+ expect ( ( result as any ) . id ) . toEqual ( relatedCreator . id ) ;
367+ done ( ) ;
368+ } ) ;
369+ } ) ;
370+ } ) ;
371+
372+ describe ( 'when the metadata refers to a relationship leading to an error response' , ( ) => {
373+ beforeEach ( ( ) => {
374+ metadatum = parentItem . metadata [ 'dc.creator' ] [ 1 ] ;
375+ } ) ;
376+
377+ it ( 'should return an authority controlled MetadatumRepresentation' , ( done ) => {
378+ service . resolveMetadataRepresentation ( metadatum , parentItem , 'Person' ) . subscribe ( ( result ) => {
379+ expect ( result . representationType ) . toEqual ( MetadataRepresentationType . AuthorityControlled ) ;
380+ done ( ) ;
381+ } ) ;
382+ } ) ;
383+ } ) ;
384+ } ) ;
231385} ) ;
0 commit comments