@@ -175,6 +175,15 @@ describe('/functions', () => {
175
175
assert . equal ( true , ! ! datum )
176
176
assert . equal ( true , ! ! included )
177
177
} )
178
+ it ( 'GET single by ID' , async ( ) => {
179
+ const functions = await axios . get ( `${ URL } /functions` )
180
+ const functionFiltered = functions . data . find (
181
+ ( func ) => `${ func . schema } .${ func . name } ` === 'public.add'
182
+ )
183
+ const { data : functionById } = await axios . get ( `${ URL } /functions/${ functionFiltered . id } ` )
184
+
185
+ assert . deepStrictEqual ( functionById , functionFiltered )
186
+ } )
178
187
} )
179
188
describe ( '/tables' , async ( ) => {
180
189
it ( 'GET' , async ( ) => {
@@ -312,7 +321,7 @@ describe('/tables', async () => {
312
321
type : 'int2' ,
313
322
default_value : 42 ,
314
323
is_nullable : false ,
315
- comment : 'foo'
324
+ comment : 'foo' ,
316
325
} )
317
326
318
327
const { data : columns } = await axios . get ( `${ URL } /columns` )
@@ -337,17 +346,16 @@ describe('/tables', async () => {
337
346
} )
338
347
339
348
// https://wiki.postgresql.org/wiki/Retrieve_primary_key_columns
340
- const { data : primaryKeys } = await axios . post (
341
- `${ URL } /query` ,
342
- { query : `
349
+ const { data : primaryKeys } = await axios . post ( `${ URL } /query` , {
350
+ query : `
343
351
SELECT a.attname
344
352
FROM pg_index i
345
353
JOIN pg_attribute a ON a.attrelid = i.indrelid
346
354
AND a.attnum = ANY(i.indkey)
347
355
WHERE i.indrelid = '${ newTable . name } '::regclass
348
356
AND i.indisprimary;
349
- ` }
350
- )
357
+ ` ,
358
+ } )
351
359
assert . equal ( primaryKeys . length , 1 )
352
360
assert . equal ( primaryKeys [ 0 ] . attname , 'bar' )
353
361
@@ -363,18 +371,17 @@ describe('/tables', async () => {
363
371
is_unique : true ,
364
372
} )
365
373
366
- const { data : uniqueColumns } = await axios . post (
367
- `${ URL } /query` ,
368
- { query : `
374
+ const { data : uniqueColumns } = await axios . post ( `${ URL } /query` , {
375
+ query : `
369
376
SELECT a.attname
370
377
FROM pg_index i
371
378
JOIN pg_constraint c ON c.conindid = i.indexrelid
372
379
JOIN pg_attribute a ON a.attrelid = i.indrelid
373
380
AND a.attnum = ANY(i.indkey)
374
381
WHERE i.indrelid = '${ newTable . name } '::regclass
375
382
AND i.indisunique;
376
- ` }
377
- )
383
+ ` ,
384
+ } )
378
385
assert . equal ( uniqueColumns . length , 1 )
379
386
assert . equal ( uniqueColumns [ 0 ] . attname , 'bar' )
380
387
@@ -423,16 +430,15 @@ describe('/tables', async () => {
423
430
check : "description <> ''" ,
424
431
} )
425
432
426
- const { data : constraints } = await axios . post (
427
- `${ URL } /query` ,
428
- { query : `
433
+ const { data : constraints } = await axios . post ( `${ URL } /query` , {
434
+ query : `
429
435
SELECT pg_get_constraintdef((
430
436
SELECT c.oid
431
437
FROM pg_constraint c
432
438
WHERE c.conrelid = '${ newTable . name } '::regclass
433
439
));
434
- ` }
435
- )
440
+ ` ,
441
+ } )
436
442
assert . equal ( constraints . length , 1 )
437
443
assert . equal ( constraints [ 0 ] . pg_get_constraintdef , "CHECK ((description <> ''::text))" )
438
444
@@ -499,7 +505,7 @@ describe('/tables', async () => {
499
505
500
506
const { data : updatedColumn } = await axios . patch ( `${ URL } /columns/${ newTable . id } .1` , {
501
507
type : 'int4' ,
502
- default_value : 0
508
+ default_value : 0 ,
503
509
} )
504
510
505
511
assert . strictEqual ( updatedColumn . format , 'int4' )
@@ -737,7 +743,10 @@ describe('/publications with tables', () => {
737
743
assert . equal ( newPublication . publish_update , publication . publish_update )
738
744
assert . equal ( newPublication . publish_delete , publication . publish_delete )
739
745
assert . equal ( newPublication . publish_truncate , publication . publish_truncate )
740
- assert . equal ( newPublication . tables . some ( table => `${ table . schema } .${ table . name } ` === 'public.users' ) , true )
746
+ assert . equal (
747
+ newPublication . tables . some ( ( table ) => `${ table . schema } .${ table . name } ` === 'public.users' ) ,
748
+ true
749
+ )
741
750
} )
742
751
it ( 'GET' , async ( ) => {
743
752
const res = await axios . get ( `${ URL } /publications` )
@@ -755,7 +764,10 @@ describe('/publications with tables', () => {
755
764
} )
756
765
assert . equal ( updated . name , 'b' )
757
766
assert . equal ( updated . publish_insert , false )
758
- assert . equal ( updated . tables . some ( table => `${ table . schema } .${ table . name } ` === 'public.users' ) , false )
767
+ assert . equal (
768
+ updated . tables . some ( ( table ) => `${ table . schema } .${ table . name } ` === 'public.users' ) ,
769
+ false
770
+ )
759
771
} )
760
772
it ( 'DELETE' , async ( ) => {
761
773
const res = await axios . get ( `${ URL } /publications` )
@@ -768,9 +780,15 @@ describe('/publications with tables', () => {
768
780
} )
769
781
it ( '/publications for tables with uppercase' , async ( ) => {
770
782
const { data : table } = await axios . post ( `${ URL } /tables` , { name : 'T' } )
771
- const { data : publication } = await axios . post ( `${ URL } /publications` , { name : 'pub' , tables : [ 'T' ] } )
783
+ const { data : publication } = await axios . post ( `${ URL } /publications` , {
784
+ name : 'pub' ,
785
+ tables : [ 'T' ] ,
786
+ } )
772
787
assert . equal ( publication . name , 'pub' )
773
- const { data : alteredPublication } = await axios . patch ( `${ URL } /publications/${ publication . id } ` , { tables : [ 'T' ] } )
788
+ const { data : alteredPublication } = await axios . patch (
789
+ `${ URL } /publications/${ publication . id } ` ,
790
+ { tables : [ 'T' ] }
791
+ )
774
792
assert . equal ( alteredPublication . name , 'pub' )
775
793
776
794
await axios . delete ( `${ URL } /publications/${ publication . id } ` )
@@ -784,7 +802,7 @@ describe('/publications FOR ALL TABLES', () => {
784
802
publish_insert : true ,
785
803
publish_update : true ,
786
804
publish_delete : true ,
787
- publish_truncate : false
805
+ publish_truncate : false ,
788
806
}
789
807
it ( 'POST' , async ( ) => {
790
808
const { data : newPublication } = await axios . post ( `${ URL } /publications` , publication )
0 commit comments