perf(web): batch dashboard tile hydration
This commit is contained in:
parent
63b008095f
commit
de87464ef1
7 changed files with 518 additions and 40 deletions
53
apps/web/src/server/index.test.ts
Normal file
53
apps/web/src/server/index.test.ts
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
import { afterAll, describe, expect, test, vi } from "vitest";
|
||||
import { handleRequest } from "./index";
|
||||
|
||||
describe("server request routing", () => {
|
||||
const consoleInfo = vi.spyOn(console, "info").mockImplementation(() => undefined);
|
||||
|
||||
afterAll(() => {
|
||||
consoleInfo.mockRestore();
|
||||
});
|
||||
|
||||
test("routes dashboard tile batch requests", async () => {
|
||||
const response = await handleRequest(
|
||||
new Request("https://example.test/api/dashboard/tiles", {
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
tiles: [
|
||||
{
|
||||
kind: "status",
|
||||
stripId: "footer-status",
|
||||
id: "auto-refresh",
|
||||
},
|
||||
],
|
||||
}),
|
||||
}),
|
||||
);
|
||||
|
||||
expect(response.status).toBe(200);
|
||||
await expect(response.json()).resolves.toMatchObject({
|
||||
state: "ready",
|
||||
tiles: [
|
||||
{
|
||||
state: "ready",
|
||||
tile: {
|
||||
kind: "status",
|
||||
stripId: "footer-status",
|
||||
id: "auto-refresh",
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
test("rejects non-post dashboard tile batch requests", async () => {
|
||||
const response = await handleRequest(
|
||||
new Request("https://example.test/api/dashboard/tiles", {
|
||||
method: "GET",
|
||||
}),
|
||||
);
|
||||
|
||||
expect(response.status).toBe(405);
|
||||
expect(response.headers.get("allow")).toBe("POST");
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue