Skip to content

Commit 1dfb1fa

Browse files
committed
Fixed: using different collections to avoid conflicts in ITs
1 parent 5307e38 commit 1dfb1fa

File tree

7 files changed

+54
-29
lines changed

7 files changed

+54
-29
lines changed

test/integration/collections/CollectionsRepository.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
} from '../../testHelpers/collections/collectionHelper'
1010
import { ROOT_COLLECTION_ALIAS } from '../../../src/collections/domain/models/Collection'
1111

12-
describe.skip('CollectionsRepository', () => {
12+
describe('CollectionsRepository', () => {
1313
const testGetCollection: CollectionsRepository = new CollectionsRepository()
1414

1515
beforeAll(async () => {
@@ -19,7 +19,7 @@ describe.skip('CollectionsRepository', () => {
1919
process.env.TEST_API_KEY
2020
)
2121
try {
22-
await createCollectionViaApi()
22+
await createCollectionViaApi(TestConstants.TEST_CREATED_COLLECTION_ALIAS_2)
2323
} catch (error) {
2424
throw new Error('Tests beforeAll(): Error while creating test collection')
2525
}
@@ -32,7 +32,7 @@ describe.skip('CollectionsRepository', () => {
3232
process.env.TEST_API_KEY
3333
)
3434
try {
35-
await deleteCollectionViaApi()
35+
await deleteCollectionViaApi(TestConstants.TEST_CREATED_COLLECTION_ALIAS_2)
3636
} catch (error) {
3737
throw new Error('Tests afterAll(): Error while deleting test collection')
3838
}
@@ -49,9 +49,9 @@ describe.skip('CollectionsRepository', () => {
4949
describe('by string alias', () => {
5050
test('should return collection when it exists filtering by id AS (alias)', async () => {
5151
const actual = await testGetCollection.getCollection(
52-
TestConstants.TEST_CREATED_COLLECTION_ALIAS
52+
TestConstants.TEST_CREATED_COLLECTION_ALIAS_2
5353
)
54-
expect(actual.alias).toBe(TestConstants.TEST_CREATED_COLLECTION_ALIAS)
54+
expect(actual.alias).toBe(TestConstants.TEST_CREATED_COLLECTION_ALIAS_2)
5555
})
5656

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

test/integration/datasets/DatasetsRepository.test.ts

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ describe('DatasetsRepository', () => {
7272

7373
const createCollection = async () => {
7474
try {
75-
await createCollectionViaApi()
75+
await createCollectionViaApi(TestConstants.TEST_CREATED_COLLECTION_ALIAS_1)
7676
} catch (error) {
7777
throw new Error('Tests beforeAll(): Error while creating test collection')
7878
}
@@ -82,22 +82,25 @@ describe('DatasetsRepository', () => {
8282
try {
8383
firstDatasetIds = await createDataset.execute(
8484
TestConstants.TEST_NEW_DATASET_DTO,
85-
TestConstants.TEST_CREATED_COLLECTION_ALIAS
85+
TestConstants.TEST_CREATED_COLLECTION_ALIAS_1
8686
)
8787
secondDatasetIds = await createDataset.execute(
8888
TestConstants.TEST_NEW_DATASET_DTO,
89-
TestConstants.TEST_CREATED_COLLECTION_ALIAS
89+
TestConstants.TEST_CREATED_COLLECTION_ALIAS_1
9090
)
9191
thirdDatasetIds = await createDataset.execute(
9292
TestConstants.TEST_NEW_DATASET_DTO,
93-
TestConstants.TEST_CREATED_COLLECTION_ALIAS
93+
TestConstants.TEST_CREATED_COLLECTION_ALIAS_1
9494
)
9595
fourthDatasetIds = await createDataset.execute(
9696
TestConstants.TEST_NEW_DATASET_DTO,
97-
TestConstants.TEST_CREATED_COLLECTION_ALIAS
97+
TestConstants.TEST_CREATED_COLLECTION_ALIAS_1
9898
)
9999

100-
await waitForDatasetsIndexedInSolr(expectedTotalDatasetCount)
100+
await waitForDatasetsIndexedInSolr(
101+
expectedTotalDatasetCount,
102+
TestConstants.TEST_CREATED_COLLECTION_ALIAS_1
103+
)
101104
} catch (error) {
102105
throw new Error('Tests beforeAll(): Error while creating test datasets')
103106
}
@@ -116,7 +119,7 @@ describe('DatasetsRepository', () => {
116119

117120
const deleteCollection = async () => {
118121
try {
119-
await deleteCollectionViaApi()
122+
await deleteCollectionViaApi(TestConstants.TEST_CREATED_COLLECTION_ALIAS_1)
120123
} catch (error) {
121124
throw new Error('Tests afterAll(): Error while deleting test collection')
122125
}
@@ -126,7 +129,7 @@ describe('DatasetsRepository', () => {
126129
const actual: DatasetPreviewSubset = await sut.getAllDatasetPreviews(
127130
undefined,
128131
undefined,
129-
TestConstants.TEST_CREATED_COLLECTION_ALIAS
132+
TestConstants.TEST_CREATED_COLLECTION_ALIAS_1
130133
)
131134
expect(actual.datasetPreviews.length).toEqual(expectedTotalDatasetCount)
132135
expect(actual.datasetPreviews[0].persistentId).toMatch(fourthDatasetIds.persistentId)
@@ -137,7 +140,7 @@ describe('DatasetsRepository', () => {
137140
const actual = await sut.getAllDatasetPreviews(
138141
testPageLimit,
139142
0,
140-
TestConstants.TEST_CREATED_COLLECTION_ALIAS
143+
TestConstants.TEST_CREATED_COLLECTION_ALIAS_1
141144
)
142145
expect(actual.datasetPreviews.length).toEqual(1)
143146
expect(actual.datasetPreviews[0].persistentId).toMatch(fourthDatasetIds.persistentId)
@@ -148,7 +151,7 @@ describe('DatasetsRepository', () => {
148151
const actual = await sut.getAllDatasetPreviews(
149152
testPageLimit,
150153
1,
151-
TestConstants.TEST_CREATED_COLLECTION_ALIAS
154+
TestConstants.TEST_CREATED_COLLECTION_ALIAS_1
152155
)
153156
expect(actual.datasetPreviews.length).toEqual(1)
154157
expect(actual.datasetPreviews[0].persistentId).toMatch(thirdDatasetIds.persistentId)
@@ -159,7 +162,7 @@ describe('DatasetsRepository', () => {
159162
const actual = await sut.getAllDatasetPreviews(
160163
testPageLimit,
161164
2,
162-
TestConstants.TEST_CREATED_COLLECTION_ALIAS
165+
TestConstants.TEST_CREATED_COLLECTION_ALIAS_1
163166
)
164167
expect(actual.datasetPreviews.length).toEqual(1)
165168
expect(actual.datasetPreviews[0].persistentId).toMatch(secondDatasetIds.persistentId)
@@ -170,7 +173,7 @@ describe('DatasetsRepository', () => {
170173
const actual = await sut.getAllDatasetPreviews(
171174
testPageLimit,
172175
3,
173-
TestConstants.TEST_CREATED_COLLECTION_ALIAS
176+
TestConstants.TEST_CREATED_COLLECTION_ALIAS_1
174177
)
175178
expect(actual.datasetPreviews.length).toEqual(1)
176179
expect(actual.datasetPreviews[0].persistentId).toMatch(firstDatasetIds.persistentId)

test/testHelpers/TestConstants.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ export class TestConstants {
4747
}
4848
static readonly TEST_DUMMY_COLLECTION_ID = 10001
4949
static readonly TEST_DUMMY_COLLECTION_ALIAS = 'dummyCollectionId'
50-
static readonly TEST_CREATED_COLLECTION_ALIAS = 'testCollection'
50+
static readonly TEST_CREATED_COLLECTION_ALIAS_1 = 'testCollection1'
51+
static readonly TEST_CREATED_COLLECTION_ALIAS_2 = 'testCollection2'
5152
static readonly TEST_NEW_DATASET_DTO: NewDatasetDTO = {
5253
license: {
5354
name: 'CC0 1.0',

test/testHelpers/collections/collectionHelper.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import { DvObjectType } from '../../../src'
33
import { CollectionPayload } from '../../../src/collections/infra/repositories/transformers/CollectionPayload'
44
import { TestConstants } from '../TestConstants'
55
import axios from 'axios'
6-
import collectionJson from './test-collection-1.json'
6+
import collectionJson1 from './test-collection-1.json'
7+
import collectionJson2 from './test-collection-2.json'
78

89
const COLLECTION_ID = 11111
910
const COLLECTION_ALIAS_STR = 'secondCollection'
@@ -39,17 +40,19 @@ export const createCollectionPayload = (): CollectionPayload => {
3940
return collectionPayload
4041
}
4142

42-
export async function createCollectionViaApi(): Promise<void> {
43+
export async function createCollectionViaApi(collectionAlias: string): Promise<void> {
4344
return await axios.post(
4445
`${TestConstants.TEST_API_URL}/dataverses/root`,
45-
collectionJson,
46+
collectionAlias == TestConstants.TEST_CREATED_COLLECTION_ALIAS_1
47+
? collectionJson1
48+
: collectionJson2,
4649
DATAVERSE_API_REQUEST_HEADERS
4750
)
4851
}
4952

50-
export async function deleteCollectionViaApi(): Promise<void> {
53+
export async function deleteCollectionViaApi(collectionAlias: string): Promise<void> {
5154
return await axios.delete(
52-
`${TestConstants.TEST_API_URL}/dataverses/${TestConstants.TEST_CREATED_COLLECTION_ALIAS}`,
55+
`${TestConstants.TEST_API_URL}/dataverses/${collectionAlias}`,
5356
DATAVERSE_API_REQUEST_HEADERS
5457
)
5558
}

test/testHelpers/collections/test-collection-1.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"id": 4,
3-
"alias": "testCollection",
2+
"id": 100,
3+
"alias": "testCollection1",
44
"name": "Scientific Research",
55
"dataverseContacts": [
66
{
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"id": 101,
3+
"alias": "testCollection2",
4+
"name": "Scientific Research",
5+
"dataverseContacts": [
6+
{
7+
"contactEmail": "[email protected]"
8+
},
9+
{
10+
"contactEmail": "[email protected]"
11+
}
12+
],
13+
"affiliation": "Scientific Research University",
14+
"description": "We do all the science.",
15+
"dataverseType": "LABORATORY"
16+
}

test/testHelpers/datasets/datasetHelper.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -289,14 +289,17 @@ export const waitForNoLocks = async (
289289
}
290290

291291
export async function waitForDatasetsIndexedInSolr(
292-
expectedNumberOfIndexedDatasets: number
292+
expectedNumberOfIndexedDatasets: number,
293+
collectionAlias: string
293294
): Promise<void> {
294-
console.log('Waiting for datasets indexing in Solr...')
295295
let datasetsIndexed = false
296296
let retry = 0
297297
while (!datasetsIndexed && retry < 10) {
298298
await axios
299-
.get(`${TestConstants.TEST_API_URL}/search?q=*&type=dataset`, DATAVERSE_API_REQUEST_HEADERS)
299+
.get(
300+
`${TestConstants.TEST_API_URL}/search?q=*&type=dataset&subtree=${collectionAlias}`,
301+
DATAVERSE_API_REQUEST_HEADERS
302+
)
300303
.then((response) => {
301304
const nDatasets = response.data.data.items.length
302305
if (nDatasets === expectedNumberOfIndexedDatasets) {
@@ -316,5 +319,4 @@ export async function waitForDatasetsIndexedInSolr(
316319
if (!datasetsIndexed) {
317320
throw new Error('Tests setup: Timeout reached while waiting for datasets indexing in Solr')
318321
}
319-
console.log('Datasets indexed in Solr')
320322
}

0 commit comments

Comments
 (0)