@@ -16,17 +16,40 @@ test('it should throw an error if no valid params are provided', async () => {
16
16
expect ( ( ) => createClient ( URL , '' ) ) . toThrowError ( 'supabaseKey is required.' )
17
17
} )
18
18
19
- describe ( 'Custom Headers' , ( ) => {
20
- const customHeader = { 'X-Test-Header' : 'value' }
19
+ test ( 'it should not cache Authorization header' , async ( ) => {
20
+ const checkHeadersSpy = jest . spyOn ( SupabaseClient . prototype as any , '_getAuthHeaders' )
21
+
22
+ supabase . auth . setAuth ( 'token1' )
23
+ supabase . rpc ( '' ) // Calling public method `rpc` calls private method _getAuthHeaders which result we want to test
24
+ supabase . auth . setAuth ( 'token2' )
25
+ supabase . rpc ( '' ) // Calling public method `rpc` calls private method _getAuthHeaders which result we want to test
26
+
27
+ expect ( checkHeadersSpy . mock . results [ 0 ] . value ) . toHaveProperty ( 'Authorization' , 'Bearer token1' )
28
+ expect ( checkHeadersSpy . mock . results [ 1 ] . value ) . toHaveProperty ( 'Authorization' , 'Bearer token2' )
29
+ } )
21
30
31
+ describe ( 'Custom Headers' , ( ) => {
22
32
test ( 'should have custom header set' , ( ) => {
33
+ const customHeader = { 'X-Test-Header' : 'value' }
34
+
23
35
const checkHeadersSpy = jest . spyOn ( SupabaseClient . prototype as any , '_getAuthHeaders' )
24
36
createClient ( URL , KEY , { headers : customHeader } ) . rpc ( '' ) // Calling public method `rpc` calls private method _getAuthHeaders which result we want to test
25
37
const getHeaders = checkHeadersSpy . mock . results [ 0 ] . value
26
38
27
39
expect ( checkHeadersSpy ) . toBeCalled ( )
28
40
expect ( getHeaders ) . toHaveProperty ( 'X-Test-Header' , 'value' )
29
41
} )
42
+
43
+ test ( 'should allow custom Authorization header' , ( ) => {
44
+ const customHeader = { Authorization : 'Bearer custom_token' }
45
+ supabase . auth . setAuth ( 'override_me' )
46
+ const checkHeadersSpy = jest . spyOn ( SupabaseClient . prototype as any , '_getAuthHeaders' )
47
+ createClient ( URL , KEY , { headers : customHeader } ) . rpc ( '' ) // Calling public method `rpc` calls private method _getAuthHeaders which result we want to test
48
+ const getHeaders = checkHeadersSpy . mock . results [ 0 ] . value
49
+
50
+ expect ( checkHeadersSpy ) . toBeCalled ( )
51
+ expect ( getHeaders ) . toHaveProperty ( 'Authorization' , 'Bearer custom_token' )
52
+ } )
30
53
} )
31
54
32
55
// Socket should close when there are no open connections
0 commit comments