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 2 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)
}
16 changes: 12 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_HTML,
MellyGray marked this conversation as resolved.
Show resolved Hide resolved
isPartOf: { type: DvObjectType.DATAVERSE, identifier: 'root', displayName: 'Root' }
}
return collectionModel
Expand All @@ -26,8 +26,16 @@ 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
}
export const transformedCollectionModel: CollectionPayload = {
MellyGray marked this conversation as resolved.
Show resolved Hide resolved
id: COLLECTION_ID,
alias: COLLECTION_ALIAS_STR,
name: COLLECTION_NAME_STR,
affiliation: COLLECTION_AFFILIATION_STR,
description: COLLECTION_DESCRIPTION_MARKDOWN,
isPartOf: { type: DvObjectType.DATAVERSE, identifier: 'root', displayName: 'Root' }
}
9 changes: 5 additions & 4 deletions test/unit/collections/CollectionsRepository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import {
} from '../../../src/core/infra/repositories/ApiConfig'
import {
createCollectionModel,
createCollectionPayload
createCollectionPayload,
transformedCollectionModel
} from '../../testHelpers/collections/collectionHelper'
import { TestConstants } from '../../testHelpers/TestConstants'
import { ReadError } from '../../../src'
Expand Down Expand Up @@ -45,7 +46,7 @@ describe('CollectionsRepository', () => {
const actual = await sut.getCollection(testCollectionModel.id)

expect(axios.get).toHaveBeenCalledWith(expectedApiEndpoint, expectedRequestConfigApiKey)
expect(actual).toStrictEqual(testCollectionModel)
expect(actual).toStrictEqual(transformedCollectionModel)
MellyGray marked this conversation as resolved.
Show resolved Hide resolved
})

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

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

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

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

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