@@ -8,7 +8,7 @@ import * as index from '../drivers/index_api_rest_test_support'
88import * as gen from '../gen'
99import axios from 'axios'
1010const chance = new Chance ( )
11- import { InputField } from '@wix-velo/velo-external-db-types '
11+ import { eventually } from '../drivers/eventually '
1212
1313const axiosServer = axios . create ( {
1414 baseURL : 'http://localhost:8080'
@@ -19,17 +19,17 @@ export const streamToArray = async (stream) => { //todo: move this to utils
1919
2020 return new Promise ( ( resolve , reject ) => {
2121 const arr = [ ]
22-
22+
2323 stream . on ( 'data' , data => {
2424 arr . push ( JSON . parse ( data . toString ( ) ) )
2525 } ) ;
26-
26+
2727 stream . on ( 'end' , ( ) => {
2828 resolve ( arr )
2929 } ) ;
3030
3131 stream . on ( 'error' , ( err ) => reject ( err ) )
32-
32+
3333 } )
3434}
3535
@@ -48,22 +48,80 @@ describe(`Velo External DB Index API: ${currentDbImplementationName()}`, () => {
4848
4949 const response = await axiosServer . post ( '/indexes/list' , {
5050 dataCollectionId : ctx . collectionName
51- } , { responseType : 'stream' , ...authOwner } )
51+ } , { responseType : 'stream' , ...authOwner } )
5252
53- await expect ( streamToArray ( response . data ) ) . resolves . toEqual ( matchers . listIndexResponseWithDefaultIndex ( ) )
53+ // expect(streamToArray(response.data)).
54+ expect ( streamToArray ( response . data ) ) . resolves . toEqual ( matchers . listIndexResponseWithDefaultIndex ( ) )
5455 } )
5556
5657 test ( 'list with multiple indexes' , async ( ) => {
5758 await schema . givenCollection ( ctx . collectionName , [ ctx . column ] , authOwner )
5859 await index . givenIndexes ( ctx . collectionName , [ ctx . index ] , authOwner )
5960
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+ } )
6368
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+ } )
6585 } )
6686
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+
67125 afterAll ( async ( ) => {
68126 await teardownApp ( )
69127 } )
0 commit comments