@@ -99,7 +99,7 @@ describe('/schemas', () => {
99
99
assert . equal ( true , ! ! datum )
100
100
assert . equal ( true , ! ! included )
101
101
} )
102
- it ( 'POST & PATCH' , async ( ) => {
102
+ it ( 'POST & PATCH & DELETE ' , async ( ) => {
103
103
const res = await axios . post ( `${ URL } /schemas` , { name : 'api' } )
104
104
assert . equal ( 'api' , res . data . name )
105
105
const newSchemaId = res . data . id
@@ -110,6 +110,15 @@ describe('/schemas', () => {
110
110
owner : 'postgres' ,
111
111
} )
112
112
assert . equal ( 'api' , res3 . data . name )
113
+
114
+ const res4 = await axios . delete ( `${ URL } /schemas/${ newSchemaId } ` )
115
+ assert . equal ( res4 . data . name , 'api' )
116
+
117
+ const res5 = await axios . get ( `${ URL } /schemas` )
118
+ assert . equal (
119
+ res5 . data . some ( ( x ) => x . id === newSchemaId ) ,
120
+ false
121
+ )
113
122
} )
114
123
} )
115
124
describe ( '/types' , ( ) => {
@@ -169,12 +178,19 @@ describe('/tables & /columns', async () => {
169
178
assert . equal ( true , relationship . target_table_schema === 'public' )
170
179
assert . equal ( true , relationship . target_table_name === 'users' )
171
180
} )
172
- it ( 'GET /tabls with system tables' , async ( ) => {
181
+ it ( 'GET /tables with system tables' , async ( ) => {
173
182
const res = await axios . get ( `${ URL } /tables?includeSystemSchemas=true` )
174
183
const included = res . data . find ( ( x ) => `${ x . schema } .${ x . name } ` === 'pg_catalog.pg_type' )
175
184
assert . equal ( res . status , STATUS . SUCCESS )
176
185
assert . equal ( true , ! ! included )
177
186
} )
187
+ // FIXME: Bad handling of query param in /tables & /columns & /schemas & /types
188
+ // it('GET /tables without system tables (explicit)', async () => {
189
+ // const res = await axios.get(`${URL}/tables?includeSystemSchemas=false`)
190
+ // const isIncluded = res.data.some((x) => `${x.schema}.${x.name}` === 'pg_catalog.pg_type')
191
+ // assert.equal(res.status, STATUS.SUCCESS)
192
+ // assert.equal(isIncluded, false)
193
+ // })
178
194
it ( 'GET /columns' , async ( ) => {
179
195
const res = await axios . get ( `${ URL } /columns` )
180
196
// console.log('res.data', res.data)
@@ -194,30 +210,84 @@ describe('/tables & /columns', async () => {
194
210
assert . equal ( true , ! ! included )
195
211
} )
196
212
it ( 'POST /tables should create a table' , async ( ) => {
197
- await axios . post ( `${ URL } /query` , { query : 'DROP TABLE IF EXISTS public.test' } )
198
- let { data : newTable } = await axios . post ( `${ URL } /tables` , {
199
- schema : 'public' ,
200
- name : 'test' ,
201
- // columns: [
202
- // { name: 'id', is_identity: true, is_nullable: false, data_type: 'bigint' },
203
- // { name: 'data', data_type: 'text' },
204
- // ],
205
- // primary_keys: ['id'],
206
- } )
207
- // console.log('newTable', newTable)
208
- const newTableId = newTable . id
209
- assert . equal ( newTableId > 0 , true )
210
- // const { data: tables } = await axios.get(`${URL}/tables`)
211
- // const test = tables.find((table) => `${table.schema}.${table.name}` === 'public.test')
212
- // const id = test.columns.find((column) => column.name === 'id')
213
- // const data = test.columns.find((column) => column.name === 'data')
214
- // assert.equal(id.is_identity, true)
215
- // assert.equal(id.is_nullable, false)
216
- // assert.equal(id.data_type, 'bigint')
217
- // assert.equal(data.is_identity, false)
218
- // assert.equal(data.is_nullable, true)
219
- // assert.equal(data.data_type, 'text')
220
- await axios . post ( `${ URL } /query` , { query : 'DROP TABLE public.test' } )
213
+ const { data : newTable } = await axios . post ( `${ URL } /tables` , { name : 'test' } )
214
+ assert . equal ( `${ newTable . schema } .${ newTable . name } ` , 'public.test' )
215
+
216
+ const { data : tables } = await axios . get ( `${ URL } /tables` )
217
+ assert . equal (
218
+ tables . some ( ( table ) => table . id === newTable . id ) ,
219
+ true
220
+ )
221
+
222
+ await axios . delete ( `${ URL } /tables/${ newTable . id } ` )
223
+ } )
224
+ it ( 'PATCH /tables' , async ( ) => {
225
+ const { data : newTable } = await axios . post ( `${ URL } /tables` , { name : 'test' } )
226
+ await axios . patch ( `${ URL } /tables/${ newTable . id } ` , { name : 'test a' } )
227
+ const { data : tables } = await axios . get ( `${ URL } /tables` )
228
+ assert . equal (
229
+ tables . some ( ( table ) => `${ table . schema } .${ table . name } ` === `public.test a` ) ,
230
+ true
231
+ )
232
+
233
+ await axios . delete ( `${ URL } /tables/${ newTable . id } ` )
234
+ } )
235
+ it ( 'DELETE /tables' , async ( ) => {
236
+ const { data : newTable } = await axios . post ( `${ URL } /tables` , { name : 'test' } )
237
+
238
+ await axios . delete ( `${ URL } /tables/${ newTable . id } ` )
239
+ const { data : tables } = await axios . get ( `${ URL } /tables` )
240
+ assert . equal (
241
+ tables . some ( ( table ) => `${ table . schema } .${ table . name } ` === `public.test` ) ,
242
+ false
243
+ )
244
+ } )
245
+ it ( 'POST /column' , async ( ) => {
246
+ const { data : newTable } = await axios . post ( `${ URL } /tables` , { name : 'foo bar' } )
247
+ await axios . post ( `${ URL } /columns` , { tableId : newTable . id , name : 'foo bar' , type : 'int2' } )
248
+
249
+ const { data : columns } = await axios . get ( `${ URL } /columns` )
250
+ assert . equal (
251
+ columns . some (
252
+ ( column ) =>
253
+ column . id === `${ newTable . id } .1` && column . name === 'foo bar' && column . format === 'int2'
254
+ ) ,
255
+ true
256
+ )
257
+
258
+ await axios . delete ( `${ URL } /columns/${ newTable . id } .1` )
259
+ await axios . delete ( `${ URL } /tables/${ newTable . id } ` )
260
+ } )
261
+ it ( 'PATCH /columns' , async ( ) => {
262
+ const { data : newTable } = await axios . post ( `${ URL } /tables` , { name : 'foo bar' } )
263
+ await axios . post ( `${ URL } /columns` , { tableId : newTable . id , name : 'foo' , type : 'int2' } )
264
+
265
+ await axios . patch ( `${ URL } /columns/${ newTable . id } .1` , { name : 'foo bar' , type : 'int4' } )
266
+
267
+ const { data : columns } = await axios . get ( `${ URL } /columns` )
268
+ assert . equal (
269
+ columns . some (
270
+ ( column ) =>
271
+ column . id === `${ newTable . id } .1` && column . name === 'foo bar' && column . format === 'int4'
272
+ ) ,
273
+ true
274
+ )
275
+
276
+ await axios . delete ( `${ URL } /columns/${ newTable . id } .1` )
277
+ await axios . delete ( `${ URL } /tables/${ newTable . id } ` )
278
+ } )
279
+ it ( 'DELETE /columns' , async ( ) => {
280
+ const { data : newTable } = await axios . post ( `${ URL } /tables` , { name : 'foo bar' } )
281
+ await axios . post ( `${ URL } /columns` , { tableId : newTable . id , name : 'foo bar' , type : 'int2' } )
282
+
283
+ await axios . delete ( `${ URL } /columns/${ newTable . id } .1` )
284
+ const { data : columns } = await axios . get ( `${ URL } /columns` )
285
+ assert . equal (
286
+ columns . some ( ( column ) => column . id === `${ newTable . id } .1` ) ,
287
+ false
288
+ )
289
+
290
+ await axios . delete ( `${ URL } /tables/${ newTable . id } ` )
221
291
} )
222
292
} )
223
293
describe ( '/extensions' , ( ) => {
0 commit comments