Skip to content

Commit e1b0b81

Browse files
committed
Added: enhanced IT coverage for getCollection and createCollection
1 parent cc27ae2 commit e1b0b81

File tree

3 files changed

+34
-10
lines changed

3 files changed

+34
-10
lines changed

test/environment/.env

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
POSTGRES_VERSION=13
22
DATAVERSE_DB_USER=dataverse
33
SOLR_VERSION=9.3.0
4-
DATAVERSE_IMAGE_REGISTRY=docker.io
5-
DATAVERSE_IMAGE_TAG=unstable
4+
DATAVERSE_IMAGE_REGISTRY=ghcr.io
5+
DATAVERSE_IMAGE_TAG=10633-create-collection-api-ext
66
DATAVERSE_BOOTSTRAP_TIMEOUT=5m

test/integration/collections/CollectionsRepository.test.ts

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ describe('CollectionsRepository', () => {
4141
test('should return the root collection of the Dataverse installation if no parameter is passed AS `root`', async () => {
4242
const actual = await sut.getCollection()
4343
expect(actual.alias).toBe(ROOT_COLLECTION_ALIAS)
44+
expect(actual.id).toBe(1)
45+
expect(actual.name).toBe('Root')
46+
expect(actual.alias).toBe('root')
47+
expect(actual.isReleased).toBe(true)
48+
expect(actual.affiliation).toBe(undefined)
49+
expect(actual.description).toBe('The root dataverse.')
50+
expect(actual.inputLevels).toBe(undefined)
4451
})
4552

4653
test('should return isReleased is true for root collection', async () => {
@@ -97,16 +104,33 @@ describe('CollectionsRepository', () => {
97104
})
98105

99106
test('should create collection in root when no parent collection is set', async () => {
100-
const actual = await sut.createCollection(createCollectionDTO(testCreateCollectionAlias1))
101-
expect(typeof actual).toBe('number')
107+
const newCollectionDTO = createCollectionDTO(testCreateCollectionAlias1)
108+
const actualId = await sut.createCollection(newCollectionDTO)
109+
expect(typeof actualId).toBe('number')
110+
111+
const createdCollection = await sut.getCollection(actualId)
112+
113+
expect(createdCollection.id).toBe(actualId)
114+
expect(createdCollection.alias).toBe(newCollectionDTO.alias)
115+
expect(createdCollection.name).toBe(newCollectionDTO.name)
116+
expect(createdCollection.affiliation).toBe(newCollectionDTO.affiliation)
117+
expect(createdCollection.isPartOf.type).toBe('DATAVERSE')
118+
expect(createdCollection.isPartOf.displayName).toBe('Root')
119+
expect(createdCollection.isPartOf.identifier).toBe('root')
120+
121+
expect(createdCollection.inputLevels?.length).toBe(1)
122+
const inputLevel = createdCollection.inputLevels?.[0]
123+
expect(inputLevel?.datasetFieldName).toBe('geographicCoverage')
124+
expect(inputLevel?.include).toBe(true)
125+
expect(inputLevel?.required).toBe(true)
102126
})
103127

104128
test('should create collection in parent collection when parent collection is set', async () => {
105-
const actual = await sut.createCollection(
129+
const actualId = await sut.createCollection(
106130
createCollectionDTO(testCreateCollectionAlias2),
107131
testCollectionId
108132
)
109-
expect(typeof actual).toBe('number')
133+
expect(typeof actualId).toBe('number')
110134
})
111135

112136
test('should return error when parent collection does not exist', async () => {

test/unit/collections/GetCollectionFacets.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,18 @@ describe('execute', () => {
77
const testFacets = ['test1', 'test2']
88
const collectionRepositoryStub: ICollectionsRepository = {} as ICollectionsRepository
99
collectionRepositoryStub.getCollectionFacets = jest.fn().mockResolvedValue(testFacets)
10-
const testGetCollection = new GetCollectionFacets(collectionRepositoryStub)
10+
const testGetCollectionFacets = new GetCollectionFacets(collectionRepositoryStub)
1111

12-
const actual = await testGetCollection.execute(1)
12+
const actual = await testGetCollectionFacets.execute(1)
1313

1414
expect(actual).toEqual(testFacets)
1515
})
1616

1717
test('should return error result on repository error', async () => {
1818
const collectionRepositoryStub: ICollectionsRepository = {} as ICollectionsRepository
1919
collectionRepositoryStub.getCollectionFacets = jest.fn().mockRejectedValue(new ReadError())
20-
const testGetCollection = new GetCollectionFacets(collectionRepositoryStub)
20+
const testGetCollectionFacets = new GetCollectionFacets(collectionRepositoryStub)
2121

22-
await expect(testGetCollection.execute(1)).rejects.toThrow(ReadError)
22+
await expect(testGetCollectionFacets.execute(1)).rejects.toThrow(ReadError)
2323
})
2424
})

0 commit comments

Comments
 (0)