@@ -8,7 +8,7 @@ import * as index from '../drivers/index_api_rest_test_support'
8
8
import * as gen from '../gen'
9
9
import axios from 'axios'
10
10
const chance = new Chance ( )
11
- import { InputField } from '@wix-velo/velo-external-db-types '
11
+ import { eventually } from '../drivers/eventually '
12
12
13
13
const axiosServer = axios . create ( {
14
14
baseURL : 'http://localhost:8080'
@@ -19,17 +19,17 @@ export const streamToArray = async (stream) => { //todo: move this to utils
19
19
20
20
return new Promise ( ( resolve , reject ) => {
21
21
const arr = [ ]
22
-
22
+
23
23
stream . on ( 'data' , data => {
24
24
arr . push ( JSON . parse ( data . toString ( ) ) )
25
25
} ) ;
26
-
26
+
27
27
stream . on ( 'end' , ( ) => {
28
28
resolve ( arr )
29
29
} ) ;
30
30
31
31
stream . on ( 'error' , ( err ) => reject ( err ) )
32
-
32
+
33
33
} )
34
34
}
35
35
@@ -48,22 +48,80 @@ describe(`Velo External DB Index API: ${currentDbImplementationName()}`, () => {
48
48
49
49
const response = await axiosServer . post ( '/indexes/list' , {
50
50
dataCollectionId : ctx . collectionName
51
- } , { responseType : 'stream' , ...authOwner } )
51
+ } , { responseType : 'stream' , ...authOwner } )
52
52
53
- await expect ( streamToArray ( response . data ) ) . resolves . toEqual ( matchers . listIndexResponseWithDefaultIndex ( ) )
53
+ // expect(streamToArray(response.data)).
54
+ expect ( streamToArray ( response . data ) ) . resolves . toEqual ( matchers . listIndexResponseWithDefaultIndex ( ) )
54
55
} )
55
56
56
57
test ( 'list with multiple indexes' , async ( ) => {
57
58
await schema . givenCollection ( ctx . collectionName , [ ctx . column ] , authOwner )
58
59
await index . givenIndexes ( ctx . collectionName , [ ctx . index ] , authOwner )
59
60
60
- const response = await axiosServer . post ( '/indexes/list' , {
61
- dataCollectionId : ctx . collectionName
62
- } , { responseType : 'stream' , ...authOwner } )
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
+ } )
67
+ } )
63
68
64
- await expect ( streamToArray ( response . data ) ) . resolves . toEqual ( matchers . listIndexResponseWith ( [ ctx . index ] ) )
69
+ test ( 'create' , async ( ) => {
70
+ await schema . givenCollection ( ctx . collectionName , [ ctx . column ] , authOwner )
71
+
72
+ // in-progress
73
+ await expect ( axiosServer . post ( '/indexes/create' , {
74
+ dataCollectionId : ctx . collectionName ,
75
+ index : ctx . index
76
+ } , authOwner ) ) . resolves . toEqual ( matchers . createIndexResponseWith ( ctx . index ) )
77
+
78
+ // 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
+ } )
65
85
} )
66
86
87
+ test ( 'create with existing index' , async ( ) => {
88
+ await schema . givenCollection ( ctx . collectionName , [ ctx . column ] , authOwner )
89
+ await index . givenIndexes ( ctx . collectionName , [ ctx . index ] , authOwner )
90
+
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
+ } )
100
+ } )
101
+
102
+ test . only ( 'remove' , async ( ) => {
103
+ await schema . givenCollection ( ctx . collectionName , [ ctx . column ] , authOwner )
104
+ 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]))
122
+ } )
123
+
124
+
67
125
afterAll ( async ( ) => {
68
126
await teardownApp ( )
69
127
} )
0 commit comments