mirror of
https://github.com/wahyd4/heygo.git
synced 2026-08-09 05:15:52 +10:00
40 lines
1.2 KiB
TypeScript
40 lines
1.2 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 };
|
|
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' });
|
|
});
|
|
});
|