mirror of
https://github.com/wahyd4/heygo.git
synced 2026-08-09 05:15:52 +10:00
- Terraform configs for D1 databases, KV namespaces, Worker custom domains - wrangler.dev.jsonc and wrangler.prod.jsonc for environment-specific deployments - Worker code refactored to use env vars for host checking (PUBLIC_HOST, PRIVATE_HOST) - Configurable app URLs and cookie domain via env vars - Deploy and migrate npm scripts for dev/prod - Updated all tests with new env fixtures - Deployment guide in README
46 lines
1.3 KiB
TypeScript
46 lines
1.3 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import worker from '../worker/index';
|
|
|
|
class FakeExecutionContext {
|
|
waitUntil(): void {}
|
|
passThroughOnException(): void {}
|
|
}
|
|
|
|
function fetchWorker(path: string) {
|
|
const request = new Request(`https://heygo.test${path}`);
|
|
const env = {
|
|
DB: {} as D1Database,
|
|
PUBLIC_HOST: 'heygo.cc',
|
|
PRIVATE_HOST: 'my.heygo.cc',
|
|
APP_BASE_URL: 'https://heygo.cc',
|
|
COOKIE_DOMAIN: '.heygo.cc',
|
|
};
|
|
const ctx = new FakeExecutionContext();
|
|
|
|
return worker.fetch(
|
|
request as unknown as Parameters<typeof worker.fetch>[0],
|
|
env as unknown as Parameters<typeof worker.fetch>[1],
|
|
ctx as unknown as Parameters<typeof worker.fetch>[2],
|
|
);
|
|
}
|
|
|
|
describe('worker API scaffold', () => {
|
|
it('responds to the health endpoint', async () => {
|
|
const response = await fetchWorker('/api/health');
|
|
|
|
expect(response.status).toBe(200);
|
|
expect(response.headers.get('content-type')).toContain('application/json');
|
|
await expect(response.json()).resolves.toEqual({
|
|
ok: true,
|
|
service: 'heygo-worker',
|
|
});
|
|
});
|
|
|
|
it('returns 404 JSON for unknown API routes', async () => {
|
|
const response = await fetchWorker('/api/missing');
|
|
|
|
expect(response.status).toBe(404);
|
|
await expect(response.json()).resolves.toEqual({ error: 'Not found' });
|
|
});
|
|
});
|