@@ -99,7 +99,7 @@ describe('/schemas', () => {
9999 assert . equal ( true , ! ! datum )
100100 assert . equal ( true , ! ! included )
101101 } )
102- it ( 'POST & PATCH' , async ( ) => {
102+ it ( 'POST & PATCH & DELETE ' , async ( ) => {
103103 const res = await axios . post ( `${ URL } /schemas` , { name : 'api' } )
104104 assert . equal ( 'api' , res . data . name )
105105 const newSchemaId = res . data . id
@@ -110,6 +110,15 @@ describe('/schemas', () => {
110110 owner : 'postgres' ,
111111 } )
112112 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+ )
113122 } )
114123} )
115124describe ( '/types' , ( ) => {
@@ -169,12 +178,19 @@ describe('/tables & /columns', async () => {
169178 assert . equal ( true , relationship . target_table_schema === 'public' )
170179 assert . equal ( true , relationship . target_table_name === 'users' )
171180 } )
172- it ( 'GET /tabls with system tables' , async ( ) => {
181+ it ( 'GET /tables with system tables' , async ( ) => {
173182 const res = await axios . get ( `${ URL } /tables?includeSystemSchemas=true` )
174183 const included = res . data . find ( ( x ) => `${ x . schema } .${ x . name } ` === 'pg_catalog.pg_type' )
175184 assert . equal ( res . status , STATUS . SUCCESS )
176185 assert . equal ( true , ! ! included )
177186 } )
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+ // })
178194 it ( 'GET /columns' , async ( ) => {
179195 const res = await axios . get ( `${ URL } /columns` )
180196 // console.log('res.data', res.data)
@@ -194,30 +210,84 @@ describe('/tables & /columns', async () => {
194210 assert . equal ( true , ! ! included )
195211 } )
196212 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 } ` )
221291 } )
222292} )
223293describe ( '/extensions' , ( ) => {
0 commit comments