Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

140 transform html to markdown for Collection description #145

Merged
merged 3 commits into from
Apr 22, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Collection } from '../../../domain/models/Collection'
import { AxiosResponse } from 'axios'
import { CollectionPayload } from './CollectionPayload'
import { transformPayloadToOwnerNode } from '../../../../core/infra/repositories/transformers/dvObjectOwnerNodeTransformer'
import { transformHtmlToMarkdown } from '../../../../datasets/infra/repositories/transformers/datasetTransformers'

export const transformCollectionResponseToCollection = (response: AxiosResponse): Collection => {
const collectionPayload = response.data.data
Expand All @@ -14,7 +15,7 @@ const transformPayloadToCollection = (collectionPayload: CollectionPayload): Col
alias: collectionPayload.alias,
name: collectionPayload.name,
affiliation: collectionPayload.affiliation,
description: collectionPayload.description,
description: transformHtmlToMarkdown(collectionPayload.description),
...(collectionPayload.isPartOf && {
isPartOf: transformPayloadToOwnerNode(collectionPayload.isPartOf)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,6 @@ const transformPayloadToDatasetMetadataSubfieldValue = (
return result
}

const transformHtmlToMarkdown = (source: string): string => {
export const transformHtmlToMarkdown = (source: string): string => {
return turndownService.turndown(source)
}
8 changes: 4 additions & 4 deletions test/testHelpers/collections/collectionHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ const COLLECTION_ID = 11111
const COLLECTION_ALIAS_STR = 'secondCollection'
const COLLECTION_NAME_STR = 'Laboratory Research'
const COLLECTION_AFFILIATION_STR = 'Laboratory Research Corporation'
const COLLECTION_DESCRIPTION_STR = 'This is an example collection used for testing.'

const COLLECTION_DESCRIPTION_HTML = 'This is an <b>example</b> collection used for testing.'
const COLLECTION_DESCRIPTION_MARKDOWN = 'This is an **example** collection used for testing.'
export const createCollectionModel = (): Collection => {
const collectionModel: Collection = {
id: COLLECTION_ID,
alias: COLLECTION_ALIAS_STR,
name: COLLECTION_NAME_STR,
affiliation: COLLECTION_AFFILIATION_STR,
description: COLLECTION_DESCRIPTION_STR,
description: COLLECTION_DESCRIPTION_MARKDOWN,
isPartOf: { type: DvObjectType.DATAVERSE, identifier: 'root', displayName: 'Root' }
}
return collectionModel
Expand All @@ -26,7 +26,7 @@ export const createCollectionPayload = (): CollectionPayload => {
alias: COLLECTION_ALIAS_STR,
name: COLLECTION_NAME_STR,
affiliation: COLLECTION_AFFILIATION_STR,
description: COLLECTION_DESCRIPTION_STR,
description: COLLECTION_DESCRIPTION_HTML,
isPartOf: { type: DvObjectType.DATAVERSE, identifier: 'root', displayName: 'Root' }
}
return collectionPayload
Expand Down
6 changes: 3 additions & 3 deletions test/unit/collections/CollectionsRepository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe('CollectionsRepository', () => {
const actual = await sut.getCollection(testCollectionModel.id)

expect(axios.get).toHaveBeenCalledWith(expectedApiEndpoint, expectedRequestConfigApiKey)
expect(actual).toStrictEqual(testCollectionModel)
expect(actual).toStrictEqual(createCollectionModel())
})

test('should return error on repository read error', async () => {
Expand All @@ -68,7 +68,7 @@ describe('CollectionsRepository', () => {
const actual = await sut.getCollection(testCollectionModel.alias)

expect(axios.get).toHaveBeenCalledWith(expectedApiEndpoint, expectedRequestConfigApiKey)
expect(actual).toStrictEqual(testCollectionModel)
expect(actual).toStrictEqual(createCollectionModel())
})

test('should return error on repository read error', async () => {
Expand All @@ -91,7 +91,7 @@ describe('CollectionsRepository', () => {
const actual = await sut.getCollection()

expect(axios.get).toHaveBeenCalledWith(expectedApiEndpoint, expectedRequestConfigApiKey)
expect(actual).toStrictEqual(testCollectionModel)
expect(actual).toStrictEqual(createCollectionModel())
})

test('should return error on repository read error', async () => {
Expand Down
Loading