@@ -132,16 +132,16 @@ describe('/types', () => {
132
132
assert . equal ( true , ! ! included )
133
133
} )
134
134
} )
135
- describe ( '/tables' , async ( ) => {
136
- it ( 'GET' , async ( ) => {
135
+ describe ( '/tables & /columns ' , async ( ) => {
136
+ it ( 'GET /tables ' , async ( ) => {
137
137
const tables = await axios . get ( `${ URL } /tables` )
138
138
const datum = tables . data . find ( ( x ) => `${ x . schema } .${ x . name } ` === 'public.users' )
139
139
const notIncluded = tables . data . find ( ( x ) => `${ x . schema } .${ x . name } ` === 'pg_catalog.pg_type' )
140
140
assert . equal ( tables . status , STATUS . SUCCESS )
141
141
assert . equal ( true , ! ! datum )
142
142
assert . equal ( true , ! notIncluded )
143
143
} )
144
- it ( 'should return the columns' , async ( ) => {
144
+ it ( '/tables should return the columns' , async ( ) => {
145
145
const tables = await axios . get ( `${ URL } /tables` )
146
146
const datum = tables . data . find ( ( x ) => `${ x . schema } .${ x . name } ` === 'public.users' )
147
147
const idColumn = datum . columns . find ( ( x ) => x . name === 'id' )
@@ -153,12 +153,12 @@ describe('/tables', async () => {
153
153
assert . equal ( idColumn . is_identity , true )
154
154
assert . equal ( nameColumn . is_identity , false )
155
155
} )
156
- it ( 'should return the grants' , async ( ) => {
156
+ it ( '/tables should return the grants' , async ( ) => {
157
157
const tables = await axios . get ( `${ URL } /tables` )
158
158
const datum = tables . data . find ( ( x ) => `${ x . schema } .${ x . name } ` === 'public.users' )
159
159
assert . equal ( datum . grants . length > 0 , true )
160
160
} )
161
- it ( 'should return the relationships' , async ( ) => {
161
+ it ( '/tables should return the relationships' , async ( ) => {
162
162
const tables = await axios . get ( `${ URL } /tables` )
163
163
const datum = tables . data . find ( ( x ) => `${ x . schema } .${ x . name } ` === 'public.users' )
164
164
const relationships = datum . relationships
@@ -169,32 +169,54 @@ describe('/tables', async () => {
169
169
assert . equal ( true , relationship . target_table_schema === 'public' )
170
170
assert . equal ( true , relationship . target_table_name === 'users' )
171
171
} )
172
- it ( 'GET with system tables' , async ( ) => {
172
+ it ( 'GET /tabls with system tables' , async ( ) => {
173
173
const res = await axios . get ( `${ URL } /tables?includeSystemSchemas=true` )
174
174
const included = res . data . find ( ( x ) => `${ x . schema } .${ x . name } ` === 'pg_catalog.pg_type' )
175
175
assert . equal ( res . status , STATUS . SUCCESS )
176
176
assert . equal ( true , ! ! included )
177
177
} )
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` , {
180
199
schema : 'public' ,
181
200
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'],
187
206
} )
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')
198
220
await axios . post ( `${ URL } /query` , { query : 'DROP TABLE public.test' } )
199
221
} )
200
222
} )
0 commit comments