Files
puter/src/backend/testUtil.test.ts
T
Daniel Salazar 52e481128f
Maintain Release Merge PR / update-release-pr (push) Has been cancelled
Notify HeyPuter / notify (push) Has been cancelled
release-please / release-please (push) Has been cancelled
wip: puter js tests structure (#3393)
2026-07-15 19:09:35 -07:00

42 lines
1.7 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import { setupPuterTestEnv } from './testUtil.ts';
// Exercises the client-facing test environment: a real HTTP listener on an
// ephemeral port, deterministic seeded users, and both auth paths clients
// use (pre-minted session token, and a real password login).
describe('setupPuterTestEnv', () => {
it('boots a reachable server with working credentials', async () => {
const env = await setupPuterTestEnv();
try {
const who = await fetch(`${env.apiOrigin}/whoami`, {
headers: {
Authorization: `Bearer ${env.users.user.token}`,
Origin: env.apiOrigin,
},
});
expect(who.status).toBe(200);
const whoBody = (await who.json()) as { username: string };
expect(whoBody.username).toBe(env.users.user.username);
// /login is a root-only route — it lives on the root origin,
// not the api subdomain.
const login = await fetch(`${env.origin}/login`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Origin: env.origin,
},
body: JSON.stringify({
username: env.users.admin.username,
password: env.users.admin.password,
}),
});
expect(login.status).toBe(200);
const loginBody = (await login.json()) as { token?: string };
expect(loginBody.token).toBeTruthy();
} finally {
await env.shutdown();
}
}, 120_000);
});