mirror of
https://github.com/HeyPuter/puter.git
synced 2026-05-27 20:01:35 +00:00
594cbe03ef
- Strengthen Broadcast tests - strengthen oidc tests - add middleware tests - add extensions test - add puter hosting tests - add Chat Completion Driver tests
42 lines
1.3 KiB
TypeScript
42 lines
1.3 KiB
TypeScript
import type { Request, Response } from 'express';
|
|
import { describe, expect, it, vi } from 'vitest';
|
|
import { handleWorkerSandboxPage } from './workerSandbox.ts';
|
|
|
|
interface CapturedResponse {
|
|
contentType: string | undefined;
|
|
body: string | undefined;
|
|
}
|
|
|
|
const makeRes = () => {
|
|
const captured: CapturedResponse = {
|
|
contentType: undefined,
|
|
body: undefined,
|
|
};
|
|
const res = {
|
|
type: vi.fn((mime: string) => {
|
|
captured.contentType = mime;
|
|
return res;
|
|
}),
|
|
send: vi.fn((value: string) => {
|
|
captured.body = value;
|
|
return res;
|
|
}),
|
|
};
|
|
return { res: res as unknown as Response, captured };
|
|
};
|
|
|
|
describe('workerSandbox extension — handleWorkerSandboxPage', () => {
|
|
it('sends the playground HTML page with text/html content type', () => {
|
|
const { res, captured } = makeRes();
|
|
|
|
handleWorkerSandboxPage({} as Request, res);
|
|
|
|
expect(captured.contentType).toBe('html');
|
|
expect(typeof captured.body).toBe('string');
|
|
expect(captured.body).toContain('<!doctype html>');
|
|
expect(captured.body).toContain('Puter Worker Sandbox Playground');
|
|
// The page is meant to load the public puter SDK
|
|
expect(captured.body).toContain('https://js.puter.com/v2/');
|
|
});
|
|
});
|