Skip to content

Commit 0d85969

Browse files
committed
test: add tests
1 parent 2434086 commit 0d85969

File tree

3 files changed

+106
-4
lines changed

3 files changed

+106
-4
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import {
2+
ApiConfig,
3+
createDataset,
4+
getDatasetLinkedCollections,
5+
linkDataset,
6+
WriteError
7+
} from '../../../src'
8+
import { DataverseApiAuthMechanism } from '../../../src/core/infra/repositories/ApiConfig'
9+
import {
10+
createCollectionViaApi,
11+
deleteCollectionViaApi
12+
} from '../../testHelpers/collections/collectionHelper'
13+
import { deleteUnpublishedDatasetViaApi } from '../../testHelpers/datasets/datasetHelper'
14+
import { TestConstants } from '../../testHelpers/TestConstants'
15+
16+
describe('execute', () => {
17+
const testCollectionAlias = 'getDatasetLinkedCollectionsFunctionalTestCollection'
18+
beforeEach(async () => {
19+
ApiConfig.init(
20+
TestConstants.TEST_API_URL,
21+
DataverseApiAuthMechanism.API_KEY,
22+
process.env.TEST_API_KEY
23+
)
24+
})
25+
26+
it('should return empty array when no collections are linked', async () => {
27+
const createdDatasetIdentifiers = await createDataset.execute(
28+
TestConstants.TEST_NEW_DATASET_DTO
29+
)
30+
const linkedCollections = await getDatasetLinkedCollections.execute(
31+
createdDatasetIdentifiers.numericId
32+
)
33+
expect(linkedCollections.length).toBe(0)
34+
await deleteUnpublishedDatasetViaApi(createdDatasetIdentifiers.numericId)
35+
})
36+
37+
it('should return linked collections for a dataset', async () => {
38+
const createdDatasetIdentifiers = await createDataset.execute(
39+
TestConstants.TEST_NEW_DATASET_DTO
40+
)
41+
await createCollectionViaApi(testCollectionAlias)
42+
43+
await linkDataset.execute(createdDatasetIdentifiers.numericId, testCollectionAlias)
44+
45+
const linkedCollections = await getDatasetLinkedCollections.execute(
46+
createdDatasetIdentifiers.numericId
47+
)
48+
expect(linkedCollections.length).toBe(1)
49+
expect(linkedCollections[0].alias).toBe(testCollectionAlias)
50+
51+
await deleteUnpublishedDatasetViaApi(createdDatasetIdentifiers.numericId)
52+
await deleteCollectionViaApi(testCollectionAlias)
53+
})
54+
55+
it('should return error when dataset does not exist', async () => {
56+
const nonExistentDatasetId = 99999
57+
58+
await expect(getDatasetLinkedCollections.execute(nonExistentDatasetId)).rejects.toBeInstanceOf(
59+
WriteError
60+
)
61+
})
62+
})

test/functional/datasets/LinkDataset.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ describe('execute', () => {
4949

5050
it('should throw an error when trying to link a dataset that does not exist', async () => {
5151
await createCollectionViaApi(testCollectionAlias)
52-
const nonExistentDatasetId = 'nonExistentDatasetId'
52+
const nonExistentDatasetId = 999999
5353
await expect(
5454
linkDataset.execute(nonExistentDatasetId, testCollectionAlias)
5555
).rejects.toBeInstanceOf(WriteError)

test/integration/datasets/DatasetsRepository.test.ts

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1408,7 +1408,8 @@ describe('DatasetsRepository', () => {
14081408

14091409
expect(actual).toBeUndefined()
14101410

1411-
// TODO:ME - Once we get linked dataset collections use case assert that the collection exists
1411+
const linkedCollections = await sut.getDatasetLinkedCollections(testDatasetIds.numericId)
1412+
expect(linkedCollections[0].alias).toBe(testCollectionAlias)
14121413
})
14131414

14141415
test('should return error when dataset does not exist', async () => {
@@ -1438,11 +1439,16 @@ describe('DatasetsRepository', () => {
14381439

14391440
test('should unlink a dataset from a collection', async () => {
14401441
await sut.linkDataset(testDatasetIds.numericId, testCollectionAlias)
1442+
const linkedCollections = await sut.getDatasetLinkedCollections(testDatasetIds.numericId)
1443+
expect(linkedCollections[0].alias).toBe(testCollectionAlias)
1444+
14411445
const actual = await sut.unlinkDataset(testDatasetIds.numericId, testCollectionAlias)
14421446

14431447
expect(actual).toBeUndefined()
1444-
1445-
// TODO:ME - Once we get linked dataset collections use case assert that the collection exists
1448+
const updatedLinkedCollections = await sut.getDatasetLinkedCollections(
1449+
testDatasetIds.numericId
1450+
)
1451+
expect(updatedLinkedCollections.length).toBe(0)
14461452
})
14471453

14481454
test('should return error when dataset does not exist', async () => {
@@ -1461,4 +1467,38 @@ describe('DatasetsRepository', () => {
14611467
).rejects.toThrow()
14621468
})
14631469
})
1470+
1471+
describe('getDatasetLinkedCollections', () => {
1472+
let testDatasetIds: CreatedDatasetIdentifiers
1473+
const testCollectionAlias = 'testGetLinkedCollections'
1474+
1475+
beforeAll(async () => {
1476+
testDatasetIds = await createDataset.execute(TestConstants.TEST_NEW_DATASET_DTO)
1477+
await createCollectionViaApi(testCollectionAlias)
1478+
})
1479+
1480+
afterAll(async () => {
1481+
await deletePublishedDatasetViaApi(testDatasetIds.persistentId)
1482+
await deleteCollectionViaApi(testCollectionAlias)
1483+
})
1484+
1485+
test('should return empty array when no collections are linked', async () => {
1486+
const linkedCollections = await sut.getDatasetLinkedCollections(testDatasetIds.numericId)
1487+
1488+
expect(linkedCollections.length).toBe(0)
1489+
})
1490+
1491+
test('should return linked collections for a dataset', async () => {
1492+
await sut.linkDataset(testDatasetIds.numericId, testCollectionAlias)
1493+
1494+
const linkedCollections = await sut.getDatasetLinkedCollections(testDatasetIds.numericId)
1495+
1496+
expect(linkedCollections.length).toBe(1)
1497+
expect(linkedCollections[0].alias).toBe(testCollectionAlias)
1498+
})
1499+
1500+
test('should return error when dataset does not exist', async () => {
1501+
await expect(sut.getDatasetLinkedCollections(nonExistentTestDatasetId)).rejects.toThrow()
1502+
})
1503+
})
14641504
})

0 commit comments

Comments
 (0)