Skip to content

Commit

Permalink
Added: integration tests and tweaks to GetDatasetLocks
Browse files Browse the repository at this point in the history
  • Loading branch information
GPortas committed Oct 19, 2023
1 parent f3d810a commit a2dc047
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/datasets/domain/models/DatasetLock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export interface DatasetLock {
lockType: DatasetLockType;
date?: string;
userId: string;
datasetId: string;
datasetPersistentId: string;
message?: string;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const transformDatasetLockPayloadToDatasetLock = (datasetLockPayload: any): Data
lockType: datasetLockPayload.lockType as DatasetLockType,
...(datasetLockPayload.date && { date: datasetLockPayload.date }),
userId: datasetLockPayload.user,
datasetId: datasetLockPayload.dataset,
datasetPersistentId: datasetLockPayload.dataset,
...(datasetLockPayload.message && { message: datasetLockPayload.message }),
};
};
44 changes: 41 additions & 3 deletions test/integration/datasets/DatasetsRepository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ import { DatasetsRepository } from '../../../src/datasets/infra/repositories/Dat
import { assert } from 'sinon';
import { ApiConfig, DataverseApiAuthMechanism } from '../../../src/core/infra/repositories/ApiConfig';
import { TestConstants } from '../../testHelpers/TestConstants';
import { createDatasetViaApi, createPrivateUrlViaApi } from '../../testHelpers/datasets/datasetHelper';
import {
createDatasetViaApi,
createPrivateUrlViaApi,
publishDatasetViaApi,
} from '../../testHelpers/datasets/datasetHelper';
import { ReadError } from '../../../src/core/domain/repositories/ReadError';
import { DatasetNotNumberedVersion } from '../../../src/datasets';
import { DatasetNotNumberedVersion, DatasetLockType } from '../../../src/datasets';

describe('DatasetsRepository', () => {
const sut: DatasetsRepository = new DatasetsRepository();
Expand Down Expand Up @@ -150,7 +154,7 @@ describe('DatasetsRepository', () => {
assert.match(actual.canDeleteDatasetDraft, true);
});

test('should return error when file does not exist', async () => {
test('should return error when dataset does not exist', async () => {
let error: ReadError = undefined;

await sut.getDatasetUserPermissions(nonExistentTestDatasetId).catch((e) => (error = e));
Expand All @@ -161,5 +165,39 @@ describe('DatasetsRepository', () => {
);
});
});

describe('getDatasetLocks', () => {
test('should return list of dataset locks by dataset id for a dataset while publishing', async () => {
// We create a new dataset
await createDatasetViaApi()
.then()
.catch(() => {
assert.fail('Error while creating test Dataset');
});
const createdDatasetId = 3;
// We publish the new test dataset so it will create a lock during publishing
await publishDatasetViaApi(createdDatasetId)
.then()
.catch(() => {
assert.fail('Error while publishing test Dataset');
});
const actual = await sut.getDatasetLocks(createdDatasetId);
assert.match(actual.length, 1);
assert.match(actual[0].lockType, DatasetLockType.FINALIZE_PUBLICATION);
assert.match(actual[0].userId, 'dataverseAdmin');
assert.match(actual[0].message, 'Publishing the dataset; Validating Datafiles Asynchronously');
});

test('should return error when dataset does not exist', async () => {
let error: ReadError = undefined;

await sut.getDatasetLocks(nonExistentTestDatasetId).catch((e) => (error = e));

assert.match(
error.message,
`There was an error when reading the resource. Reason was: [404] Dataset with ID ${nonExistentTestDatasetId} not found.`,
);
});
});
});
});
8 changes: 8 additions & 0 deletions test/testHelpers/datasets/datasetHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,14 @@ export const createDatasetViaApi = async (): Promise<AxiosResponse> => {
);
};

export const publishDatasetViaApi = async (datasetId: number): Promise<AxiosResponse> => {
return await axios.post(
`${TestConstants.TEST_API_URL}/datasets/${datasetId}/actions/:publish?type=major`,
{},
DATAVERSE_API_REQUEST_HEADERS,
);
};

export const createPrivateUrlViaApi = async (datasetId: number): Promise<AxiosResponse> => {
return await axios.post(
`${TestConstants.TEST_API_URL}/datasets/${datasetId}/privateUrl`,
Expand Down
4 changes: 2 additions & 2 deletions test/testHelpers/datasets/datasetLockHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export const createDatasetLockModel = (): DatasetLock => {
lockType: DatasetLockType.EDIT_IN_PROGRESS,
date: '2023-05-15T08:21:03Z',
userId: '1',
datasetId: '2',
datasetPersistentId: 'doi:10.5072/FK2/QYOVTJ',
message: 'Test.',
};
};
Expand All @@ -15,7 +15,7 @@ export const createDatasetLockPayload = (): any => {
lockType: DatasetLockType.EDIT_IN_PROGRESS.toString(),
date: '2023-05-15T08:21:03Z',
user: '1',
dataset: '2',
dataset: 'doi:10.5072/FK2/QYOVTJ',
message: 'Test.',
};
};
5 changes: 5 additions & 0 deletions test/testHelpers/datasets/test-dataset.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{
"datasetVersion": {
"license": {
"name": "CC0 1.0",
"uri": "http://creativecommons.org/publicdomain/zero/1.0",
"iconUri": "https://licensebuttons.net/p/zero/1.0/88x31.png"
},
"metadataBlocks": {
"citation": {
"fields": [
Expand Down

0 comments on commit a2dc047

Please sign in to comment.