22 ApiConfig ,
33 WriteError ,
44 createCollection ,
5- getCollection ,
65 linkCollection ,
76 deleteCollection ,
87 getCollectionItems ,
@@ -16,56 +15,49 @@ describe('execute', () => {
1615 const firstCollectionAlias = 'unlinkCollection-functional-test-first'
1716 const secondCollectionAlias = 'unlinkCollection-functional-test-second'
1817
18+ let firstCollectionId : number
19+ let secondCollectionId : number
1920 beforeEach ( async ( ) => {
2021 ApiConfig . init (
2122 TestConstants . TEST_API_URL ,
2223 DataverseApiAuthMechanism . API_KEY ,
2324 process . env . TEST_API_KEY
2425 )
25- const firstCollection = createCollectionDTO ( firstCollectionAlias )
26- const secondCollection = createCollectionDTO ( secondCollectionAlias )
27- await createCollection . execute ( firstCollection )
28- await createCollection . execute ( secondCollection )
29- await linkCollection . execute ( secondCollection . alias , firstCollection . alias )
26+ const firstCollectionDTO = createCollectionDTO ( firstCollectionAlias )
27+ const secondCollectionDTO = createCollectionDTO ( secondCollectionAlias )
28+ firstCollectionId = await createCollection . execute ( firstCollectionDTO )
29+ secondCollectionId = await createCollection . execute ( secondCollectionDTO )
30+ await linkCollection . execute ( secondCollectionAlias , firstCollectionAlias )
31+ // Give enough time to Solr for indexing
32+ await new Promise ( ( resolve ) => setTimeout ( resolve , 5000 ) )
3033 } )
3134
3235 afterEach ( async ( ) => {
3336 await Promise . all ( [
34- getCollection
35- . execute ( firstCollectionAlias )
36- . then ( ( collection ) =>
37- collection && collection . id ? deleteCollection . execute ( collection . id ) : null
38- ) ,
39- getCollection
40- . execute ( secondCollectionAlias )
41- . then ( ( collection ) =>
42- collection && collection . id ? deleteCollection . execute ( collection . id ) : null
43- )
37+ deleteCollection . execute ( firstCollectionId ) ,
38+ deleteCollection . execute ( secondCollectionId )
4439 ] )
4540 } )
4641
4742 test ( 'should successfully unlink two collections' , async ( ) => {
48- const firstCollection = await getCollection . execute ( firstCollectionAlias )
49- const secondCollection = await getCollection . execute ( secondCollectionAlias )
50- // Give enough time to Solr for indexing
51- await new Promise ( ( resolve ) => setTimeout ( resolve , 5000 ) )
43+ // Verify that the collections are linked
5244 const collectionItemSubset = await getCollectionItems . execute ( firstCollectionAlias )
5345 expect ( collectionItemSubset . items . length ) . toBe ( 1 )
5446
55- await unlinkCollection . execute ( secondCollection . alias , firstCollection . alias )
47+ await unlinkCollection . execute ( secondCollectionAlias , firstCollectionAlias )
48+ // Wait for the unlinking to be processed by Solr
5649 await new Promise ( ( resolve ) => setTimeout ( resolve , 5000 ) )
5750 const collectionItemSubset2 = await getCollectionItems . execute ( firstCollectionAlias )
5851 expect ( collectionItemSubset2 . items . length ) . toBe ( 0 )
5952 } )
6053
6154 test ( 'should throw an error when linking a non-existent collection' , async ( ) => {
6255 const invalidCollectionId = 99999
63- const firstCollection = await getCollection . execute ( firstCollectionAlias )
6456
6557 expect . assertions ( 2 )
6658 let writeError : WriteError | undefined = undefined
6759 try {
68- await unlinkCollection . execute ( invalidCollectionId , firstCollection . id )
60+ await unlinkCollection . execute ( invalidCollectionId , firstCollectionId )
6961 throw new Error ( 'Use case should throw an error' )
7062 } catch ( error ) {
7163 writeError = error as WriteError
0 commit comments