Skip to content

Commit 57409da

Browse files
authored
Merge pull request #417 from vera/feat/get-collection-theme
Extend "get collection" use case to return theme
2 parents 2b58ce3 + 0a587e8 commit 57409da

8 files changed

Lines changed: 79 additions & 9 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ This changelog follows the principles of [Keep a Changelog](https://keepachangel
99
### Added
1010

1111
- Collections: Added `allowedDatasetTypes` field to the [Collection](./src/collections/domain/models/Collection.ts) model. This field is optional and only populated the feature is enabled on the installation and configured on the collection.
12+
- Collections: Added theme information when retrieving a collection using `getCollection`.
1213

1314
### Changed
1415

src/collections/domain/models/Collection.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,18 @@ export interface Collection {
1818
isMetadataBlockRoot: boolean
1919
isFacetRoot: boolean
2020
childCount: number
21+
theme?: CollectionTheme
22+
}
23+
24+
export interface CollectionTheme {
25+
id: number
26+
logo?: string
27+
tagline?: string
28+
linkUrl?: string
29+
linkColor?: string
30+
textColor?: string
31+
backgroundColor?: string
32+
logoBackgroundColor?: string
2133
}
2234

2335
export interface CollectionInputLevel {

src/collections/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export {
7070
deleteCollectionStorageDriver,
7171
getAllowedCollectionStorageDrivers
7272
}
73-
export { Collection, CollectionInputLevel } from './domain/models/Collection'
73+
export { Collection, CollectionInputLevel, CollectionTheme } from './domain/models/Collection'
7474
export { CollectionFacet } from './domain/models/CollectionFacet'
7575
export { CollectionUserPermissions } from './domain/models/CollectionUserPermissions'
7676
export { CollectionDTO, CollectionInputLevelDTO } from './domain/dtos/CollectionDTO'

src/collections/infra/repositories/transformers/CollectionPayload.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,18 @@ export interface CollectionPayload {
1515
isMetadataBlockRoot: boolean
1616
isFacetRoot: boolean
1717
childCount: number
18+
theme?: CollectionThemePayload
19+
}
20+
21+
export interface CollectionThemePayload {
22+
id: number
23+
logo?: string
24+
tagline?: string
25+
linkUrl?: string
26+
linkColor?: string
27+
textColor?: string
28+
backgroundColor?: string
29+
logoBackgroundColor?: string
1830
}
1931

2032
export interface CollectionInputLevelPayload {

src/collections/infra/repositories/transformers/collectionTransformers.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ const transformPayloadToCollection = (collectionPayload: CollectionPayload): Col
7575
isFacetRoot: collectionPayload.isFacetRoot,
7676
description: collectionPayload.description,
7777
childCount: collectionPayload.childCount,
78+
...(collectionPayload.theme && {
79+
theme: collectionPayload.theme
80+
}),
7881
...(collectionPayload.isPartOf && {
7982
isPartOf: transformPayloadToOwnerNode(collectionPayload.isPartOf)
8083
}),

test/integration/collections/CollectionsRepository.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,17 @@ describe('CollectionsRepository', () => {
110110
expect(actual.alias).toBe(ROOT_COLLECTION_ALIAS)
111111
expect(actual.isReleased).toBe(true)
112112
})
113+
114+
test('should return theme for root collection', async () => {
115+
const actual = await sut.getCollection()
116+
expect(actual.alias).toBe(ROOT_COLLECTION_ALIAS)
117+
// Root collection might or might not have a theme, but the property should be present if it does
118+
// and we want to ensure the transformer doesn't fail.
119+
// In a default Dataverse installation, root theme is usually undefined or has some default values.
120+
if (actual.theme) {
121+
expect(actual.theme).toHaveProperty('id')
122+
}
123+
})
113124
})
114125
describe('by string alias', () => {
115126
test('should return collection when it exists filtering by id AS (alias)', async () => {

test/testHelpers/collections/collectionHelper.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
import { Collection, CollectionFacet } from '../../../src/collections'
1+
import { Collection, CollectionFacet, CollectionTheme } from '../../../src/collections'
22
import { DvObjectType } from '../../../src'
3-
import { CollectionPayload } from '../../../src/collections/infra/repositories/transformers/CollectionPayload'
3+
import {
4+
CollectionPayload,
5+
CollectionThemePayload
6+
} from '../../../src/collections/infra/repositories/transformers/CollectionPayload'
47
import { TestConstants } from '../TestConstants'
58
import axios from 'axios'
69
import { CollectionDTO } from '../../../src/collections/domain/dtos/CollectionDTO'
@@ -22,7 +25,7 @@ const DATAVERSE_API_REQUEST_HEADERS = {
2225
headers: { 'Content-Type': 'application/json', 'X-Dataverse-Key': process.env.TEST_API_KEY }
2326
}
2427

25-
export const createCollectionModel = (): Collection => {
28+
export const createCollectionModel = (theme?: CollectionTheme): Collection => {
2629
const collectionModel: Collection = {
2730
id: COLLECTION_ID,
2831
alias: COLLECTION_ALIAS_STR,
@@ -55,12 +58,13 @@ export const createCollectionModel = (): Collection => {
5558
],
5659
isMetadataBlockRoot: true,
5760
isFacetRoot: true,
58-
childCount: 0
61+
childCount: 0,
62+
...(theme && { theme })
5963
}
6064
return collectionModel
6165
}
6266

63-
export const createCollectionPayload = (): CollectionPayload => {
67+
export const createCollectionPayload = (theme?: CollectionThemePayload): CollectionPayload => {
6468
const collectionPayload: CollectionPayload = {
6569
id: COLLECTION_ID,
6670
alias: COLLECTION_ALIAS_STR,
@@ -93,7 +97,8 @@ export const createCollectionPayload = (): CollectionPayload => {
9397
],
9498
isMetadataBlockRoot: true,
9599
isFacetRoot: true,
96-
childCount: 0
100+
childCount: 0,
101+
...(theme && { theme })
97102
}
98103
return collectionPayload
99104
}

test/unit/collections/CollectionsRepository.test.ts

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@ import {
1212
createCollectionFacetRequestPayload,
1313
createCollectionModel,
1414
createCollectionPayload,
15-
createNewCollectionRequestPayload
15+
createNewCollectionRequestPayload,
1616
} from '../../testHelpers/collections/collectionHelper'
1717
import { TestConstants } from '../../testHelpers/TestConstants'
1818
import { ReadError, WriteError } from '../../../src'
19-
import { ROOT_COLLECTION_ID } from '../../../src/collections/domain/models/Collection'
19+
import { ROOT_COLLECTION_ID, CollectionTheme } from '../../../src/collections/domain/models/Collection'
20+
import { CollectionThemePayload } from '../../../src/collections/infra/repositories/transformers/CollectionPayload'
2021
import { AllowedStorageDrivers } from '../../../src/collections/domain/models/AllowedStorageDrivers'
2122
import { StorageDriver } from '../../../src/core/domain/models/StorageDriver'
2223
import {
@@ -137,6 +138,31 @@ describe('CollectionsRepository', () => {
137138
expect(error).toBeInstanceOf(Error)
138139
})
139140
})
141+
142+
describe('with theme', () => {
143+
test('should return Collection with theme when providing a numeric id and the collection has a theme with only some fields', async () => {
144+
const testThemePayload: CollectionThemePayload = {
145+
id: 1
146+
}
147+
const testCollectionPayload = createCollectionPayload(testThemePayload)
148+
const testThemeModel: CollectionTheme = {
149+
id: 1
150+
}
151+
const testCollectionModelWithTheme = createCollectionModel(testThemeModel)
152+
153+
jest.spyOn(axios, 'get').mockResolvedValue({
154+
data: {
155+
status: 'OK',
156+
data: testCollectionPayload
157+
}
158+
})
159+
160+
const actual = await sut.getCollection(testCollectionModel.id)
161+
162+
expect(actual).toStrictEqual(testCollectionModelWithTheme)
163+
})
164+
})
165+
140166
describe('by alias id', () => {
141167
test('should return a Collection when providing the Collection alias is successful', async () => {
142168
jest.spyOn(axios, 'get').mockResolvedValue(testCollectionSuccessfulResponse)

0 commit comments

Comments
 (0)