@@ -65,13 +65,10 @@ async function createApiToken(page: Page): Promise<string> {
6565 throw new Error ( 'Failed to create API token after retries' ) ;
6666}
6767
68- function buildAuthHeaders ( token : string , xsrfToken : string ) : Record < string , string > {
68+ function bearerHeaders ( token : string ) : Record < string , string > {
6969 return {
7070 Accept : 'application/json' ,
7171 Authorization : `Bearer ${ token } ` ,
72- // XSRF header is needed for web routes (e.g. PUT /teams) that go through
73- // VerifyCsrfToken middleware. API routes ignore it but it doesn't hurt.
74- ...( xsrfToken ? { 'X-XSRF-TOKEN' : xsrfToken } : { } ) ,
7572 } ;
7673}
7774
@@ -82,11 +79,7 @@ function buildAuthHeaders(token: string, xsrfToken: string): Record<string, stri
8279export async function setupTestContext ( page : Page ) : Promise < TestContext > {
8380 const token = await createApiToken ( page ) ;
8481 const request = page . request ;
85-
86- const cookies = await page . context ( ) . cookies ( ) ;
87- const xsrfCookie = cookies . find ( ( c ) => c . name === 'XSRF-TOKEN' ) ;
88- const xsrfToken = xsrfCookie ? decodeURIComponent ( xsrfCookie . value ) : '' ;
89- const headers = buildAuthHeaders ( token , xsrfToken ) ;
82+ const headers = bearerHeaders ( token ) ;
9083
9184 const orgId = await getOrganizationId ( request , headers ) ;
9285 const memberId = await getCurrentMemberId ( request , orgId , headers ) ;
@@ -547,11 +540,17 @@ export async function updateOrganizationSettingViaApi(
547540}
548541
549542export async function updateOrganizationCurrencyViaWeb (
543+ page : Page ,
550544 ctx : TestContext ,
551545 currency : string ,
552546 name : string = 'Test Organization'
553547) {
554- const response = await ctx . request . put ( `${ PLAYWRIGHT_BASE_URL } /teams/${ ctx . orgId } ` , {
548+ const cookies = await page . context ( ) . cookies ( ) ;
549+ const xsrfCookie = cookies . find ( ( c ) => c . name === 'XSRF-TOKEN' ) ;
550+ const xsrfToken = xsrfCookie ? decodeURIComponent ( xsrfCookie . value ) : '' ;
551+
552+ const response = await page . request . put ( `${ PLAYWRIGHT_BASE_URL } /teams/${ ctx . orgId } ` , {
553+ headers : { 'X-XSRF-TOKEN' : xsrfToken } ,
555554 data : { name, currency } ,
556555 } ) ;
557556 expect ( response . status ( ) ) . toBe ( 200 ) ;
0 commit comments