@@ -23,6 +23,33 @@ test('custom headers', async () => {
23
23
expect ( ( postgrest . from ( 'users' ) . select ( ) as any ) . headers [ 'apikey' ] ) . toEqual ( 'foo' )
24
24
} )
25
25
26
+ describe ( 'custom prefer headers with ' , ( ) => {
27
+ test ( 'insert' , async ( ) => {
28
+ const postgrest = new PostgrestClient ( REST_URL , { headers : { Prefer : 'tx=rollback' } } )
29
+ const postgrestFilterBuilder = postgrest . from ( 'users' ) . insert ( { username : 'dragarcia' } ) as any
30
+ expect ( postgrestFilterBuilder . headers [ 'Prefer' ] ) . toContain ( 'tx=rollback' )
31
+ expect ( postgrestFilterBuilder . headers [ 'Prefer' ] ) . toContain ( 'return=' )
32
+ } )
33
+ test ( 'update' , async ( ) => {
34
+ const postgrest = new PostgrestClient ( REST_URL , { headers : { Prefer : 'tx=rollback' } } )
35
+ const postgrestFilterBuilder = postgrest . from ( 'users' ) . update ( { username : 'dragarcia' } ) as any
36
+ expect ( postgrestFilterBuilder . headers [ 'Prefer' ] ) . toContain ( 'tx=rollback' )
37
+ expect ( postgrestFilterBuilder . headers [ 'Prefer' ] ) . toContain ( 'return=' )
38
+ } )
39
+ test ( 'upsert' , async ( ) => {
40
+ const postgrest = new PostgrestClient ( REST_URL , { headers : { Prefer : 'tx=rollback' } } )
41
+ const postgrestFilterBuilder = postgrest . from ( 'users' ) . upsert ( { username : 'dragarcia' } ) as any
42
+ expect ( postgrestFilterBuilder . headers [ 'Prefer' ] ) . toContain ( 'tx=rollback' )
43
+ expect ( postgrestFilterBuilder . headers [ 'Prefer' ] ) . toContain ( 'return=' )
44
+ } )
45
+ test ( 'delete' , async ( ) => {
46
+ const postgrest = new PostgrestClient ( REST_URL , { headers : { Prefer : 'tx=rollback' } } )
47
+ const postgrestFilterBuilder = postgrest . from ( 'users' ) . delete ( ) as any
48
+ expect ( postgrestFilterBuilder . headers [ 'Prefer' ] ) . toContain ( 'tx=rollback' )
49
+ expect ( postgrestFilterBuilder . headers [ 'Prefer' ] ) . toContain ( 'return=' )
50
+ } )
51
+ } )
52
+
26
53
test ( 'auth' , async ( ) => {
27
54
const postgrest = new PostgrestClient ( REST_URL ) . auth ( 'foo' )
28
55
expect ( ( postgrest . from ( 'users' ) . select ( ) as any ) . headers [ 'Authorization' ] ) . toEqual ( 'Bearer foo' )
0 commit comments