@@ -26,25 +26,34 @@ test('custom headers', async () => {
26
26
describe ( 'custom prefer headers with ' , ( ) => {
27
27
test ( 'insert' , async ( ) => {
28
28
const postgrest = new PostgrestClient ( REST_URL , { headers : { Prefer : 'tx=rollback' } } )
29
- const postgrestFilterBuilder = postgrest . from ( 'users' ) . insert ( { username : 'dragarcia' } ) as any
29
+ const postgrestFilterBuilder = postgrest
30
+ . from ( 'users' )
31
+ . insert ( { username : 'dragarcia' } )
32
+ . select ( ) as any
30
33
expect ( postgrestFilterBuilder . headers [ 'Prefer' ] ) . toContain ( 'tx=rollback' )
31
34
expect ( postgrestFilterBuilder . headers [ 'Prefer' ] ) . toContain ( 'return=' )
32
35
} )
33
36
test ( 'update' , async ( ) => {
34
37
const postgrest = new PostgrestClient ( REST_URL , { headers : { Prefer : 'tx=rollback' } } )
35
- const postgrestFilterBuilder = postgrest . from ( 'users' ) . update ( { username : 'dragarcia' } ) as any
38
+ const postgrestFilterBuilder = postgrest
39
+ . from ( 'users' )
40
+ . update ( { username : 'dragarcia' } )
41
+ . select ( ) as any
36
42
expect ( postgrestFilterBuilder . headers [ 'Prefer' ] ) . toContain ( 'tx=rollback' )
37
43
expect ( postgrestFilterBuilder . headers [ 'Prefer' ] ) . toContain ( 'return=' )
38
44
} )
39
45
test ( 'upsert' , async ( ) => {
40
46
const postgrest = new PostgrestClient ( REST_URL , { headers : { Prefer : 'tx=rollback' } } )
41
- const postgrestFilterBuilder = postgrest . from ( 'users' ) . upsert ( { username : 'dragarcia' } ) as any
47
+ const postgrestFilterBuilder = postgrest
48
+ . from ( 'users' )
49
+ . upsert ( { username : 'dragarcia' } )
50
+ . select ( ) as any
42
51
expect ( postgrestFilterBuilder . headers [ 'Prefer' ] ) . toContain ( 'tx=rollback' )
43
52
expect ( postgrestFilterBuilder . headers [ 'Prefer' ] ) . toContain ( 'return=' )
44
53
} )
45
54
test ( 'delete' , async ( ) => {
46
55
const postgrest = new PostgrestClient ( REST_URL , { headers : { Prefer : 'tx=rollback' } } )
47
- const postgrestFilterBuilder = postgrest . from ( 'users' ) . delete ( ) as any
56
+ const postgrestFilterBuilder = postgrest . from ( 'users' ) . delete ( ) . select ( ) as any
48
57
expect ( postgrestFilterBuilder . headers [ 'Prefer' ] ) . toContain ( 'tx=rollback' )
49
58
expect ( postgrestFilterBuilder . headers [ 'Prefer' ] ) . toContain ( 'return=' )
50
59
} )
@@ -65,13 +74,15 @@ test('on_conflict insert', async () => {
65
74
const res = await postgrest
66
75
. from ( 'users' )
67
76
. upsert ( { username : 'dragarcia' } , { onConflict : 'username' } )
77
+ . select ( )
68
78
expect ( res ) . toMatchSnapshot ( )
69
79
} )
70
80
71
81
test ( 'ignoreDuplicates upsert' , async ( ) => {
72
82
const res = await postgrest
73
83
. from ( 'users' )
74
84
. upsert ( { username : 'dragarcia' } , { onConflict : 'username' , ignoreDuplicates : true } )
85
+ . select ( )
75
86
expect ( res ) . toMatchSnapshot ( )
76
87
} )
77
88
@@ -80,6 +91,7 @@ describe('basic insert, update, delete', () => {
80
91
let res = await postgrest
81
92
. from ( 'messages' )
82
93
. insert ( { message : 'foo' , username : 'supabot' , channel_id : 1 } )
94
+ . select ( )
83
95
expect ( res ) . toMatchSnapshot ( )
84
96
85
97
res = await postgrest . from ( 'messages' ) . select ( )
@@ -90,33 +102,41 @@ describe('basic insert, update, delete', () => {
90
102
let res = await postgrest
91
103
. from ( 'messages' )
92
104
. upsert ( { id : 3 , message : 'foo' , username : 'supabot' , channel_id : 2 } )
105
+ . select ( )
93
106
expect ( res ) . toMatchSnapshot ( )
94
107
95
108
res = await postgrest . from ( 'messages' ) . select ( )
96
109
expect ( res ) . toMatchSnapshot ( )
97
110
} )
98
111
99
112
test ( 'bulk insert' , async ( ) => {
100
- let res = await postgrest . from ( 'messages' ) . insert ( [
101
- { message : 'foo' , username : 'supabot' , channel_id : 1 } ,
102
- { message : 'foo' , username : 'supabot' , channel_id : 1 } ,
103
- ] )
113
+ let res = await postgrest
114
+ . from ( 'messages' )
115
+ . insert ( [
116
+ { message : 'foo' , username : 'supabot' , channel_id : 1 } ,
117
+ { message : 'foo' , username : 'supabot' , channel_id : 1 } ,
118
+ ] )
119
+ . select ( )
104
120
expect ( res ) . toMatchSnapshot ( )
105
121
106
122
res = await postgrest . from ( 'messages' ) . select ( )
107
123
expect ( res ) . toMatchSnapshot ( )
108
124
} )
109
125
110
126
test ( 'basic update' , async ( ) => {
111
- let res = await postgrest . from ( 'messages' ) . update ( { channel_id : 2 } ) . eq ( 'message' , 'foo' )
127
+ let res = await postgrest
128
+ . from ( 'messages' )
129
+ . update ( { channel_id : 2 } )
130
+ . eq ( 'message' , 'foo' )
131
+ . select ( )
112
132
expect ( res ) . toMatchSnapshot ( )
113
133
114
134
res = await postgrest . from ( 'messages' ) . select ( )
115
135
expect ( res ) . toMatchSnapshot ( )
116
136
} )
117
137
118
138
test ( 'basic delete' , async ( ) => {
119
- let res = await postgrest . from ( 'messages' ) . delete ( ) . eq ( 'message' , 'foo' )
139
+ let res = await postgrest . from ( 'messages' ) . delete ( ) . eq ( 'message' , 'foo' ) . select ( )
120
140
expect ( res ) . toMatchSnapshot ( )
121
141
122
142
res = await postgrest . from ( 'messages' ) . select ( )
@@ -249,9 +269,7 @@ test('allow ordering on JSON column', async () => {
249
269
} )
250
270
251
271
test ( 'Prefer: return=minimal' , async ( ) => {
252
- const { data } = await postgrest
253
- . from ( 'users' )
254
- . insert ( { username : 'bar' } , { returning : 'minimal' } )
272
+ const { data } = await postgrest . from ( 'users' ) . insert ( { username : 'bar' } )
255
273
expect ( data ) . toMatchSnapshot ( )
256
274
257
275
await postgrest . from ( 'users' ) . delete ( ) . eq ( 'username' , 'bar' )
@@ -305,6 +323,7 @@ describe("insert, update, delete with count: 'exact'", () => {
305
323
let res = await postgrest
306
324
. from ( 'messages' )
307
325
. insert ( { message : 'foo' , username : 'supabot' , channel_id : 1 } , { count : 'exact' } )
326
+ . select ( )
308
327
expect ( res ) . toMatchSnapshot ( )
309
328
310
329
res = await postgrest . from ( 'messages' ) . select ( )
@@ -315,20 +334,24 @@ describe("insert, update, delete with count: 'exact'", () => {
315
334
let res = await postgrest
316
335
. from ( 'messages' )
317
336
. upsert ( { id : 3 , message : 'foo' , username : 'supabot' , channel_id : 2 } , { count : 'exact' } )
337
+ . select ( )
318
338
expect ( res ) . toMatchSnapshot ( )
319
339
320
340
res = await postgrest . from ( 'messages' ) . select ( )
321
341
expect ( res ) . toMatchSnapshot ( )
322
342
} )
323
343
324
344
test ( "bulk insert with count: 'exact'" , async ( ) => {
325
- let res = await postgrest . from ( 'messages' ) . insert (
326
- [
327
- { message : 'foo' , username : 'supabot' , channel_id : 1 } ,
328
- { message : 'foo' , username : 'supabot' , channel_id : 1 } ,
329
- ] ,
330
- { count : 'exact' }
331
- )
345
+ let res = await postgrest
346
+ . from ( 'messages' )
347
+ . insert (
348
+ [
349
+ { message : 'foo' , username : 'supabot' , channel_id : 1 } ,
350
+ { message : 'foo' , username : 'supabot' , channel_id : 1 } ,
351
+ ] ,
352
+ { count : 'exact' }
353
+ )
354
+ . select ( )
332
355
expect ( res ) . toMatchSnapshot ( )
333
356
334
357
res = await postgrest . from ( 'messages' ) . select ( )
@@ -340,14 +363,19 @@ describe("insert, update, delete with count: 'exact'", () => {
340
363
. from ( 'messages' )
341
364
. update ( { channel_id : 2 } , { count : 'exact' } )
342
365
. eq ( 'message' , 'foo' )
366
+ . select ( )
343
367
expect ( res ) . toMatchSnapshot ( )
344
368
345
369
res = await postgrest . from ( 'messages' ) . select ( )
346
370
expect ( res ) . toMatchSnapshot ( )
347
371
} )
348
372
349
373
test ( "basic delete count: 'exact'" , async ( ) => {
350
- let res = await postgrest . from ( 'messages' ) . delete ( { count : 'exact' } ) . eq ( 'message' , 'foo' )
374
+ let res = await postgrest
375
+ . from ( 'messages' )
376
+ . delete ( { count : 'exact' } )
377
+ . eq ( 'message' , 'foo' )
378
+ . select ( )
351
379
expect ( res ) . toMatchSnapshot ( )
352
380
353
381
res = await postgrest . from ( 'messages' ) . select ( )
0 commit comments