@@ -15,24 +15,6 @@ const axiosServer = axios.create({
15
15
} )
16
16
17
17
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
-
36
18
describe ( `Velo External DB Index API: ${ currentDbImplementationName ( ) } ` , ( ) => {
37
19
beforeAll ( async ( ) => {
38
20
await setupDb ( )
@@ -46,24 +28,14 @@ describe(`Velo External DB Index API: ${currentDbImplementationName()}`, () => {
46
28
test ( 'list' , async ( ) => {
47
29
await schema . givenCollection ( ctx . collectionName , [ ctx . column ] , authOwner )
48
30
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 ( ) )
55
32
} )
56
33
57
34
test ( 'list with multiple indexes' , async ( ) => {
58
35
await schema . givenCollection ( ctx . collectionName , [ ctx . column ] , authOwner )
59
36
await index . givenIndexes ( ctx . collectionName , [ ctx . index ] , authOwner )
60
37
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 ] ) )
67
39
} )
68
40
69
41
test ( 'create' , async ( ) => {
@@ -76,52 +48,48 @@ describe(`Velo External DB Index API: ${currentDbImplementationName()}`, () => {
76
48
} , authOwner ) ) . resolves . toEqual ( matchers . createIndexResponseWith ( ctx . index ) )
77
49
78
50
// 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
+ )
85
54
} )
86
55
87
56
test ( 'create with existing index' , async ( ) => {
88
57
await schema . givenCollection ( ctx . collectionName , [ ctx . column ] , authOwner )
89
58
await index . givenIndexes ( ctx . collectionName , [ ctx . index ] , authOwner )
90
59
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 ( )
100
64
} )
101
65
102
- test . only ( 'remove' , async ( ) => {
66
+ test ( 'remove' , async ( ) => {
103
67
await schema . givenCollection ( ctx . collectionName , [ ctx . column ] , authOwner )
104
68
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 ] ) )
122
76
} )
123
77
124
78
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
+
125
93
afterAll ( async ( ) => {
126
94
await teardownApp ( )
127
95
} )
@@ -130,11 +98,13 @@ describe(`Velo External DB Index API: ${currentDbImplementationName()}`, () => {
130
98
collectionName : Uninitialized ,
131
99
column : Uninitialized ,
132
100
index : Uninitialized ,
101
+ invalidIndex : Uninitialized ,
133
102
}
134
103
135
104
beforeEach ( ( ) => {
136
105
ctx . collectionName = chance . word ( )
137
106
ctx . column = gen . randomColumn ( )
138
107
ctx . index = gen . spiIndexFor ( ctx . collectionName , [ ctx . column . name ] )
108
+ ctx . invalidIndex = gen . spiIndexFor ( ctx . collectionName , [ 'wrongColumn' ] )
139
109
} )
140
110
} ) ;
0 commit comments