Skip to content

Commit

Permalink
Merge pull request IQSS#225 from IQSS/feature/207-integration-get-dea…
Browse files Browse the repository at this point in the history
…ccessioned-dataset

207 - Integration get deaccessioned dataset
  • Loading branch information
GPortas authored Dec 11, 2023
2 parents 8f81247 + 958d720 commit aeaf84b
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@ import {
} from '@iqss/dataverse-client-javascript'
import { JSDatasetMapper } from '../mappers/JSDatasetMapper'

const includeDeaccessioned = true

export class DatasetJSDataverseRepository implements DatasetRepository {
getByPersistentId(
persistentId: string,
version?: string,
requestedVersion?: string
): Promise<Dataset | undefined> {
return getDataset
.execute(persistentId, this.versionToVersionId(version))
.execute(persistentId, this.versionToVersionId(version), includeDeaccessioned)
.then((jsDataset) =>
Promise.all([
jsDataset,
Expand Down
17 changes: 15 additions & 2 deletions tests/e2e-integration/e2e/sections/dataset/Dataset.spec.tsx
Original file line number Diff line number Diff line change
@@ -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'

Expand Down Expand Up @@ -156,7 +156,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')
})
})
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
25 changes: 8 additions & 17 deletions tests/e2e-integration/shared/datasets/DatasetHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<{
Expand Down

0 comments on commit aeaf84b

Please sign in to comment.