Skip to content

Commit

Permalink
Merge branch 'develop' into feat/202-featured-items-use-cases
Browse files Browse the repository at this point in the history
  • Loading branch information
g-saracca committed Jan 13, 2025
2 parents f58eed6 + d9a70a2 commit 1de7036
Show file tree
Hide file tree
Showing 10 changed files with 213 additions and 11 deletions.
1 change: 1 addition & 0 deletions src/datasets/domain/models/DatasetPreview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ export interface DatasetPreview {
publicationStatuses: PublicationStatus[]
parentCollectionName: string
parentCollectionAlias: string
imageUrl?: string
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ export interface DatasetPreviewPayload {
publicationStatuses: string[]
identifier_of_dataverse: string
name_of_dataverse: string
image_url?: string
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ export const transformDatasetPreviewPayloadToDatasetPreview = (
description: datasetPreviewPayload.description,
publicationStatuses: publicationStatuses,
parentCollectionAlias: datasetPreviewPayload.identifier_of_dataverse,
parentCollectionName: datasetPreviewPayload.name_of_dataverse
parentCollectionName: datasetPreviewPayload.name_of_dataverse,
...(datasetPreviewPayload.image_url && {
imageUrl: datasetPreviewPayload.image_url
})
}
}
6 changes: 6 additions & 0 deletions src/files/domain/models/FilePreview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ export interface FilePreview {
datasetCitation: string
publicationStatuses: PublicationStatus[]
releaseOrCreateDate: Date
restricted: boolean
canDownloadFile: boolean
categories?: string[]
tabularTags?: string[]
variables?: number
observations?: number
}

export interface FilePreviewChecksum {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ export interface FilePreviewPayload {
dataset_citation: string
publicationStatuses: string[]
releaseOrCreateDate: string
restricted: boolean
canDownloadFile: boolean
categories?: string[]
tabularTags?: string[]
variables?: number
observations?: number
}

export interface FilePreviewChecksumPayload {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ export const transformFilePreviewPayloadToFilePreview = (
datasetPersistentId: filePreviewPayload.dataset_persistent_id,
datasetCitation: filePreviewPayload.dataset_citation,
publicationStatuses: publicationStatuses,
releaseOrCreateDate: new Date(filePreviewPayload.releaseOrCreateDate)
releaseOrCreateDate: new Date(filePreviewPayload.releaseOrCreateDate),
restricted: filePreviewPayload.restricted,
canDownloadFile: filePreviewPayload.canDownloadFile,
...(filePreviewPayload.categories && { categories: filePreviewPayload.categories }),
...(filePreviewPayload.tabularTags && {
tabularTags: filePreviewPayload.tabularTags
}),
...(filePreviewPayload.variables && { variables: filePreviewPayload.variables }),
...(filePreviewPayload.observations && { observations: filePreviewPayload.observations })
}
}
165 changes: 160 additions & 5 deletions test/integration/collections/CollectionsRepository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@ import {
ROOT_COLLECTION_ALIAS
} from '../../testHelpers/collections/collectionHelper'
import { CollectionPayload } from '../../../src/collections/infra/repositories/transformers/CollectionPayload'
import { uploadFileViaApi } from '../../testHelpers/files/filesHelper'
import { deleteUnpublishedDatasetViaApi } from '../../testHelpers/datasets/datasetHelper'
import { updateFileTabularTags, uploadFileViaApi } from '../../testHelpers/files/filesHelper'
import {
deletePublishedDatasetViaApi,
deleteUnpublishedDatasetViaApi,
publishDatasetViaApi
} from '../../testHelpers/datasets/datasetHelper'
import { PublicationStatus } from '../../../src/core/domain/models/PublicationStatus'
import { CollectionType } from '../../../src/collections/domain/models/CollectionType'
import {
Expand All @@ -41,7 +45,7 @@ describe('CollectionsRepository', () => {
const testCollectionAlias = 'collectionsRepositoryTestCollection'
const sut: CollectionsRepository = new CollectionsRepository()
let testCollectionId: number

const currentYear = new Date().getFullYear()
beforeAll(async () => {
ApiConfig.init(
TestConstants.TEST_API_URL,
Expand Down Expand Up @@ -300,8 +304,7 @@ describe('CollectionsRepository', () => {
const actualCollectionPreview = actual.items[2] as CollectionPreview

const expectedFileMd5 = '68b22040025784da775f55cfcb6dee2e'
const expectedDatasetCitationFragment =
'Admin, Dataverse; Owner, Dataverse, 2025, "Dataset created using the createDataset use case'
const expectedDatasetCitationFragment = `Admin, Dataverse; Owner, Dataverse, ${currentYear}, "Dataset created using the createDataset use case"`
const expectedDatasetDescription = 'Dataset created using the createDataset use case'
const expectedFileName = 'test-file-1.txt'
const expectedCollectionsName = 'Scientific Research'
Expand Down Expand Up @@ -386,6 +389,8 @@ describe('CollectionsRepository', () => {
expect(actualFilePreview.url).not.toBeUndefined()
expect(actualFilePreview.releaseOrCreateDate).not.toBeUndefined()
expect(actualFilePreview.type).toBe(CollectionItemType.FILE)
expect(actualFilePreview.restricted).toBe(false)
expect(actualFilePreview.canDownloadFile).toBe(true)

expect(actualDatasetPreview.title).toBe(expectedDatasetDescription)
expect(actualDatasetPreview.citation).toContain(expectedDatasetCitationFragment)
Expand Down Expand Up @@ -666,6 +671,156 @@ describe('CollectionsRepository', () => {
})
})

describe('getCollectionItems for published tabular file', () => {
let testDatasetIds: CreatedDatasetIdentifiers
const testTextFile4Name = 'test-file-4.tab'
const testSubCollectionAlias = 'collectionsRepositoryTestSubCollection'

beforeAll(async () => {
await sut.publishCollection(testCollectionId).catch(() => {
throw new Error(`Tests beforeAll(): Error while publishing collection ${testCollectionId}`)
})

const collectionPayload = await createCollectionViaApi(
testSubCollectionAlias,
testCollectionAlias
).catch(() => {
throw new Error(
`Tests beforeAll(): Error while creating subcollection ${testSubCollectionAlias}`
)
})

await sut.publishCollection(collectionPayload.id).catch(() => {
throw new Error(`Tests beforeAll(): Error while publishing collection ${testCollectionId}`)
})

try {
testDatasetIds = await createDataset.execute(
TestConstants.TEST_NEW_DATASET_DTO,
testSubCollectionAlias
)
} catch (error) {
throw new Error('Tests beforeAll(): Error while creating test dataset')
}
const uploadFileViaApiResult = await uploadFileViaApi(
testDatasetIds.numericId,
testTextFile4Name,
{
categories: ['tabular data']
}
).catch(() => {
throw new Error(`Tests beforeAll(): Error while uploading file ${testTextFile4Name}`)
})
await new Promise((resolve) => setTimeout(resolve, 5000))

await updateFileTabularTags(uploadFileViaApiResult.data.data.files[0].dataFile.id, [
'Survey',
'Genomics'
]).catch(() => {
throw new Error(
`Tests beforeAll(): Error while updating file tabular tags ${uploadFileViaApiResult.data.data.files[0].dataFile.id}`
)
})

await publishDatasetViaApi(testDatasetIds.numericId).catch(() => {
throw new Error(
`Tests beforeAll(): Error while publishing dataset ${testDatasetIds.numericId}`
)
})
})

afterAll(async () => {
try {
await deletePublishedDatasetViaApi(testDatasetIds.persistentId)
} catch (error) {
throw new Error(
`Tests afterAll(): Error while deleting test dataset ${testDatasetIds.persistentId}`
)
}
try {
await deleteCollectionViaApi(testSubCollectionAlias)
} catch (error) {
throw new Error(
`Tests afterAll(): Error while deleting subcollection ${testSubCollectionAlias}`
)
}
})

test('should return collection items given a valid collection alias', async () => {
// Give enough time to Solr for indexing
await new Promise((resolve) => setTimeout(resolve, 5000))

const actual = await sut.getCollectionItems(testCollectionAlias)
const actualFilePreview = actual.items[1] as FilePreview
const actualDatasetPreview = actual.items[0] as DatasetPreview
const actualCollectionPreview = actual.items[2] as CollectionPreview

const expectedFileMd5 = '77c7f03a7d7772907b43f0b322cef723'

const expectedDatasetCitationFragment = `Admin, Dataverse; Owner, Dataverse, ${currentYear}, "Dataset created using the createDataset use case`
const expectedDatasetDescription = 'Dataset created using the createDataset use case'
const expectedFileName = 'test-file-4.tab'
const expectedCollectionsName = 'Scientific Research'

expect(actualFilePreview.checksum?.type).toBe('MD5')
expect(actualFilePreview.checksum?.value).toBe(expectedFileMd5)
expect(actualFilePreview.datasetCitation).toContain(expectedDatasetCitationFragment)
expect(actualFilePreview.datasetId).toBe(testDatasetIds.numericId)
expect(actualFilePreview.datasetName).toBe(expectedDatasetDescription)
expect(actualFilePreview.datasetPersistentId).toBe(testDatasetIds.persistentId)
expect(actualFilePreview.description).toBe('')
expect(actualFilePreview.fileContentType).toBe('text/tab-separated-values')
expect(actualFilePreview.fileId).not.toBeUndefined()
expect(actualFilePreview.fileType).toBe('Tab-Delimited')
expect(actualFilePreview.md5).toBe(expectedFileMd5)
expect(actualFilePreview.name).toBe(expectedFileName)
expect(actualFilePreview.publicationStatuses[0]).toBe(PublicationStatus.Published)
expect(actualFilePreview.sizeInBytes).toBe(137)
expect(actualFilePreview.url).not.toBeUndefined()
expect(actualFilePreview.releaseOrCreateDate).not.toBeUndefined()
expect(actualFilePreview.type).toBe(CollectionItemType.FILE)
expect(actualFilePreview.restricted).toBe(false)
expect(actualFilePreview.canDownloadFile).toBe(true)
expect(actualFilePreview.categories).toEqual(['tabular data'])
expect(actualFilePreview.tabularTags).toEqual(['Genomics', 'Survey'])
expect(actualFilePreview.observations).toBe(10)
expect(actualFilePreview.variables).toBe(3)

expect(actualDatasetPreview.title).toBe(expectedDatasetDescription)
expect(actualDatasetPreview.citation).toContain(expectedDatasetCitationFragment)
expect(actualDatasetPreview.description).toBe('This is the description of the dataset.')
expect(actualDatasetPreview.persistentId).not.toBeUndefined()
expect(actualDatasetPreview.persistentId).not.toBeUndefined()
expect(actualDatasetPreview.publicationStatuses[0]).toBe(PublicationStatus.Published)
expect(actualDatasetPreview.versionId).not.toBeUndefined()
expect(actualDatasetPreview.versionInfo.createTime).not.toBeUndefined()
expect(actualDatasetPreview.versionInfo.lastUpdateTime).not.toBeUndefined()
expect(actualDatasetPreview.versionInfo.majorNumber).toBe(1)
expect(actualDatasetPreview.versionInfo.minorNumber).toBe(0)
expect(actualDatasetPreview.versionInfo.state).toBe('RELEASED')
expect(actualDatasetPreview.parentCollectionAlias).toBe(
'collectionsRepositoryTestSubCollection'
)
expect(actualDatasetPreview.parentCollectionName).toBe(expectedCollectionsName)
expect(actualDatasetPreview.type).toBe(CollectionItemType.DATASET)

expect(actualCollectionPreview.name).toBe(expectedCollectionsName)
expect(actualCollectionPreview.alias).toBe(testSubCollectionAlias)
expect(actualCollectionPreview.description).toBe('We do all the science.')
expect(actualCollectionPreview.imageUrl).toBe(undefined)
expect(actualCollectionPreview.parentAlias).toBe(testCollectionAlias)
expect(actualCollectionPreview.parentName).toBe(expectedCollectionsName)
expect(actualCollectionPreview.publicationStatuses[0]).toBe(PublicationStatus.Published)
expect(actualCollectionPreview.releaseOrCreateDate).not.toBeUndefined()
expect(actualCollectionPreview.affiliation).toBe('Scientific Research University')
expect(actualCollectionPreview.parentAlias).toBe('collectionsRepositoryTestCollection')
expect(actualCollectionPreview.parentName).toBe(expectedCollectionsName)
expect(actualCollectionPreview.type).toBe(CollectionItemType.COLLECTION)

expect(actual.totalItemCount).toBe(3)
})
})

describe('updateCollection', () => {
const testUpdatedCollectionAlias = 'updateCollection-test-updatedAlias'

Expand Down
6 changes: 4 additions & 2 deletions test/testHelpers/datasets/datasetPreviewHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ export const createDatasetPreviewModel = (): DatasetPreview => {
description: 'test',
publicationStatuses: [PublicationStatus.Draft, PublicationStatus.Unpublished],
parentCollectionAlias: 'parentCollection',
parentCollectionName: 'Parent Collection'
parentCollectionName: 'Parent Collection',
imageUrl: 'http://dataverse.com'
}
return datasetPreviewModel
}
Expand All @@ -50,6 +51,7 @@ export const createDatasetPreviewPayload = (): DatasetPreviewPayload => {
type: 'dataset',
publicationStatuses: ['Draft', 'Unpublished'],
identifier_of_dataverse: 'parentCollection',
name_of_dataverse: 'Parent Collection'
name_of_dataverse: 'Parent Collection',
image_url: 'http://dataverse.com'
}
}
8 changes: 6 additions & 2 deletions test/testHelpers/files/filePreviewHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ export const createFilePreviewModel = (): FilePreview => {
datasetPersistentId: 'test pid1',
datasetCitation: 'test citation',
publicationStatuses: [PublicationStatus.Published],
releaseOrCreateDate: new Date('2023-05-15T08:21:01Z')
releaseOrCreateDate: new Date('2023-05-15T08:21:01Z'),
canDownloadFile: true,
restricted: false
}
return filePreviewModel
}
Expand Down Expand Up @@ -53,6 +55,8 @@ export const createFilePreviewPayload = (): FilePreviewPayload => {
dataset_persistent_id: 'test pid1',
dataset_citation: 'test citation',
publicationStatuses: ['Published'],
releaseOrCreateDate: '2023-05-15T08:21:01Z'
releaseOrCreateDate: '2023-05-15T08:21:01Z',
canDownloadFile: true,
restricted: false
}
}
16 changes: 16 additions & 0 deletions test/testHelpers/files/filesHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,3 +211,19 @@ async function createBlobWithSize(size: number): Promise<Blob> {
const arrayBuffer = new ArrayBuffer(size)
return new Blob([arrayBuffer])
}

export const updateFileTabularTags = async (
fileId: number,
tabularTags: string[]
): Promise<AxiosResponse> => {
return await axios.post(
`${TestConstants.TEST_API_URL}/files/${fileId}/metadata/tabularTags`,
{ tabularTags },
{
headers: {
'Content-type': 'application/json',
'X-Dataverse-Key': process.env.TEST_API_KEY
}
}
)
}

0 comments on commit 1de7036

Please sign in to comment.