@@ -2,14 +2,7 @@ import * as fs from 'fs'
22import { DockerComposeEnvironment , Wait } from 'testcontainers'
33import axios from 'axios'
44import { TestConstants } from '../testHelpers/TestConstants'
5- import datasetJson1 from '../testHelpers/datasets/test-dataset-1.json'
6- import datasetJson2 from '../testHelpers/datasets/test-dataset-2.json'
7- import datasetJson3 from '../testHelpers/datasets/test-dataset-3.json'
8- import datasetJson4 from '../testHelpers/datasets/test-dataset-4.json'
9- import collectionJson from '../testHelpers/collections/test-collection-1.json'
10- import { ROOT_COLLECTION_ALIAS } from '../../src/collections/domain/models/Collection'
115
12- const NUMBER_OF_DATASETS = 4
136const COMPOSE_FILE = 'docker-compose.yml'
147
158const CONTAINER_DATAVERSE_BOOTSTRAP_NAME = 'test_dataverse_bootstrap'
@@ -24,7 +17,6 @@ const API_KEY_USER_PASSWORD = 'admin1'
2417export default async function setupTestEnvironment ( ) : Promise < void > {
2518 await setupContainers ( )
2619 await setupApiKey ( )
27- await setupTestFixtures ( )
2820}
2921
3022async function setupContainers ( ) : Promise < void > {
@@ -54,88 +46,3 @@ async function setupApiKey(): Promise<void> {
5446 } )
5547 console . log ( 'API key obtained' )
5648}
57-
58- async function setupTestFixtures ( ) : Promise < void > {
59- console . log ( 'Creating test datasets...' )
60- await createDatasetViaApi ( datasetJson1 )
61- . then ( )
62- . catch ( ( ) => {
63- console . error ( 'Tests setup: Error while creating test Dataset 1' )
64- } )
65- await createDatasetViaApi ( datasetJson2 ) . catch ( ( ) => {
66- console . error ( 'Tests setup: Error while creating test Dataset 2' )
67- } )
68- await createDatasetViaApi ( datasetJson4 ) . catch ( ( ) => {
69- console . error ( 'Tests setup: Error while creating test Dataset 4' )
70- } )
71- await createCollectionViaApi ( collectionJson )
72- . then ( )
73- . catch ( ( ) => {
74- console . error ( 'Tests setup: Error while creating test Collection 1' )
75- } )
76- await createDatasetViaApi ( datasetJson3 , collectionJson . alias )
77- . then ( )
78- . catch ( ( ) => {
79- console . error ( 'Tests setup: Error while creating test Dataset 3' )
80- } )
81- console . log ( 'Test datasets created' )
82- await waitForDatasetsIndexingInSolr ( )
83- }
84-
85- /* eslint-disable @typescript-eslint/no-explicit-any */
86- async function createCollectionViaApi ( collectionJson : any ) : Promise < any > {
87- return await axios . post (
88- `${ TestConstants . TEST_API_URL } /dataverses/root` ,
89- collectionJson ,
90- buildRequestHeaders ( )
91- )
92- }
93-
94- /* eslint-disable @typescript-eslint/no-explicit-any */
95- async function createDatasetViaApi (
96- datasetJson : any ,
97- collectionId = ROOT_COLLECTION_ALIAS
98- ) : Promise < any > {
99- return await axios . post (
100- `${ TestConstants . TEST_API_URL } /dataverses/${ collectionId } /datasets` ,
101- datasetJson ,
102- buildRequestHeaders ( )
103- )
104- }
105-
106- /* eslint-disable @typescript-eslint/no-explicit-any */
107- async function waitForDatasetsIndexingInSolr ( ) : Promise < void > {
108- console . log ( 'Waiting for datasets indexing in Solr...' )
109- let datasetsIndexed = false
110- let retry = 0
111- while ( ! datasetsIndexed && retry < 10 ) {
112- await axios
113- . get ( `${ TestConstants . TEST_API_URL } /search?q=*&type=dataset` , buildRequestHeaders ( ) )
114- . then ( ( response ) => {
115- const nDatasets = response . data . data . items . length
116- if ( nDatasets === NUMBER_OF_DATASETS ) {
117- datasetsIndexed = true
118- }
119- } )
120- . catch ( ( error ) => {
121- console . error (
122- `Tests setup: Error while waiting for datasets indexing in Solr: [${
123- error . response . status
124- } ]${ error . response . data ? ` ${ error . response . data . message } ` : '' } `
125- )
126- } )
127- await new Promise ( ( resolve ) => setTimeout ( resolve , 1000 ) )
128- retry ++
129- }
130- if ( ! datasetsIndexed ) {
131- throw new Error ( 'Tests setup: Timeout reached while waiting for datasets indexing in Solr' )
132- }
133- console . log ( 'Datasets indexed in Solr' )
134- }
135-
136- /* eslint-disable @typescript-eslint/no-explicit-any */
137- function buildRequestHeaders ( ) : any {
138- return {
139- headers : { 'Content-Type' : 'application/json' , 'X-Dataverse-Key' : process . env . TEST_API_KEY }
140- }
141- }
0 commit comments