Skip to content

Commit

Permalink
Merge pull request #670 from geonetwork/fix-status
Browse files Browse the repository at this point in the history
Fix [DH]: Display record's update status correctly
  • Loading branch information
tkohr authored Nov 3, 2023
2 parents 416fe36 + 1b7dade commit 95ebc52
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 2 deletions.
115 changes: 115 additions & 0 deletions libs/api/metadata-converter/src/lib/gn4/gn4.field.mapper.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,120 @@ describe('Gn4FieldMapper', () => {
])
})
})

describe('#getMappingFn', () => {
it('should return a function when given a valid field name', () => {
const fieldName = 'id'
const mappingFn = service.getMappingFn(fieldName)
expect(typeof mappingFn).toBe('function')
})
it('should return a generic field when given an invalid field name', () => {
const fieldName = 'invalidField'
const mappingFn = service.getMappingFn(fieldName)
expect(mappingFn).toBe(service.genericField)
})
it('should return a function that maps the correct field even if the source object has additional unknown properties', () => {
const fieldName = 'id'
const mappingFn = service.getMappingFn(fieldName)
const output = {}
const source = { id: '12345', unknownProp: 'value' }
const result = mappingFn(output, source)
expect(result).toEqual({ extras: { id: '12345' } })
})
describe('field mappings', () => {
it('id - should return a function that correctly maps the field', () => {
const fieldName = 'id'
const mappingFn = service.getMappingFn(fieldName)
const output = {}
const source = { id: '12345' }
const result = mappingFn(output, source)
expect(result).toEqual({ extras: { id: '12345' } })
})
it('uuid - should return a function that correctly maps the field', () => {
const fieldName = 'uuid'
const mappingFn = service.getMappingFn(fieldName)
const output = {}
const source = { uuid: '12345' }
const result = mappingFn(output, source)
expect(result).toEqual({
landingPage: new URL('http://localhost/url'),
uniqueIdentifier: '12345',
})
})
it('resourceTitleObject - should return a function that correctly maps the field to default lang', () => {
service.lang3 = 'langeng'
const fieldName = 'resourceTitleObject'
const mappingFn = service.getMappingFn(fieldName)
const output = {}
const source = {
resourceTitleObject: {
default: 'Default title',
langfre: 'French title',
},
}
const result = mappingFn(output, source)
expect(result).toEqual({
title: 'Default title',
})
})
it('resourceAbstractObject - should return a function that correctly maps the field to fre lang', () => {
service.lang3 = 'langfre'
const fieldName = 'resourceAbstractObject'
const mappingFn = service.getMappingFn(fieldName)
const output = {}
const source = {
resourceAbstractObject: {
default: 'Default abstract',
langfre: 'French abstract',
},
}
const result = mappingFn(output, source)
expect(result).toEqual({
abstract: 'French abstract',
})
})
it('overview - should return a function that correctly maps the field', () => {
service.lang3 = 'langfre'
const fieldName = 'overview'
const mappingFn = service.getMappingFn(fieldName)
const output = {}
const source = {
overview: [
{
url: 'https://mygeodata/map.png',
text: {
default: 'Default overview description',
langfre: 'French overview description',
},
},
],
}
const result = mappingFn(output, source)
expect(result).toEqual({
overviews: [
{
url: new URL('https://mygeodata/map.png'),
description: 'French overview description',
},
],
})
})
it('cl_status - should return a function that correctly maps the field', () => {
const fieldName = 'cl_status'
const mappingFn = service.getMappingFn(fieldName)
const output = {}
const source = {
cl_status: {
key: 'completed',
default: 'Finalisé',
langfre: 'Finalisé',
link: 'http://standards.iso.org/iso/19139/resources/gmxCodelists.xml#MD_ProgressCode',
},
}
const result = mappingFn(output, source)
expect(result).toEqual({ status: 'completed' })
})
})
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export class Gn4FieldMapper {
cl_status: (output, source) => ({
...output,
status: getStatusFromStatusCode(
getFirstValue(selectField(source, 'cl_status'))
selectField(getFirstValue(selectField(source, 'cl_status')), 'key')
),
}),
cl_maintenanceAndUpdateFrequency: (output, source) => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ describe('Gn4MetadataMapper', () => {
],
recordCreated: new Date('2021-10-05T12:48:57.678Z'),
recordUpdated: new Date('2021-10-05T12:48:57.678Z'),
status: 'under_development',
status: 'ongoing',
themes: ['Installations de suivi environnemental', 'Océans'],
title: 'Surval - Données par paramètre',
uniqueIdentifier: 'cf5048f6-5bbf-4e44-ba74-e6f429af51ea',
Expand Down

0 comments on commit 95ebc52

Please sign in to comment.