@@ -132,16 +132,16 @@ describe('/types', () => {
132132 assert . equal ( true , ! ! included )
133133 } )
134134} )
135- describe ( '/tables' , async ( ) => {
136- it ( 'GET' , async ( ) => {
135+ describe ( '/tables & /columns ' , async ( ) => {
136+ it ( 'GET /tables ' , async ( ) => {
137137 const tables = await axios . get ( `${ URL } /tables` )
138138 const datum = tables . data . find ( ( x ) => `${ x . schema } .${ x . name } ` === 'public.users' )
139139 const notIncluded = tables . data . find ( ( x ) => `${ x . schema } .${ x . name } ` === 'pg_catalog.pg_type' )
140140 assert . equal ( tables . status , STATUS . SUCCESS )
141141 assert . equal ( true , ! ! datum )
142142 assert . equal ( true , ! notIncluded )
143143 } )
144- it ( 'should return the columns' , async ( ) => {
144+ it ( '/tables should return the columns' , async ( ) => {
145145 const tables = await axios . get ( `${ URL } /tables` )
146146 const datum = tables . data . find ( ( x ) => `${ x . schema } .${ x . name } ` === 'public.users' )
147147 const idColumn = datum . columns . find ( ( x ) => x . name === 'id' )
@@ -153,12 +153,12 @@ describe('/tables', async () => {
153153 assert . equal ( idColumn . is_identity , true )
154154 assert . equal ( nameColumn . is_identity , false )
155155 } )
156- it ( 'should return the grants' , async ( ) => {
156+ it ( '/tables should return the grants' , async ( ) => {
157157 const tables = await axios . get ( `${ URL } /tables` )
158158 const datum = tables . data . find ( ( x ) => `${ x . schema } .${ x . name } ` === 'public.users' )
159159 assert . equal ( datum . grants . length > 0 , true )
160160 } )
161- it ( 'should return the relationships' , async ( ) => {
161+ it ( '/tables should return the relationships' , async ( ) => {
162162 const tables = await axios . get ( `${ URL } /tables` )
163163 const datum = tables . data . find ( ( x ) => `${ x . schema } .${ x . name } ` === 'public.users' )
164164 const relationships = datum . relationships
@@ -169,32 +169,54 @@ describe('/tables', async () => {
169169 assert . equal ( true , relationship . target_table_schema === 'public' )
170170 assert . equal ( true , relationship . target_table_name === 'users' )
171171 } )
172- it ( 'GET with system tables' , async ( ) => {
172+ it ( 'GET /tabls with system tables' , async ( ) => {
173173 const res = await axios . get ( `${ URL } /tables?includeSystemSchemas=true` )
174174 const included = res . data . find ( ( x ) => `${ x . schema } .${ x . name } ` === 'pg_catalog.pg_type' )
175175 assert . equal ( res . status , STATUS . SUCCESS )
176176 assert . equal ( true , ! ! included )
177177 } )
178- it ( 'POST' , async ( ) => {
179- await axios . post ( `${ URL } /tables` , {
178+ it ( 'GET /columns' , async ( ) => {
179+ const res = await axios . get ( `${ URL } /columns` )
180+ // console.log('res.data', res.data)
181+ const datum = res . data . find ( ( x ) => x . schema == 'public' )
182+ const notIncluded = res . data . find ( ( x ) => x . schema == 'pg_catalog' )
183+ assert . equal ( res . status , STATUS . SUCCESS )
184+ assert . equal ( true , ! ! datum )
185+ assert . equal ( true , ! notIncluded )
186+ } )
187+ it ( 'GET /columns with system types' , async ( ) => {
188+ const res = await axios . get ( `${ URL } /columns?includeSystemSchemas=true` )
189+ // console.log('res.data', res.data)
190+ const datum = res . data . find ( ( x ) => x . schema == 'public' )
191+ const included = res . data . find ( ( x ) => x . schema == 'pg_catalog' )
192+ assert . equal ( res . status , STATUS . SUCCESS )
193+ assert . equal ( true , ! ! datum )
194+ assert . equal ( true , ! ! included )
195+ } )
196+ 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` , {
180199 schema : 'public' ,
181200 name : 'test' ,
182- columns : [
183- { name : 'id' , is_identity : true , is_nullable : false , data_type : 'bigint' } ,
184- { name : 'data' , data_type : 'text' } ,
185- ] ,
186- primary_keys : [ 'id' ] ,
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'],
187206 } )
188- const { data : tables } = await axios . get ( `${ URL } /tables` )
189- const test = tables . find ( ( table ) => `${ table . schema } .${ table . name } ` === 'public.test' )
190- const id = test . columns . find ( ( column ) => column . name === 'id' )
191- const data = test . columns . find ( ( column ) => column . name === 'data' )
192- assert . equal ( id . is_identity , true )
193- assert . equal ( id . is_nullable , false )
194- assert . equal ( id . data_type , 'bigint' )
195- assert . equal ( data . is_identity , false )
196- assert . equal ( data . is_nullable , true )
197- assert . equal ( data . data_type , 'text' )
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')
198220 await axios . post ( `${ URL } /query` , { query : 'DROP TABLE public.test' } )
199221 } )
200222} )
0 commit comments