PHP Classes

File: tests/playwright/helpers.js

Recommend this page to a friend!
  Packages of Matthew Asham   Binkterm PHP   tests/playwright/helpers.js   Download  
File: tests/playwright/helpers.js
Role: Auxiliary data
Content type: text/plain
Description: Auxiliary data
Class: Binkterm PHP
Bulletin board system based on the Web
Author: By
Last change:
Date: 5 days ago
Size: 814 bytes
 

Contents

Class file image Download
/** * Shared test helpers. */ const path = require('path'); const fs = require('fs'); const CSRF_PATH = path.join(__dirname, '.csrf-token.json'); /** * Returns the CSRF token saved during auth setup. * All state-changing API requests (POST/PUT/DELETE) must include this * as the X-CSRF-TOKEN header. */ function getCsrfToken() { if (!fs.existsSync(CSRF_PATH)) { throw new Error('CSRF token file not found ? run the setup project first'); } const data = JSON.parse(fs.readFileSync(CSRF_PATH, 'utf-8')); return data.csrf_token ?? ''; } /** * Returns headers required for state-changing requests. */ function authHeaders() { return { 'X-CSRF-TOKEN': getCsrfToken(), 'Content-Type': 'application/json', }; } module.exports = { getCsrfToken, authHeaders };