diff --git a/src/collections/domain/models/CollectionItemSubset.ts b/src/collections/domain/models/CollectionItemSubset.ts index 681b7db5..aecd038f 100644 --- a/src/collections/domain/models/CollectionItemSubset.ts +++ b/src/collections/domain/models/CollectionItemSubset.ts @@ -9,11 +9,8 @@ export interface CollectionItemSubset { } export interface CollectionItemsFacet { - [key: string]: CollectionItemsFacetValue -} - -interface CollectionItemsFacetValue { - friendly: string + name: string + friendlyName: string labels: CollectionItemsFacetLabel[] } diff --git a/src/collections/infra/repositories/transformers/collectionTransformers.ts b/src/collections/infra/repositories/transformers/collectionTransformers.ts index 5139e960..68f730c6 100644 --- a/src/collections/infra/repositories/transformers/collectionTransformers.ts +++ b/src/collections/infra/repositories/transformers/collectionTransformers.ts @@ -107,13 +107,12 @@ export const transformCollectionItemsResponseToCollectionItemSubset = ( const transformedFacets: CollectionItemsFacet[] = Object.entries(facets[0]).map( ([key, facetData]) => ({ - [key]: { - friendly: facetData.friendly, - labels: facetData.labels.map((label: Record) => { - const [name, count] = Object.entries(label)[0] - return { name, count } - }) - } + name: key, + friendlyName: facetData.friendly, + labels: facetData.labels.map((label: Record) => { + const [name, count] = Object.entries(label)[0] + return { name, count } + }) }) ) diff --git a/test/integration/collections/CollectionsRepository.test.ts b/test/integration/collections/CollectionsRepository.test.ts index 3f68e3ca..bff0f6a5 100644 --- a/test/integration/collections/CollectionsRepository.test.ts +++ b/test/integration/collections/CollectionsRepository.test.ts @@ -301,63 +301,63 @@ describe('CollectionsRepository', () => { //prettier-ignore const expectedFacetsAll = [ { - dvCategory: { friendly: 'Dataverse Category', labels: [{ name: 'Laboratory', count: 1 }] } + name: 'dvCategory', friendlyName: 'Dataverse Category', labels: [{ name: 'Laboratory', count: 1 }] }, { - publicationStatus: { friendly: 'Publication Status', labels: [{ name: 'Unpublished', count: 3 },{ name: 'Draft', count: 2 }] } + name: 'publicationStatus', friendlyName: 'Publication Status', labels: [{ name: 'Unpublished', count: 3 },{ name: 'Draft', count: 2 }] }, { - authorName_ss: { friendly: 'Author Name', labels: [{ name: 'Admin, Dataverse', count: 1 },{ name: 'Owner, Dataverse', count: 1 }]} + name: 'authorName_ss', friendlyName: 'Author Name', labels: [{ name: 'Admin, Dataverse', count: 1 },{ name: 'Owner, Dataverse', count: 1 }] }, { - subject_ss: { friendly: 'Subject', labels: [{ name: 'Medicine, Health and Life Sciences', count: 1 }]} + name: 'subject_ss', friendlyName: 'Subject', labels: [{ name: 'Medicine, Health and Life Sciences', count: 1 }] }, { - fileTypeGroupFacet: { friendly: 'File Type', labels: [{ name: 'Text', count: 1 }] } + name: 'fileTypeGroupFacet', friendlyName: 'File Type', labels: [{ name: 'Text', count: 1 }] }, { - fileAccess: { friendly: 'Access', labels: [{ name: 'Public', count: 1 }] } + name: 'fileAccess', friendlyName: 'Access', labels: [{ name: 'Public', count: 1 }] } ] //prettier-ignore const expectedFacetsFromCollectionOnly = [ { - dvCategory: { friendly: 'Dataverse Category', labels: [{ name: 'Laboratory', count: 1 }] } + name: 'dvCategory', friendlyName: 'Dataverse Category', labels: [{ name: 'Laboratory', count: 1 }] }, { - publicationStatus: { friendly: 'Publication Status', labels: [{ name: 'Unpublished', count: 1 }]} + name: 'publicationStatus', friendlyName: 'Publication Status', labels: [{ name: 'Unpublished', count: 1 }] } ] //prettier-ignore const expectedFacetsFromDatasetOnly = [ { - publicationStatus: { friendly: 'Publication Status', labels: [{ name: 'Draft', count: 1 },{ name: 'Unpublished', count: 1 }] } + name: 'publicationStatus', friendlyName: 'Publication Status', labels: [{ name: 'Draft', count: 1 },{ name: 'Unpublished', count: 1 }] }, { - authorName_ss: { friendly: 'Author Name', labels: [{ name: 'Admin, Dataverse', count: 1 },{ name: 'Owner, Dataverse', count: 1 }] } + name: 'authorName_ss', friendlyName: 'Author Name', labels: [{ name: 'Admin, Dataverse', count: 1 },{ name: 'Owner, Dataverse', count: 1 }] }, { - subject_ss: { friendly: 'Subject', labels: [{ name: 'Medicine, Health and Life Sciences', count: 1 }] } + name: 'subject_ss', friendlyName: 'Subject', labels: [{ name: 'Medicine, Health and Life Sciences', count: 1 }] } ] //prettier-ignore const expectedFacetsFromFileOnly = [ { - publicationStatus: { friendly: 'Publication Status', labels: [{ name: 'Draft', count: 1 },{ name: 'Unpublished', count: 1 }] } + name: 'publicationStatus', friendlyName: 'Publication Status', labels: [{ name: 'Draft', count: 1 },{ name: 'Unpublished', count: 1 }] }, - { fileTypeGroupFacet: { friendly: 'File Type', labels: [{ name: 'Text', count: 1 }] } }, - { fileAccess: { friendly: 'Access', labels: [{ name: 'Public', count: 1 }] } } + { name: 'fileTypeGroupFacet', friendlyName: 'File Type', labels: [{ name: 'Text', count: 1 }] }, + { name: 'fileAccess', friendlyName: 'Access', labels: [{ name: 'Public', count: 1 }] } ] //prettier-ignore const expectedFacetsFromCollectionAndFile = [ { - dvCategory: { friendly: 'Dataverse Category', labels: [{ name: 'Laboratory', count: 1 }] } + name: 'dvCategory', friendlyName: 'Dataverse Category', labels: [{ name: 'Laboratory', count: 1 }] }, { - publicationStatus: { friendly: 'Publication Status', labels: [{ name: 'Unpublished', count: 2 },{ name: 'Draft', count: 1 }] } + name: 'publicationStatus', friendlyName: 'Publication Status', labels: [{ name: 'Unpublished', count: 2 },{ name: 'Draft', count: 1 }] }, - { fileTypeGroupFacet: { friendly: 'File Type', labels: [{ name: 'Text', count: 1 }] } }, - { fileAccess: { friendly: 'Access', labels: [{ name: 'Public', count: 1 }] } } + { name: 'fileTypeGroupFacet', friendlyName: 'File Type', labels: [{ name: 'Text', count: 1 }] }, + { name: 'fileAccess', friendlyName: 'Access', labels: [{ name: 'Public', count: 1 }] } ] expect(actualFilePreview.checksum?.type).toBe('MD5') diff --git a/test/testHelpers/collections/collectionItemsFacetsHelper.ts b/test/testHelpers/collections/collectionItemsFacetsHelper.ts index cb5650b1..c1754dee 100644 --- a/test/testHelpers/collections/collectionItemsFacetsHelper.ts +++ b/test/testHelpers/collections/collectionItemsFacetsHelper.ts @@ -4,22 +4,20 @@ import { CollectionItemsFacetPayload } from '../../../src/collections/infra/repo export const createCollectionItemsFacetsModel = (): CollectionItemsFacet[] => { return [ { - facet1: { - friendly: 'Facet 1', - labels: [ - { name: 'Label 1', count: 5 }, - { name: 'Label 2', count: 4 } - ] - } + name: 'facet1', + friendlyName: 'Facet 1', + labels: [ + { name: 'Label 1', count: 5 }, + { name: 'Label 2', count: 4 } + ] }, { - facet2: { - friendly: 'Facet 2', - labels: [ - { name: 'Label 3', count: 8 }, - { name: 'Label 4', count: 9 } - ] - } + name: 'facet2', + friendlyName: 'Facet 2', + labels: [ + { name: 'Label 3', count: 8 }, + { name: 'Label 4', count: 9 } + ] } ] }