From efd66ebf0d1cb91060f2926e9976c3f7f15fa772 Mon Sep 17 00:00:00 2001 From: MellyGray Date: Tue, 7 Nov 2023 13:00:57 +0100 Subject: [PATCH 1/3] feat(IntegrationDatasetDeaccessioned): add integration and e2e tests --- .../e2e/sections/dataset/Dataset.spec.tsx | 18 ++++++++++--- .../DatasetJSDataverseRepository.spec.ts | 18 +++++++++++++ .../files/FileJSDataverseRepository.spec.ts | 14 ++++------- .../shared/datasets/DatasetHelper.ts | 25 ++++++------------- 4 files changed, 46 insertions(+), 29 deletions(-) diff --git a/tests/e2e-integration/e2e/sections/dataset/Dataset.spec.tsx b/tests/e2e-integration/e2e/sections/dataset/Dataset.spec.tsx index ef743d439..250115899 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' type Dataset = { @@ -126,8 +126,20 @@ describe('Dataset', () => { }) }) - it.skip('successfully loads a dataset deaccessioned', () => { - // TODO - Add test when deaccessioned endpoint works + it('successfully loads a dataset deaccessioned', () => { + 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 65f01dbfc..6197249a0 100644 --- a/tests/e2e-integration/integration/datasets/DatasetJSDataverseRepository.spec.ts +++ b/tests/e2e-integration/integration/datasets/DatasetJSDataverseRepository.spec.ts @@ -194,4 +194,22 @@ describe('Dataset JSDataverse Repository', () => { expect(dataset.metadataBlocks[0].fields.citationDate).not.to.exist }) }) + + it('gets the dataset by persistentId when the dataset is deaccessioned', async () => { + 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) + }) + }) }) diff --git a/tests/e2e-integration/integration/files/FileJSDataverseRepository.spec.ts b/tests/e2e-integration/integration/files/FileJSDataverseRepository.spec.ts index d08c7bbd4..2d2432b8d 100644 --- a/tests/e2e-integration/integration/files/FileJSDataverseRepository.spec.ts +++ b/tests/e2e-integration/integration/files/FileJSDataverseRepository.spec.ts @@ -157,19 +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 DatasetHelper.publish(datasetResponse.persistentId) await TestsUtils.wait(1500) // Wait for the dataset to be published - 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) + const dataset = await datasetRepository.getByPersistentId(datasetResponse.persistentId) + if (!dataset) throw new Error('Dataset not found') await fileRepository .getAllByDatasetPersistentId( dataset.persistentId, diff --git a/tests/e2e-integration/shared/datasets/DatasetHelper.ts b/tests/e2e-integration/shared/datasets/DatasetHelper.ts index 32143ec12..884eb35c5 100644 --- a/tests/e2e-integration/shared/datasets/DatasetHelper.ts +++ b/tests/e2e-integration/shared/datasets/DatasetHelper.ts @@ -26,23 +26,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<{ token: string }> { From 56dee767a0bf56ca9bc29d6788d3ffe2b8bcdabb Mon Sep 17 00:00:00 2001 From: MellyGray Date: Tue, 7 Nov 2023 13:45:49 +0100 Subject: [PATCH 2/3] feat(IntegrationDatasetDeaccessioned): integrate with js-dataverse --- .../repositories/DatasetJSDataverseRepository.ts | 4 +++- tests/e2e-integration/e2e/sections/dataset/Dataset.spec.tsx | 3 ++- .../datasets/DatasetJSDataverseRepository.spec.ts | 3 ++- .../integration/files/FileJSDataverseRepository.spec.ts | 5 +++-- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/dataset/infrastructure/repositories/DatasetJSDataverseRepository.ts b/src/dataset/infrastructure/repositories/DatasetJSDataverseRepository.ts index c3fc7fbf0..c618e9e62 100644 --- a/src/dataset/infrastructure/repositories/DatasetJSDataverseRepository.ts +++ b/src/dataset/infrastructure/repositories/DatasetJSDataverseRepository.ts @@ -11,6 +11,8 @@ import { } from '@iqss/dataverse-client-javascript' import { JSDatasetMapper } from '../mappers/JSDatasetMapper' +const includeDeaccessioned = true + export class DatasetJSDataverseRepository implements DatasetRepository { getByPersistentId( persistentId: string, @@ -18,7 +20,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 250115899..c5aa1246e 100644 --- a/tests/e2e-integration/e2e/sections/dataset/Dataset.spec.tsx +++ b/tests/e2e-integration/e2e/sections/dataset/Dataset.spec.tsx @@ -126,7 +126,8 @@ describe('Dataset', () => { }) }) - it('successfully loads a dataset deaccessioned', () => { + it.skip('successfully loads a dataset deaccessioned', () => { + // 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)])) diff --git a/tests/e2e-integration/integration/datasets/DatasetJSDataverseRepository.spec.ts b/tests/e2e-integration/integration/datasets/DatasetJSDataverseRepository.spec.ts index 6197249a0..3e81c1987 100644 --- a/tests/e2e-integration/integration/datasets/DatasetJSDataverseRepository.spec.ts +++ b/tests/e2e-integration/integration/datasets/DatasetJSDataverseRepository.spec.ts @@ -195,7 +195,8 @@ describe('Dataset JSDataverse Repository', () => { }) }) - it('gets the dataset by persistentId when the dataset is deaccessioned', async () => { + 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) diff --git a/tests/e2e-integration/integration/files/FileJSDataverseRepository.spec.ts b/tests/e2e-integration/integration/files/FileJSDataverseRepository.spec.ts index 2d2432b8d..0b1541c96 100644 --- a/tests/e2e-integration/integration/files/FileJSDataverseRepository.spec.ts +++ b/tests/e2e-integration/integration/files/FileJSDataverseRepository.spec.ts @@ -162,10 +162,11 @@ describe('File JSDataverse Repository', () => { await DatasetHelper.publish(datasetResponse.persistentId) await TestsUtils.wait(1500) // Wait for the dataset to be published - await DatasetHelper.deaccession(datasetResponse.id) - const dataset = await datasetRepository.getByPersistentId(datasetResponse.persistentId) if (!dataset) throw new Error('Dataset not found') + + await DatasetHelper.deaccession(datasetResponse.id) + await fileRepository .getAllByDatasetPersistentId( dataset.persistentId, From dea4da377dfa98272cdce128e3b08aea1e7de089 Mon Sep 17 00:00:00 2001 From: MellyGray Date: Wed, 8 Nov 2023 11:29:13 +0100 Subject: [PATCH 3/3] fix: update js-dataverse version --- package-lock.json | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index 9cab908e7..fc6cbabbd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "0.1.0", "dependencies": { "@faker-js/faker": "7.6.0", - "@iqss/dataverse-client-javascript": "2.0.0-pr97.418bf5e", + "@iqss/dataverse-client-javascript": "2.0.0-pr98.a8f9bb5", "@iqss/dataverse-design-system": "*", "@istanbuljs/nyc-config-typescript": "1.0.2", "@tanstack/react-table": "8.9.2", @@ -3588,9 +3588,9 @@ }, "node_modules/@iqss/dataverse-client-javascript": { "name": "@IQSS/dataverse-client-javascript", - "version": "2.0.0-pr97.418bf5e", - "resolved": "https://npm.pkg.github.com/download/@IQSS/dataverse-client-javascript/2.0.0-pr97.418bf5e/0d604232d6f567b41328143c2d5d27513d069380", - "integrity": "sha512-wKRR1ORFkFSoFoCrWsCQvcm1vExIIrVN3pJbIl9Nk8lopP7zkUEB1xcAU+UVShbGktIZIa20TQMFl0ONafDiZw==", + "version": "2.0.0-pr98.a8f9bb5", + "resolved": "https://npm.pkg.github.com/download/@IQSS/dataverse-client-javascript/2.0.0-pr98.a8f9bb5/c718d908cbe5acb5671950546b7359483de0c2a7", + "integrity": "sha512-Fzchvc5p2ibOYiK8w9Zebh8/rrkin8D026UzJHzR/Zzl1RRBWpMtbCDLXQlUDgoLMHj7oR5AJ8VwVfyk4wZZsQ==", "license": "MIT", "dependencies": { "@types/node": "^18.15.11", diff --git a/package.json b/package.json index 0c61160a5..34440fafa 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ }, "dependencies": { "@faker-js/faker": "7.6.0", - "@iqss/dataverse-client-javascript": "2.0.0-pr97.418bf5e", + "@iqss/dataverse-client-javascript": "2.0.0-pr98.a8f9bb5", "@iqss/dataverse-design-system": "*", "@istanbuljs/nyc-config-typescript": "1.0.2", "@tanstack/react-table": "8.9.2",