Skip to content

Commit 17f5a24

Browse files
committed
test: add functional and integration
1 parent 2715460 commit 17f5a24

File tree

3 files changed

+183
-0
lines changed

3 files changed

+183
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import { ApiConfig, createDataset, linkDataset, WriteError } from '../../../src'
2+
import { DataverseApiAuthMechanism } from '../../../src/core/infra/repositories/ApiConfig'
3+
import {
4+
createCollectionViaApi,
5+
deleteCollectionViaApi
6+
} from '../../testHelpers/collections/collectionHelper'
7+
import { deleteUnpublishedDatasetViaApi } from '../../testHelpers/datasets/datasetHelper'
8+
import { TestConstants } from '../../testHelpers/TestConstants'
9+
10+
describe('execute', () => {
11+
const testCollectionAlias = 'linkDatasetFunctionalTestCollection'
12+
beforeEach(async () => {
13+
ApiConfig.init(
14+
TestConstants.TEST_API_URL,
15+
DataverseApiAuthMechanism.API_KEY,
16+
process.env.TEST_API_KEY
17+
)
18+
})
19+
20+
it('should link a dataset to another collection', async () => {
21+
const createdDatasetIdentifiers = await createDataset.execute(
22+
TestConstants.TEST_NEW_DATASET_DTO
23+
)
24+
await createCollectionViaApi(testCollectionAlias)
25+
26+
const result = await linkDataset.execute(
27+
createdDatasetIdentifiers.numericId,
28+
testCollectionAlias
29+
)
30+
31+
expect(result).toBeUndefined()
32+
33+
await deleteUnpublishedDatasetViaApi(createdDatasetIdentifiers.numericId)
34+
await deleteCollectionViaApi(testCollectionAlias)
35+
})
36+
37+
it('should throw an error when trying to link a dataset to a non-existent collection', async () => {
38+
const createdDatasetIdentifiers = await createDataset.execute(
39+
TestConstants.TEST_NEW_DATASET_DTO
40+
)
41+
const nonExistentCollectionAlias = 'nonExistentCollection'
42+
43+
await expect(
44+
linkDataset.execute(createdDatasetIdentifiers.numericId, nonExistentCollectionAlias)
45+
).rejects.toBeInstanceOf(WriteError)
46+
47+
await deleteUnpublishedDatasetViaApi(createdDatasetIdentifiers.numericId)
48+
})
49+
50+
it('should throw an error when trying to link a dataset that does not exist', async () => {
51+
await createCollectionViaApi(testCollectionAlias)
52+
const nonExistentDatasetId = 'nonExistentDatasetId'
53+
await expect(
54+
linkDataset.execute(nonExistentDatasetId, testCollectionAlias)
55+
).rejects.toBeInstanceOf(WriteError)
56+
57+
await deleteCollectionViaApi(testCollectionAlias)
58+
})
59+
})
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { ApiConfig, createDataset, linkDataset, unlinkDataset, WriteError } from '../../../src'
2+
import { DataverseApiAuthMechanism } from '../../../src/core/infra/repositories/ApiConfig'
3+
import {
4+
createCollectionViaApi,
5+
deleteCollectionViaApi
6+
} from '../../testHelpers/collections/collectionHelper'
7+
import { deleteUnpublishedDatasetViaApi } from '../../testHelpers/datasets/datasetHelper'
8+
import { TestConstants } from '../../testHelpers/TestConstants'
9+
10+
describe('execute', () => {
11+
const testCollectionAlias = 'unlinkDatasetFunctionalTestCollection'
12+
beforeEach(async () => {
13+
ApiConfig.init(
14+
TestConstants.TEST_API_URL,
15+
DataverseApiAuthMechanism.API_KEY,
16+
process.env.TEST_API_KEY
17+
)
18+
})
19+
20+
it('should unlink a dataset from a collection', async () => {
21+
const createdDatasetIdentifiers = await createDataset.execute(
22+
TestConstants.TEST_NEW_DATASET_DTO
23+
)
24+
await createCollectionViaApi(testCollectionAlias)
25+
26+
await linkDataset.execute(createdDatasetIdentifiers.numericId, testCollectionAlias)
27+
28+
const result = await unlinkDataset.execute(
29+
createdDatasetIdentifiers.numericId,
30+
testCollectionAlias
31+
)
32+
33+
expect(result).toBeUndefined()
34+
35+
await deleteUnpublishedDatasetViaApi(createdDatasetIdentifiers.numericId)
36+
await deleteCollectionViaApi(testCollectionAlias)
37+
})
38+
39+
it('should throw error when dataset is not linked to the collection', async () => {
40+
const createdDatasetIdentifiers = await createDataset.execute(
41+
TestConstants.TEST_NEW_DATASET_DTO
42+
)
43+
await createCollectionViaApi(testCollectionAlias)
44+
45+
await expect(
46+
unlinkDataset.execute(createdDatasetIdentifiers.numericId, testCollectionAlias)
47+
).rejects.toBeInstanceOf(WriteError)
48+
49+
await deleteCollectionViaApi(testCollectionAlias)
50+
})
51+
})

test/integration/datasets/DatasetsRepository.test.ts

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1388,4 +1388,77 @@ describe('DatasetsRepository', () => {
13881388
await expect(sut.deleteDatasetDraft(nonExistentTestDatasetId)).rejects.toThrow(expectedError)
13891389
})
13901390
})
1391+
1392+
describe('linkDataset', () => {
1393+
let testDatasetIds: CreatedDatasetIdentifiers
1394+
const testCollectionAlias = 'testLinkDatasetCollection'
1395+
1396+
beforeAll(async () => {
1397+
testDatasetIds = await createDataset.execute(TestConstants.TEST_NEW_DATASET_DTO)
1398+
await createCollectionViaApi(testCollectionAlias)
1399+
})
1400+
1401+
afterAll(async () => {
1402+
await deletePublishedDatasetViaApi(testDatasetIds.persistentId)
1403+
await deleteCollectionViaApi(testCollectionAlias)
1404+
})
1405+
1406+
test('should link a dataset to another collection', async () => {
1407+
const actual = await sut.linkDataset(testDatasetIds.numericId, testCollectionAlias)
1408+
1409+
expect(actual).toBeUndefined()
1410+
1411+
// TODO:ME - Once we get linked dataset collections use case assert that the collection exists
1412+
})
1413+
1414+
test('should return error when dataset does not exist', async () => {
1415+
await expect(sut.linkDataset(nonExistentTestDatasetId, testCollectionAlias)).rejects.toThrow()
1416+
})
1417+
1418+
test('should return error when collection does not exist', async () => {
1419+
await expect(
1420+
sut.linkDataset(testDatasetIds.numericId, 'nonExistentCollectionAlias')
1421+
).rejects.toThrow()
1422+
})
1423+
})
1424+
1425+
describe('unlinkDataset', () => {
1426+
let testDatasetIds: CreatedDatasetIdentifiers
1427+
const testCollectionAlias = 'testUnlinkDatasetCollection'
1428+
1429+
beforeAll(async () => {
1430+
testDatasetIds = await createDataset.execute(TestConstants.TEST_NEW_DATASET_DTO)
1431+
await createCollectionViaApi(testCollectionAlias)
1432+
})
1433+
1434+
afterAll(async () => {
1435+
await deletePublishedDatasetViaApi(testDatasetIds.persistentId)
1436+
await deleteCollectionViaApi(testCollectionAlias)
1437+
})
1438+
1439+
test('should unlink a dataset from a collection', async () => {
1440+
await sut.linkDataset(testDatasetIds.numericId, testCollectionAlias)
1441+
const actual = await sut.unlinkDataset(testDatasetIds.numericId, testCollectionAlias)
1442+
1443+
expect(actual).toBeUndefined()
1444+
1445+
// TODO:ME - Once we get linked dataset collections use case assert that the collection exists
1446+
})
1447+
1448+
test('should return error when dataset does not exist', async () => {
1449+
await expect(sut.linkDataset(nonExistentTestDatasetId, testCollectionAlias)).rejects.toThrow()
1450+
})
1451+
1452+
test('should return error when collection does not exist', async () => {
1453+
await expect(
1454+
sut.linkDataset(testDatasetIds.numericId, 'nonExistentCollectionAlias')
1455+
).rejects.toThrow()
1456+
})
1457+
1458+
test('should return error when dataset is not linked to the collection', async () => {
1459+
await expect(
1460+
sut.unlinkDataset(testDatasetIds.numericId, testCollectionAlias)
1461+
).rejects.toThrow()
1462+
})
1463+
})
13911464
})

0 commit comments

Comments
 (0)