import { createHash } from 'node:crypto'; import { fileURLToPath } from 'node:url'; import { dirname, join } from 'node:path'; import { migrate, openD1 } from '../tools/d1-local.mjs'; import { handle } from '../src/api.js'; const root = join(dirname(fileURLToPath(import.meta.url)), '..'); // A curator session, as if the curator had signed in with a passkey. People only sign in with passkeys. export const ADMIN = 'jl_session_test-curator-session-0123456789abcdef'; export function makeEnv(extra = {}) { const DB = migrate(openD1(), join(root, 'migrations')); DB.raw.prepare(`INSERT INTO sessions (token_hash, role, user_id, created_at, expires_at) VALUES (?, 'curator', 'curator', ?, '9999-12-31T00:00:00.000Z')`) .run(createHash('sha256').update(ADMIN).digest('hex'), new Date().toISOString()); return { DB, ALLOW_NO_TURNSTILE: '1', ...extra }; } export async function call(env, method, path, { body, token, client, ip = '203.0.113.7', headers = {} } = {}) { const h = { ...headers, 'cf-connecting-ip': ip }; if (body !== undefined) h['content-type'] = 'application/json'; if (token) h.authorization = `Bearer ${token}`; if (client) h['x-client'] = client; const res = await handle(new Request(`https://jobley.test${path}`, { method, headers: h, body: body === undefined ? undefined : typeof body === 'string' ? body : JSON.stringify(body) }), env); const text = await res.text(); let data = null; try { data = JSON.parse(text); } catch { /* not json */ } return { status: res.status, data, headers: res.headers }; } export const JOB = { title: 'Support Engineer', company: 'Fernhollow Tools', company_url: 'https://fernhollow.example', location: 'United States', workplace: 'remote', employment_type: 'full_time', category: 'support', pay_min: 210000, pay_max: 240000, pay_period: 'year', description: 'Help the people who use our scheduling tools. You will answer questions, write the help pages and work with the engineers on fixes. Sample text for tests.', apply_url: 'https://fernhollow.example/jobs/support-engineer', contact_name: 'Rowan Vale', contact_email: 'rowan@fernhollow.example', }; export const CANDIDATE = { name: 'Mika Okafor', email: 'Mika@Example.org', location: 'Lisbon', headline: 'Support engineer, six years', looking_for: 'Remote support or success roles at small product teams.', about: 'I like untangling hard tickets.', links: ['https://example.org/mika'], resume_url: 'https://example.org/mika/resume.pdf', consent: true, }; export const MODERATOR = { name: 'Jo Lindqvist', email: 'jo@example.org', timezone: 'Europe/Stockholm', hours_per_week: 3, why: 'I have hired for small teams for years and I know what a misleading post looks like.', experience: 'Ran hiring at two small studios.', links: ['https://example.org/jo'], agree: true, };