@@ -15,24 +15,6 @@ const axiosServer = axios.create({
1515} )
1616
1717
18- export const streamToArray = async ( stream ) => { //todo: move this to utils
19-
20- return new Promise ( ( resolve , reject ) => {
21- const arr = [ ]
22-
23- stream . on ( 'data' , data => {
24- arr . push ( JSON . parse ( data . toString ( ) ) )
25- } ) ;
26-
27- stream . on ( 'end' , ( ) => {
28- resolve ( arr )
29- } ) ;
30-
31- stream . on ( 'error' , ( err ) => reject ( err ) )
32-
33- } )
34- }
35-
3618describe ( `Velo External DB Index API: ${ currentDbImplementationName ( ) } ` , ( ) => {
3719 beforeAll ( async ( ) => {
3820 await setupDb ( )
@@ -46,24 +28,14 @@ describe(`Velo External DB Index API: ${currentDbImplementationName()}`, () => {
4628 test ( 'list' , async ( ) => {
4729 await schema . givenCollection ( ctx . collectionName , [ ctx . column ] , authOwner )
4830
49- const response = await axiosServer . post ( '/indexes/list' , {
50- dataCollectionId : ctx . collectionName
51- } , { responseType : 'stream' , ...authOwner } )
52-
53- // expect(streamToArray(response.data)).
54- expect ( streamToArray ( response . data ) ) . resolves . toEqual ( matchers . listIndexResponseWithDefaultIndex ( ) )
31+ expect ( index . retrieveIndexesFor ( ctx . collectionName ) ) . resolves . toEqual ( matchers . listIndexResponseWithDefaultIndex ( ) )
5532 } )
5633
5734 test ( 'list with multiple indexes' , async ( ) => {
5835 await schema . givenCollection ( ctx . collectionName , [ ctx . column ] , authOwner )
5936 await index . givenIndexes ( ctx . collectionName , [ ctx . index ] , authOwner )
6037
61- await eventually ( async ( ) => {
62- const response = await axiosServer . post ( '/indexes/list' , {
63- dataCollectionId : ctx . collectionName
64- } , { responseType : 'stream' , ...authOwner } )
65- await expect ( streamToArray ( response . data ) ) . resolves . toEqual ( matchers . listIndexResponseWith ( [ ctx . index ] ) )
66- } )
38+ await expect ( index . retrieveIndexesFor ( ctx . collectionName ) ) . resolves . toEqual ( matchers . listIndexResponseWith ( [ ctx . index ] ) )
6739 } )
6840
6941 test ( 'create' , async ( ) => {
@@ -76,52 +48,48 @@ describe(`Velo External DB Index API: ${currentDbImplementationName()}`, () => {
7648 } , authOwner ) ) . resolves . toEqual ( matchers . createIndexResponseWith ( ctx . index ) )
7749
7850 // active
79- await eventually ( async ( ) => {
80- const response = await axiosServer . post ( '/indexes/list' , {
81- dataCollectionId : ctx . collectionName
82- } , { responseType : 'stream' , ...authOwner } )
83- await expect ( streamToArray ( response . data ) ) . resolves . toEqual ( matchers . listIndexResponseWith ( [ ctx . index ] ) )
84- } )
51+ await eventually ( async ( ) =>
52+ await expect ( index . retrieveIndexesFor ( ctx . collectionName ) ) . resolves . toEqual ( matchers . listIndexResponseWith ( [ ctx . index ] ) )
53+ )
8554 } )
8655
8756 test ( 'create with existing index' , async ( ) => {
8857 await schema . givenCollection ( ctx . collectionName , [ ctx . column ] , authOwner )
8958 await index . givenIndexes ( ctx . collectionName , [ ctx . index ] , authOwner )
9059
91- eventually ( async ( ) => {
92- await expect ( axiosServer . post ( '/indexes/create' , {
93- dataCollectionId : ctx . collectionName ,
94- index : ctx . index
95- } , authOwner ) ) . rejects . toThrow ( )
96- } , {
97- timeout : 5000 ,
98- interval : 1000
99- } )
60+ await expect ( axiosServer . post ( '/indexes/create' , {
61+ dataCollectionId : ctx . collectionName ,
62+ index : ctx . index
63+ } , authOwner ) ) . rejects . toThrow ( )
10064 } )
10165
102- test . only ( 'remove' , async ( ) => {
66+ test ( 'remove' , async ( ) => {
10367 await schema . givenCollection ( ctx . collectionName , [ ctx . column ] , authOwner )
10468 await index . givenIndexes ( ctx . collectionName , [ ctx . index ] , authOwner )
105-
106- await eventually ( async ( ) => {
107- await expect ( axiosServer . post ( '/indexes/remove' , {
108- dataCollectionId : ctx . collectionName ,
109- indexName : ctx . index . name
110- } , authOwner ) ) . resolves . toEqual ( matchers . removeIndexResponse ( ) ) . catch ( )
111- } )
112-
113- // await expect(axiosServer.post('/indexes/remove', {
114- // dataCollectionId: ctx.collectionName,
115- // index: ctx.index
116- // }, authOwner)).resolves.toEqual(matchers.removeIndexResponse())
117-
118- // const response = await axiosServer.post('/indexes/list', {
119- // dataCollectionId: ctx.collectionName
120- // }, { responseType: 'stream', ...authOwner })
121- // await expect(streamToArray(response.data)).resolves.not.toEqual(matchers.listIndexResponseWith([ctx.index]))
69+
70+ await expect ( axiosServer . post ( '/indexes/remove' , {
71+ dataCollectionId : ctx . collectionName ,
72+ indexName : ctx . index . name
73+ } , authOwner ) ) . resolves . toEqual ( matchers . removeIndexResponse ( ) ) . catch ( )
74+
75+ await expect ( index . retrieveIndexesFor ( ctx . collectionName ) ) . resolves . not . toEqual ( matchers . listIndexResponseWith ( [ ctx . index ] ) )
12276 } )
12377
12478
79+ test ( 'get failed indexes' , async ( ) => {
80+ await schema . givenCollection ( ctx . collectionName , [ ctx . column ] , authOwner )
81+
82+ await axiosServer . post ( '/indexes/create' , {
83+ dataCollectionId : ctx . collectionName ,
84+ index : ctx . invalidIndex
85+ } , authOwner ) . catch ( e => { } )
86+
87+
88+ await eventually ( async ( ) =>
89+ await expect ( index . retrieveIndexesFor ( ctx . collectionName ) ) . resolves . toEqual ( matchers . listIndexResponseWithFailedIndex ( ctx . invalidIndex ) )
90+ )
91+ } )
92+
12593 afterAll ( async ( ) => {
12694 await teardownApp ( )
12795 } )
@@ -130,11 +98,13 @@ describe(`Velo External DB Index API: ${currentDbImplementationName()}`, () => {
13098 collectionName : Uninitialized ,
13199 column : Uninitialized ,
132100 index : Uninitialized ,
101+ invalidIndex : Uninitialized ,
133102 }
134103
135104 beforeEach ( ( ) => {
136105 ctx . collectionName = chance . word ( )
137106 ctx . column = gen . randomColumn ( )
138107 ctx . index = gen . spiIndexFor ( ctx . collectionName , [ ctx . column . name ] )
108+ ctx . invalidIndex = gen . spiIndexFor ( ctx . collectionName , [ 'wrongColumn' ] )
139109 } )
140110} ) ;
0 commit comments