Skip to content

Commit

Permalink
clean up publicationDate mapping logic
Browse files Browse the repository at this point in the history
  • Loading branch information
ekraffmiller committed Jul 8, 2024
1 parent 1cf2dd5 commit 28a1ff0
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 36 deletions.
3 changes: 1 addition & 2 deletions src/dataset/domain/models/Dataset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -458,8 +458,7 @@ export class Dataset {
public readonly hierarchy: UpwardHierarchyNode,
public readonly thumbnail?: string,
public readonly privateUrl?: PrivateUrl, // will be set if the user requested a version that did not exist
public readonly requestedVersion?: string,
public readonly publicationDate?: string
public readonly requestedVersion?: string
) {
this.withAlerts()
}
Expand Down
3 changes: 1 addition & 2 deletions src/dataset/infrastructure/mappers/JSDatasetMapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ export class JSDatasetMapper {
),
undefined, // TODO: get dataset thumbnail from js-dataverse https://github.com/IQSS/dataverse-frontend/issues/203
privateUrl,
requestedVersion,
jsDataset.publicationDate
requestedVersion
).build()
}

Expand Down
150 changes: 118 additions & 32 deletions tests/component/dataset/infrastructure/mappers/JSDatasetMapper.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,103 @@ const expectedDataset = {
new UpwardHierarchyNode('Root', DvObjectType.COLLECTION, 'root')
)
}
const expectedDatasetWithPublicationDate = {
persistentId: 'doi:10.5072/FK2/B4B2MJ',
version: {
id: 101,
title: "Darwin's Finches",
labels: [{ semanticMeaning: 'dataset', value: 'Draft' }],
publishingStatus: 'draft',
isLatest: true,
isInReview: false,
latestVersionPublishingStatus: 'draft',
number: {
minorNumber: 0,
majorNumber: 0
},
someDatasetVersionHasBeenReleased: true,
citation:
'Finch, Fiona, 2023, "Darwin\'s Finches", <a href="https://doi.org/10.5072/FK2/B4B2MJ" target="_blank">https://doi.org/10.5072/FK2/B4B2MJ</a>, Root, DRAFT VERSION'
},
requestedVersion: undefined,
publicationDate: undefined,
alerts: [{ variant: 'warning', messageKey: 'draftVersion', dynamicFields: undefined }],
summaryFields: [
{
name: 'citation',
fields: {
dsDescription: [
{
dsDescriptionValue:
"Darwin's finches (also known as the Galápagos finches) are a group of about fifteen species of passerine birds."
}
],
subject: ['Medicine, Health and Life Sciences']
}
}
],
license: {
name: 'CC0 1.0',
uri: 'http://creativecommons.org/publicdomain/zero/1.0',
iconUri: 'https://licensebuttons.net/p/zero/1.0/88x31.png'
},
metadataBlocks: [
{
name: 'citation',
fields: {
title: "Darwin's Finches",
author: [{ authorName: 'Finch, Fiona', authorAffiliation: 'Birds Inc.' }],
datasetContact: [
{ datasetContactName: 'Finch, Fiona', datasetContactEmail: '[email protected]' }
],
dsDescription: [
{
dsDescriptionValue:
"Darwin's finches (also known as the Galápagos finches) are a group of about fifteen species of passerine birds."
}
],
subject: ['Medicine, Health and Life Sciences'],
publicationDate: '2023-02-12'
}
}
],
permissions: {
canDownloadFiles: true,
canUpdateDataset: true,
canPublishDataset: true,
canManageDatasetPermissions: true,
canManageFilesPermissions: true,
canDeleteDataset: true
},
locks: [
{
userPersistentId: 'dataverseAdmin',
reason: DatasetLockReason.IN_REVIEW
}
],
hasValidTermsOfAccess: true,
hasOneTabularFileAtLeast: true,
isValid: true,
thumbnail: undefined,
privateUrl: undefined,
fileDownloadSizes: [
new FileDownloadSize(5, FileSizeUnit.BYTES, FileDownloadMode.ORIGINAL),
new FileDownloadSize(7, FileSizeUnit.BYTES, FileDownloadMode.ARCHIVAL)
],
downloadUrls: {
original: `/api/access/dataset/:persistentId/versions/0.0?persistentId=doi:10.5072/FK2/B4B2MJ&format=original`,
archival: `/api/access/dataset/:persistentId/versions/0.0?persistentId=doi:10.5072/FK2/B4B2MJ`
},
hierarchy: new UpwardHierarchyNode(
"Darwin's Finches",
DvObjectType.DATASET,
'505',
'doi:10.5072/FK2/B4B2MJ',
'0.0',
new UpwardHierarchyNode('Root', DvObjectType.COLLECTION, 'root')
)
}

const expectedDatasetAlternateVersion = {
persistentId: 'doi:10.5072/FK2/B4B2MJ',
version: {
Expand Down Expand Up @@ -411,39 +508,28 @@ describe('JS Dataset Mapper', () => {
...jsDataset,
publicationDate: '2023-02-12'
}
const expectedDatasetWithPublicationDate = {
...expectedDataset,
metadataBlocks: [
{
name: 'citation',
fields: {
title: "Darwin's Finches",
author: [{ authorName: 'Finch, Fiona', authorAffiliation: 'Birds Inc.' }],
datasetContact: [
{ datasetContactName: 'Finch, Fiona', datasetContactEmail: '[email protected]' }
],
dsDescription: [
{
dsDescriptionValue:
"Darwin's finches (also known as the Galápagos finches) are a group of about fifteen species of passerine birds."
}
],
subject: ['Medicine, Health and Life Sciences'],
publicationDate: '2023-02-12'
}
}
]

const actual = JSDatasetMapper.toDataset(
jsDatasetWithPublicationDate,
citation,
datasetSummaryFields,
jsDatasetPermissions,
jsDatasetLocks,
jsDatasetFilesTotalOriginalDownloadSize,
jsDatasetFilesTotalArchivalDownloadSize
)
const replacer = function (key, value) {
if (value === undefined) {
return null
}
return value
}
expect(expectedDatasetWithPublicationDate).to.deep.equal(
JSDatasetMapper.toDataset(
jsDatasetWithPublicationDate,
citation,
datasetSummaryFields,
jsDatasetPermissions,
jsDatasetLocks,
jsDatasetFilesTotalOriginalDownloadSize,
jsDatasetFilesTotalArchivalDownloadSize
)

console.log('actual', JSON.stringify(actual, replacer))
console.log(
'expectedDatasetWithPublicationDate',
JSON.stringify(expectedDatasetWithPublicationDate, replacer)
)
expect(expectedDatasetWithPublicationDate).to.deep.equal(actual)
})
})

0 comments on commit 28a1ff0

Please sign in to comment.