diff --git a/src/dataset/infrastructure/repositories/DatasetJSDataverseRepository.ts b/src/dataset/infrastructure/repositories/DatasetJSDataverseRepository.ts index 239724296..143f75307 100644 --- a/src/dataset/infrastructure/repositories/DatasetJSDataverseRepository.ts +++ b/src/dataset/infrastructure/repositories/DatasetJSDataverseRepository.ts @@ -13,6 +13,8 @@ import { } from '@iqss/dataverse-client-javascript' import { JSDatasetMapper } from '../mappers/JSDatasetMapper' +const includeDeaccessioned = true + export class DatasetJSDataverseRepository implements DatasetRepository { getByPersistentId( persistentId: string, @@ -20,7 +22,7 @@ export class DatasetJSDataverseRepository implements DatasetRepository { requestedVersion?: string ): Promise { return getDataset - .execute(persistentId, this.versionToVersionId(version)) + .execute(persistentId, this.versionToVersionId(version), includeDeaccessioned) .then((jsDataset) => Promise.all([ jsDataset, diff --git a/tests/e2e-integration/e2e/sections/dataset/Dataset.spec.tsx b/tests/e2e-integration/e2e/sections/dataset/Dataset.spec.tsx index bcaa94aad..02aa926b9 100644 --- a/tests/e2e-integration/e2e/sections/dataset/Dataset.spec.tsx +++ b/tests/e2e-integration/e2e/sections/dataset/Dataset.spec.tsx @@ -1,6 +1,6 @@ import { DatasetLabelValue } from '../../../../../src/dataset/domain/models/Dataset' import { TestsUtils } from '../../../shared/TestsUtils' -import { DatasetHelper } from '../../../shared/datasets/DatasetHelper' +import { DatasetHelper, DatasetResponse } from '../../../shared/datasets/DatasetHelper' import { FileHelper } from '../../../shared/files/FileHelper' import moment from 'moment-timezone' @@ -128,7 +128,20 @@ describe('Dataset', () => { }) it.skip('successfully loads a dataset deaccessioned', () => { - // TODO - Add test when deaccessioned endpoint works + // TODO - Implement once the getDatasetCitation includes deaccessioned datasets + cy.wrap(DatasetHelper.create()) + // eslint-disable-next-line @typescript-eslint/no-unsafe-argument + .then((dataset) => Promise.all([dataset, DatasetHelper.publish(dataset.persistentId)])) + .then(([dataset]: [DatasetResponse]) => { + return cy + .wait(2500) + .then(() => Promise.all([dataset, DatasetHelper.deaccession(dataset.id)])) + }) + .then(([dataset]: [DatasetResponse]) => { + cy.visit(`/spa/datasets?persistentId=${dataset.persistentId}`) + + cy.findByText(DatasetLabelValue.DEACCESSIONED).should('exist') + }) }) }) diff --git a/tests/e2e-integration/integration/datasets/DatasetJSDataverseRepository.spec.ts b/tests/e2e-integration/integration/datasets/DatasetJSDataverseRepository.spec.ts index 4c9d47929..a95036bcd 100644 --- a/tests/e2e-integration/integration/datasets/DatasetJSDataverseRepository.spec.ts +++ b/tests/e2e-integration/integration/datasets/DatasetJSDataverseRepository.spec.ts @@ -196,6 +196,23 @@ describe('Dataset JSDataverse Repository', () => { }) }) + it.skip('gets the dataset by persistentId when the dataset is deaccessioned', async () => { + // TODO - Implement once the getDatasetCitation includes deaccessioned datasets + const datasetResponse = await DatasetHelper.create() + + await DatasetHelper.publish(datasetResponse.persistentId) + await TestsUtils.wait(1500) + + await DatasetHelper.deaccession(datasetResponse.id) + await datasetRepository.getByPersistentId(datasetResponse.persistentId).then((dataset) => { + if (!dataset) { + throw new Error('Dataset not found') + } + const datasetExpected = datasetData(dataset.persistentId, dataset.version.id) + + expect(dataset.getTitle()).to.deep.equal(datasetExpected.title) + }) + }) it('gets the dataset by persistentId when is locked', async () => { const datasetResponse = await DatasetHelper.create() await DatasetHelper.lock(datasetResponse.id, DatasetLockReason.FINALIZE_PUBLICATION) diff --git a/tests/e2e-integration/integration/files/FileJSDataverseRepository.spec.ts b/tests/e2e-integration/integration/files/FileJSDataverseRepository.spec.ts index 09c7de97c..391511a94 100644 --- a/tests/e2e-integration/integration/files/FileJSDataverseRepository.spec.ts +++ b/tests/e2e-integration/integration/files/FileJSDataverseRepository.spec.ts @@ -157,18 +157,15 @@ describe('File JSDataverse Repository', () => { }) it('gets all the files by dataset persistentId after dataset deaccession', async () => { - const dataset = await DatasetHelper.createWithFiles(FileHelper.createMany(3)).then( - (datasetResponse) => datasetRepository.getByPersistentId(datasetResponse.persistentId) - ) - if (!dataset) throw new Error('Dataset not found') + const datasetResponse = await DatasetHelper.createWithFiles(FileHelper.createMany(3)) - await DatasetHelper.publish(dataset.persistentId) - await TestsUtils.waitForNoLocks(dataset.persistentId) // Wait for the dataset to be published + await DatasetHelper.publish(datasetResponse.persistentId) + await TestsUtils.waitForNoLocks(datasetResponse.persistentId) // Wait for the dataset to be published + + const dataset = await datasetRepository.getByPersistentId(datasetResponse.persistentId) + if (!dataset) throw new Error('Dataset not found') - DatasetHelper.deaccession(dataset.persistentId) - await TestsUtils.wait(1500) // Wait for the dataset to be deaccessioned - await TestsUtils.wait(1500) // Wait for the dataset to be deaccessioned - await TestsUtils.wait(1500) // Wait for the dataset to be deaccessioned + await DatasetHelper.deaccession(datasetResponse.id) await fileRepository .getAllByDatasetPersistentId( diff --git a/tests/e2e-integration/shared/datasets/DatasetHelper.ts b/tests/e2e-integration/shared/datasets/DatasetHelper.ts index 962dfa4d5..e46519395 100644 --- a/tests/e2e-integration/shared/datasets/DatasetHelper.ts +++ b/tests/e2e-integration/shared/datasets/DatasetHelper.ts @@ -40,23 +40,14 @@ export class DatasetHelper extends DataverseApiHelper { return { ...response, persistentId } } - static deaccession(persistentId: string) { - return cy - .visit(`/dataset.xhtml?persistentId=${persistentId}`) - .get('#editDataSet') - .click() - .get('#datasetForm\\:deaccessionDatasetLink') - .click() - .get('#datasetForm\\:reasonOptions_label') - .click() - .get('#datasetForm\\:reasonOptions_2') - .click() - .get('#datasetForm\\:reasonForDeaccession') - .type('Test deaccession') - .get('#datasetForm\\:j_idt2181') - .click() - .get('#datasetForm\\:deaccessionConfirmation_content > div > input') - .click() + static deaccession(id: string) { + return this.request<{ status: string }>( + `/datasets/${id}/versions/:latest-published/deaccession`, + 'POST', + { + deaccessionReason: 'Description of the deaccession reason.' + } + ) } static async createPrivateUrl(id: string): Promise<{