Skip to content

Commit

Permalink
feat: improve formatting of returned facets
Browse files Browse the repository at this point in the history
  • Loading branch information
g-saracca committed Dec 9, 2024
1 parent f6c393a commit 1408cdd
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 44 deletions.
7 changes: 2 additions & 5 deletions src/collections/domain/models/CollectionItemSubset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@ export interface CollectionItemSubset {
}

export interface CollectionItemsFacet {
[key: string]: CollectionItemsFacetValue
}

interface CollectionItemsFacetValue {
friendly: string
name: string
friendlyName: string
labels: CollectionItemsFacetLabel[]
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, number>) => {
const [name, count] = Object.entries(label)[0]
return { name, count }
})
}
name: key,
friendlyName: facetData.friendly,
labels: facetData.labels.map((label: Record<string, number>) => {
const [name, count] = Object.entries(label)[0]
return { name, count }
})
})
)

Expand Down
36 changes: 18 additions & 18 deletions test/integration/collections/CollectionsRepository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
26 changes: 12 additions & 14 deletions test/testHelpers/collections/collectionItemsFacetsHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
]
}
]
}
Expand Down

0 comments on commit 1408cdd

Please sign in to comment.