2025-04-17 17:44:11 +08:00
|
|
|
import { StaticPage, StaticPageAgent } from '@/playground';
|
2024-10-28 11:04:40 +08:00
|
|
|
import PlaygroundServer from '@/playground/server';
|
2025-01-26 16:49:32 +08:00
|
|
|
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
|
2024-10-21 16:30:07 +08:00
|
|
|
|
|
|
|
describe('Playground Server', () => {
|
|
|
|
let server: PlaygroundServer;
|
|
|
|
let serverBase: string;
|
|
|
|
beforeAll(async () => {
|
2025-04-17 17:44:11 +08:00
|
|
|
server = new PlaygroundServer(StaticPage, StaticPageAgent);
|
2024-10-21 16:30:07 +08:00
|
|
|
await server.launch();
|
|
|
|
serverBase = `http://localhost:${server.port}`;
|
|
|
|
});
|
|
|
|
|
|
|
|
afterAll(async () => {
|
|
|
|
await server.close();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('post context', async () => {
|
|
|
|
const contextValue = 'bar';
|
|
|
|
const res = await fetch(`${serverBase}/playground-with-context`, {
|
|
|
|
method: 'POST',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
},
|
|
|
|
body: JSON.stringify({
|
|
|
|
context: contextValue,
|
|
|
|
}),
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(res.status).toBe(200);
|
|
|
|
const data = await res.json();
|
|
|
|
const contextId = data.uuid;
|
|
|
|
|
|
|
|
// retrieve context
|
|
|
|
const contextRes = await fetch(`${serverBase}/context/${contextId}`);
|
|
|
|
const context = await contextRes.json();
|
|
|
|
expect(context).toBeDefined();
|
|
|
|
expect(context.context).toBe(contextValue);
|
|
|
|
});
|
|
|
|
});
|