Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

207 - Integration get deaccessioned dataset #225

Merged
merged 4 commits into from
Dec 11, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,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 @@ -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')
})
})
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
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