11process . env . LOG_SCOPE = 'pgsql-test' ;
22
33import { getConnections } from '../src/connect' ;
4+ import { getRoleName } from '../src/roles' ;
45import { PgTestClient } from '../src/test-client' ;
56
67let db : PgTestClient ;
@@ -25,14 +26,16 @@ describe('anonymous', () => {
2526
2627 it ( 'runs under anonymous context' , async ( ) => {
2728 const result = await db . query ( 'SELECT current_setting(\'role\', true) AS role' ) ;
28- expect ( result . rows [ 0 ] . role ) . toBe ( 'anonymous' ) ;
29+ const expectedRole = getRoleName ( 'anonymous' ) ;
30+ expect ( result . rows [ 0 ] . role ) . toBe ( expectedRole ) ;
2931 } ) ;
3032} ) ;
3133
3234describe ( 'authenticated' , ( ) => {
3335 beforeEach ( async ( ) => {
36+ const authRole = getRoleName ( 'authenticated' ) ;
3437 db . setContext ( {
35- role : 'authenticated' ,
38+ role : authRole ,
3639 'jwt.claims.user_agent' : 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36' ,
3740 'jwt.claims.ip_address' : '127.0.0.1' ,
3841 'jwt.claims.database_id' : 'jwt.database_id' ,
@@ -47,7 +50,8 @@ describe('authenticated', () => {
4750
4851 it ( 'runs under authenticated context' , async ( ) => {
4952 const role = await db . query ( 'SELECT current_setting(\'role\', true) AS role' ) ;
50- expect ( role . rows [ 0 ] . role ) . toBe ( 'authenticated' ) ;
53+ const expectedRole = getRoleName ( 'authenticated' ) ;
54+ expect ( role . rows [ 0 ] . role ) . toBe ( expectedRole ) ;
5155 const ip = await db . query ( 'SELECT current_setting(\'jwt.claims.ip_address\', true) AS role' ) ;
5256 expect ( ip . rows [ 0 ] . role ) . toBe ( '127.0.0.1' ) ;
5357 } ) ;
0 commit comments