Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ This changelog follows the principles of [Keep a Changelog](https://keepachangel

### Added

- Collections: Added theme information when retrieving a collection using `getCollection`.

### Changed

### Fixed
Expand Down
12 changes: 12 additions & 0 deletions src/collections/domain/models/Collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@ export interface Collection {
isMetadataBlockRoot: boolean
isFacetRoot: boolean
childCount: number
theme?: CollectionTheme
}

export interface CollectionTheme {
id: number
logo?: string
tagline?: string
linkUrl?: string
linkColor?: string
textColor?: string
backgroundColor?: string
logoBackgroundColor?: string
}

export interface CollectionInputLevel {
Expand Down
2 changes: 1 addition & 1 deletion src/collections/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export {
getCollectionLinks,
getCollectionsForLinking
}
export { Collection, CollectionInputLevel } from './domain/models/Collection'
export { Collection, CollectionInputLevel, CollectionTheme } from './domain/models/Collection'
export { CollectionFacet } from './domain/models/CollectionFacet'
export { CollectionUserPermissions } from './domain/models/CollectionUserPermissions'
export { CollectionDTO, CollectionInputLevelDTO } from './domain/dtos/CollectionDTO'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@ export interface CollectionPayload {
isMetadataBlockRoot: boolean
isFacetRoot: boolean
childCount: number
theme?: CollectionThemePayload
}

export interface CollectionThemePayload {
id: number
logo?: string
tagline?: string
linkUrl?: string
linkColor?: string
textColor?: string
backgroundColor?: string
logoBackgroundColor?: string
}

export interface CollectionInputLevelPayload {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { AxiosResponse } from 'axios'
import {
CollectionContactPayload,
CollectionInputLevelPayload,
CollectionPayload
CollectionPayload,
} from './CollectionPayload'
import { transformPayloadToOwnerNode } from '../../../../core/infra/repositories/transformers/dvObjectOwnerNodeTransformer'
import { CollectionFacet } from '../../../domain/models/CollectionFacet'
Expand Down Expand Up @@ -74,6 +74,9 @@ const transformPayloadToCollection = (collectionPayload: CollectionPayload): Col
isFacetRoot: collectionPayload.isFacetRoot,
description: collectionPayload.description,
childCount: collectionPayload.childCount,
...(collectionPayload.theme && {
theme: collectionPayload.theme
}),
...(collectionPayload.isPartOf && {
isPartOf: transformPayloadToOwnerNode(collectionPayload.isPartOf)
}),
Expand Down
11 changes: 11 additions & 0 deletions test/integration/collections/CollectionsRepository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,17 @@ describe('CollectionsRepository', () => {
expect(actual.alias).toBe(ROOT_COLLECTION_ALIAS)
expect(actual.isReleased).toBe(true)
})

test('should return theme for root collection', async () => {
const actual = await sut.getCollection()
expect(actual.alias).toBe(ROOT_COLLECTION_ALIAS)
// Root collection might or might not have a theme, but the property should be present if it does
// and we want to ensure the transformer doesn't fail.
// In a default Dataverse installation, root theme is usually undefined or has some default values.
if (actual.theme) {
expect(actual.theme).toHaveProperty('id')
}
})
})
describe('by string alias', () => {
test('should return collection when it exists filtering by id AS (alias)', async () => {
Expand Down
17 changes: 11 additions & 6 deletions test/testHelpers/collections/collectionHelper.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { Collection, CollectionFacet } from '../../../src/collections'
import { Collection, CollectionFacet, CollectionTheme } from '../../../src/collections'
import { DvObjectType } from '../../../src'
import { CollectionPayload } from '../../../src/collections/infra/repositories/transformers/CollectionPayload'
import {
CollectionPayload,
CollectionThemePayload
} from '../../../src/collections/infra/repositories/transformers/CollectionPayload'
import { TestConstants } from '../TestConstants'
import axios from 'axios'
import { CollectionDTO } from '../../../src/collections/domain/dtos/CollectionDTO'
Expand All @@ -22,7 +25,7 @@ const DATAVERSE_API_REQUEST_HEADERS = {
headers: { 'Content-Type': 'application/json', 'X-Dataverse-Key': process.env.TEST_API_KEY }
}

export const createCollectionModel = (): Collection => {
export const createCollectionModel = (theme?: CollectionTheme): Collection => {
const collectionModel: Collection = {
id: COLLECTION_ID,
alias: COLLECTION_ALIAS_STR,
Expand All @@ -47,12 +50,13 @@ export const createCollectionModel = (): Collection => {
],
isMetadataBlockRoot: true,
isFacetRoot: true,
childCount: 0
childCount: 0,
...(theme && { theme })
}
return collectionModel
}

export const createCollectionPayload = (): CollectionPayload => {
export const createCollectionPayload = (theme?: CollectionThemePayload): CollectionPayload => {
const collectionPayload: CollectionPayload = {
id: COLLECTION_ID,
alias: COLLECTION_ALIAS_STR,
Expand All @@ -77,7 +81,8 @@ export const createCollectionPayload = (): CollectionPayload => {
],
isMetadataBlockRoot: true,
isFacetRoot: true,
childCount: 0
childCount: 0,
...(theme && { theme })
}
return collectionPayload
}
Expand Down
30 changes: 28 additions & 2 deletions test/unit/collections/CollectionsRepository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ import {
createCollectionFacetRequestPayload,
createCollectionModel,
createCollectionPayload,
createNewCollectionRequestPayload
createNewCollectionRequestPayload,
} from '../../testHelpers/collections/collectionHelper'
import { TestConstants } from '../../testHelpers/TestConstants'
import { ReadError, WriteError } from '../../../src'
import { ROOT_COLLECTION_ID } from '../../../src/collections/domain/models/Collection'
import { ROOT_COLLECTION_ID, CollectionTheme } from '../../../src/collections/domain/models/Collection'
import { CollectionThemePayload } from '../../../src/collections/infra/repositories/transformers/CollectionPayload'
import {
createCollectionUserPermissionsModel,
createCollectionUserPermissionsPayload
Expand Down Expand Up @@ -95,6 +96,31 @@ describe('CollectionsRepository', () => {
expect(error).toBeInstanceOf(Error)
})
})

describe('with theme', () => {
test('should return Collection with theme when providing a numeric id and the collection has a theme with only some fields', async () => {
const testThemePayload: CollectionThemePayload = {
id: 1
}
const testCollectionPayload = createCollectionPayload(testThemePayload)
const testThemeModel: CollectionTheme = {
id: 1
}
const testCollectionModelWithTheme = createCollectionModel(testThemeModel)

jest.spyOn(axios, 'get').mockResolvedValue({
data: {
status: 'OK',
data: testCollectionPayload
}
})

const actual = await sut.getCollection(testCollectionModel.id)

expect(actual).toStrictEqual(testCollectionModelWithTheme)
})
})

describe('by alias id', () => {
test('should return a Collection when providing the Collection alias is successful', async () => {
jest.spyOn(axios, 'get').mockResolvedValue(testCollectionSuccessfulResponse)
Expand Down
Loading