Skip to content

Commit

Permalink
fix(keywords): map keyword link to key
Browse files Browse the repository at this point in the history
  • Loading branch information
tkohr committed Jul 10, 2024
1 parent cec60ff commit b682381
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 9 deletions.
54 changes: 45 additions & 9 deletions libs/api/metadata-converter/src/lib/gn4/atomic-operations.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,29 +30,65 @@ describe('atomic operations', () => {
id: '1',
theme: 'theme',
keywords: [
{ en: 'keyword1', fr: 'mot-clé1' },
{ en: 'keyword2', fr: 'mot-clé2' },
{
en: 'keyword1',
fr: 'mot-clé1',
link: 'https://some-uri.org/thematique/categories/culture_tourisme_sport',
},
{
en: 'keyword2',
fr: 'mot-clé2',
link: 'https://some-uri.org/thematique/categories/services_social_sante',
},
],
},
{
id: '2',
theme: 'place',
keywords: [
{ en: 'keyword3', fr: 'mot-clé3' },
{ en: 'keyword4', fr: 'mot-clé4' },
{
en: 'keyword3',
fr: 'mot-clé3',
link: 'https://some-uri.org/place/france',
},
{
en: 'keyword4',
fr: 'mot-clé4',
link: 'https://some-uri.org/place/europe',
},
],
},
]
const expected = [
{ label: 'keyword1', type: 'theme', thesaurus: { id: '1' } },
{ label: 'keyword2', type: 'theme', thesaurus: { id: '1' } },
{ label: 'keyword3', type: 'place', thesaurus: { id: '2' } },
{ label: 'keyword4', type: 'place', thesaurus: { id: '2' } },
{
label: 'keyword1',
type: 'theme',
key: 'https://some-uri.org/thematique/categories/culture_tourisme_sport',
thesaurus: { id: '1' },
},
{
label: 'keyword2',
type: 'theme',
key: 'https://some-uri.org/thematique/categories/services_social_sante',
thesaurus: { id: '1' },
},
{
label: 'keyword3',
type: 'place',
key: 'https://some-uri.org/place/france',
thesaurus: { id: '2' },
},
{
label: 'keyword4',
type: 'place',
key: 'https://some-uri.org/place/europe',
thesaurus: { id: '2' },
},
]
expect(mapKeywords(thesauri, 'en')).toEqual(expected)
})

it('should default type to "other" if theme is not provided', () => {
it('should default type to "other" if theme is not provided and not break without link', () => {
const thesauri = [
{
id: '1',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ export const mapKeywords = (thesauri: Thesaurus[], language: string) => {
}
for (const keyword of rawThesaurus.keywords) {
keywords.push({
key: keyword.link,
label: selectTranslatedValue<string>(keyword, language),
type: getKeywordTypeFromKeywordTypeCode(rawThesaurus.theme),
...(thesaurus && { thesaurus }),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ type MultilingualField = {
[K in `lang${LangCode}`]: string
} & {
default: string
link?: string
}

type BooleanString = 'true' | 'false'
Expand Down

0 comments on commit b682381

Please sign in to comment.