Skip to content
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
2 changes: 2 additions & 0 deletions docs/useCases.md
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,8 @@ The `datasetId` parameter can be a string, for persistent identifiers, or a numb

The `oldVersion` and `newVersion` parameters specify the versions of the dataset to compare.

There is an optional third parameter called `includeDeaccessioned`, by default, deaccessioned dataset versions are not included in the search when applying the `:latest` or `:latest-published` identifiers. If not set, the default value is `false`.

#### List All Datasets

Returns an instance of [DatasetPreviewSubset](../src/datasets/domain/models/DatasetPreviewSubset.ts) that contains reduced information for each dataset that the calling user can access in the installation.
Expand Down
3 changes: 3 additions & 0 deletions src/datasets/domain/models/DatasetVersionDiff.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { DatasetVersionState } from './Dataset'

export interface DatasetVersionDiff {
oldVersion: VersionSummary
newVersion: VersionSummary
Expand All @@ -24,6 +26,7 @@ export interface FileSummary {
export interface VersionSummary {
versionNumber: string
lastUpdatedDate: string
versionState: DatasetVersionState
}
export interface MetadataBlockDiff {
blockName: string
Expand Down
3 changes: 2 additions & 1 deletion src/datasets/domain/repositories/IDatasetsRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ export interface IDatasetsRepository {
getDatasetVersionDiff(
datasetId: number | string,
newVersionId: string,
oldVersionId: string
oldVersionId: string,
includeDeaccessioned: boolean
): Promise<DatasetVersionDiff>
createDataset(
newDataset: DatasetDTO,
Expand Down
7 changes: 5 additions & 2 deletions src/datasets/domain/useCases/GetDatasetVersionDiff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,19 @@ export class GetDatasetVersionDiff implements UseCase<DatasetVersionDiff> {
* @param {number | string} [datasetId] - The dataset identifier, which can be a string (for persistent identifiers), or a number (for numeric identifiers).
* @param {string } [oldVersionId] - The dataset version identifier, which can be a version-specific numeric string (for example, 1.0) or a DatasetNotNumberedVersion enum value.
* @param {string } [newVersionId] - The dataset version identifier, which can be a version-specific numeric string (for example, 1.0) or a DatasetNotNumberedVersion enum value.
* @param {boolean} [includeDeaccessioned=false] - Indicates if you want to include deaccessioned dataset versions. The default value is false
*/
async execute(
datasetId: number | string,
oldVersionId: string,
newVersionId: string
newVersionId: string,
includeDeaccessioned = false
): Promise<DatasetVersionDiff> {
return await this.datasetsRepository.getDatasetVersionDiff(
datasetId,
oldVersionId,
newVersionId
newVersionId,
includeDeaccessioned
)
}
}
8 changes: 6 additions & 2 deletions src/datasets/infra/repositories/DatasetsRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,15 +149,19 @@ export class DatasetsRepository extends ApiRepository implements IDatasetsReposi
public async getDatasetVersionDiff(
datasetId: string | number,
oldVersionId: string,
newVersionId: string
newVersionId: string,
includeDeaccessioned: boolean
): Promise<DatasetVersionDiff> {
return this.doGet(
this.buildApiEndpoint(
this.datasetsResourceName,
`versions/${oldVersionId}/compare/${newVersionId}`,
datasetId
),
true
true,
{
includeDeaccessioned
}
)
.then((response) => transformDatasetVersionDiffResponseToDatasetVersionDiff(response))
.catch((error) => {
Expand Down
89 changes: 67 additions & 22 deletions test/integration/datasets/DatasetsRepository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,7 @@ describe('DatasetsRepository', () => {
expect(typeof actualDatasetCitation).toBe('string')
})
})

describe('getDatasetVersionDiff', () => {
let testDatasetIds: CreatedDatasetIdentifiers

Expand All @@ -514,7 +515,8 @@ describe('DatasetsRepository', () => {
const actual = await sut.getDatasetVersionDiff(
testDatasetIds.numericId,
'1.0',
DatasetNotNumberedVersion.DRAFT
DatasetNotNumberedVersion.DRAFT,
false
)
expect(actual.metadataChanges?.[0]).not.toBeUndefined()
expect(actual.metadataChanges?.[0].blockName).toEqual('Citation Metadata')
Expand Down Expand Up @@ -549,12 +551,13 @@ describe('DatasetsRepository', () => {
const actual = await sut.getDatasetVersionDiff(
testDatasetIds.numericId,
'1.0',
DatasetNotNumberedVersion.DRAFT
DatasetNotNumberedVersion.DRAFT,
false
)
expect(actual.filesAdded).toEqual(expectedFilesAdded)
})

test('should return diff between :latestPublished and :draft', async () => {
test('should return diff between :latestPublished and :draft', async () => {
const fileMetadata = {
description: 'test description',
directoryLabel: 'directoryLabel',
Expand Down Expand Up @@ -583,11 +586,42 @@ describe('DatasetsRepository', () => {
const actual = await sut.getDatasetVersionDiff(
testDatasetIds.numericId,
DatasetNotNumberedVersion.LATEST_PUBLISHED,
DatasetNotNumberedVersion.DRAFT
DatasetNotNumberedVersion.DRAFT,
false
)
expect(actual.filesAdded).toEqual(expectedFilesAdded)
})

test('should return diff between :latestPublished deaccessioned and :draft when includeDeaccessioned param is true', async () => {
await deaccessionDatasetViaApi(testDatasetIds.numericId, '1.0')

const metadataBlocksRepository = new MetadataBlocksRepository()
const citationMetadataBlock = await metadataBlocksRepository.getMetadataBlockByName(
'citation'
)

await sut.updateDataset(testDatasetIds.numericId, TEST_DIFF_DATASET_DTO, [
citationMetadataBlock
])

const actual = await sut.getDatasetVersionDiff(
testDatasetIds.numericId,
DatasetNotNumberedVersion.LATEST_PUBLISHED,
DatasetNotNumberedVersion.DRAFT,
true
)

expect(actual).not.toBeUndefined()
expect(actual.oldVersion.versionState).toBe('DEACCESSIONED')
expect(actual.oldVersion.versionNumber).toBe('1.0')

expect(actual.newVersion.versionState).toBe('DRAFT')
expect(actual.newVersion.versionNumber).toBe('DRAFT')

expect(actual.metadataChanges?.[0]).not.toBeUndefined()
expect(actual.metadataChanges?.[0].blockName).toEqual('Citation Metadata')
})

afterEach(async () => {
await deletePublishedDatasetViaApi(testDatasetIds.persistentId)
})
Expand Down Expand Up @@ -1245,33 +1279,52 @@ describe('DatasetsRepository', () => {

await deletePublishedDatasetViaApi(testDatasetIds.persistentId)
})

test('should return error when dataset does not exist', async () => {
const expectedError = new ReadError(
`[404] Dataset with ID ${nonExistentTestDatasetId} not found.`
)

await expect(sut.getDatasetVersionsSummaries(nonExistentTestDatasetId)).rejects.toThrow(
expectedError
)
})
})

describe('getDatasetDownloadCount', () => {
test('should return download count for a dataset', async () => {
const testDatasetIds = await createDataset.execute(TestConstants.TEST_NEW_DATASET_DTO)
const testGetDatasetDownloadCountCollectionAlias = 'testGetDatasetDownloadCountCollection'
let testDatasetIds: CreatedDatasetIdentifiers

beforeAll(async () => {
await createCollectionViaApi(testGetDatasetDownloadCountCollectionAlias)
await publishCollectionViaApi(testGetDatasetDownloadCountCollectionAlias)
testDatasetIds = await createDataset.execute(
TestConstants.TEST_NEW_DATASET_DTO,
testGetDatasetDownloadCountCollectionAlias
)

await publishDatasetViaApi(testDatasetIds.numericId)
await waitForNoLocks(testDatasetIds.numericId, 10)
})

afterAll(async () => {
await deletePublishedDatasetViaApi(testDatasetIds.persistentId)
await deleteCollectionViaApi(testGetDatasetDownloadCountCollectionAlias)
})

test('should return download count for a dataset', async () => {
const actual = await sut.getDatasetDownloadCount(testDatasetIds.numericId)

expect(actual.downloadCount).toBe(0)
})

test('should return download count including MDC data', async () => {
const testDatasetIds = await createDataset.execute(TestConstants.TEST_NEW_DATASET_DTO)
await publishDatasetViaApi(testDatasetIds.numericId)
await waitForNoLocks(testDatasetIds.numericId, 10)

const actual = await sut.getDatasetDownloadCount(testDatasetIds.numericId, true)

expect(actual.downloadCount).toBe(0)
})

test('should return download count including MDC data with persistent ID', async () => {
const testDatasetIds = await createDataset.execute(TestConstants.TEST_NEW_DATASET_DTO)
await publishDatasetViaApi(testDatasetIds.numericId)
await waitForNoLocks(testDatasetIds.numericId, 10)

const actual = await sut.getDatasetDownloadCount(testDatasetIds.persistentId, true)

expect(actual.downloadCount).toBe(0)
Expand All @@ -1281,14 +1334,6 @@ describe('DatasetsRepository', () => {
await expect(sut.getDatasetDownloadCount(nonExistentTestDatasetId)).rejects.toBeInstanceOf(
ReadError
)

const expectedError = new ReadError(
`[404] Dataset with ID ${nonExistentTestDatasetId} not found.`
)

await expect(sut.getDatasetVersionsSummaries(nonExistentTestDatasetId)).rejects.toThrow(
expectedError
)
})
})
})
4 changes: 3 additions & 1 deletion test/testHelpers/datasets/datasetVersionDiffHelper.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { DatasetVersionState } from '../../../src'
import {
DatasetVersionDiff,
VersionSummary,
Expand All @@ -11,7 +12,8 @@ import {
export const createDatasetVersionDiff = (): DatasetVersionDiff => {
const versionSummary: VersionSummary = {
versionNumber: '1.0',
lastUpdatedDate: '2023-05-15T08:21:03Z'
lastUpdatedDate: '2023-05-15T08:21:03Z',
versionState: DatasetVersionState.RELEASED
}

const metadataBlockDiff: MetadataBlockDiff = {
Expand Down