fix layout SSR translations and remediation follow-ups
This commit is contained in:
@@ -60,10 +60,14 @@ describe("full app", () => {
|
||||
});
|
||||
afterAll(() => app?.close());
|
||||
|
||||
test("home page responds with HTML", async () => {
|
||||
test("home page server-renders translated page and layout text", async () => {
|
||||
const res = await app.fetch("/");
|
||||
expect(res.status).toBe(200);
|
||||
expect(res.headers.get("content-type")).toContain("text/html");
|
||||
const html = await res.text();
|
||||
expect(html).toContain('<span data-t="nav.home">Home</span>');
|
||||
expect(html).toContain('<span data-t="home.title">Hello from WrNexus</span>');
|
||||
expect(html).not.toContain('<span data-t="nav.home"></span>');
|
||||
});
|
||||
|
||||
test("GET /api/hello returns a translated greeting", async () => {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { afterEach, expect, test } from "bun:test";
|
||||
import { implement } from "../../../../../packages/rpc/src/index.ts";
|
||||
import { handleRpcRequest } from "../../../../../packages/dev-server/src/rpc-dispatch.ts";
|
||||
import { catalogService } from "../../../packages/shared/src/index.ts";
|
||||
import catalogServiceImplementation from "../../admin/app/services/catalog.ts";
|
||||
import { GET } from "../app/api/product.ts";
|
||||
|
||||
const secret = process.env.WRNEXUS_RPC_SECRET;
|
||||
@@ -16,23 +15,17 @@ afterEach(() => {
|
||||
else process.env.WRNEXUS_INTERNAL_ORIGINS = origins;
|
||||
});
|
||||
|
||||
function startAdmin(allowed: boolean) {
|
||||
const service = implement(
|
||||
catalogService,
|
||||
{ getProduct: ({ sku }) => ({ sku, name: "WRNexus Starter", priceCents: 4900 }) },
|
||||
{
|
||||
selfApp: "admin",
|
||||
checkPermission: (permission, subject) =>
|
||||
allowed && permission === "catalog:read" && subject?.subjectId === "demo-user",
|
||||
},
|
||||
);
|
||||
function startAdmin() {
|
||||
return Bun.serve({
|
||||
port: 0,
|
||||
hostname: "127.0.0.1",
|
||||
async fetch(request) {
|
||||
return (
|
||||
(await handleRpcRequest(request, new URL(request.url), new Map([["catalog", service]]))) ??
|
||||
new Response("Not found", { status: 404 })
|
||||
(await handleRpcRequest(
|
||||
request,
|
||||
new URL(request.url),
|
||||
new Map([["catalog", catalogServiceImplementation]]),
|
||||
)) ?? new Response("Not found", { status: 404 })
|
||||
);
|
||||
},
|
||||
});
|
||||
@@ -41,7 +34,7 @@ function startAdmin(allowed: boolean) {
|
||||
test("web calls admin through private RPC when permitted", async () => {
|
||||
process.env.WRNEXUS_RPC_SECRET = "test-rpc-secret-at-least-32-chars-long";
|
||||
process.env.WRNEXUS_APP_NAME = "web";
|
||||
const server = startAdmin(true);
|
||||
const server = startAdmin();
|
||||
process.env.WRNEXUS_INTERNAL_ORIGINS = JSON.stringify({
|
||||
admin: `http://127.0.0.1:${server.port}`,
|
||||
});
|
||||
@@ -62,7 +55,7 @@ test("web calls admin through private RPC when permitted", async () => {
|
||||
test("web returns 403 when admin denies catalog:read", async () => {
|
||||
process.env.WRNEXUS_RPC_SECRET = "test-rpc-secret-at-least-32-chars-long";
|
||||
process.env.WRNEXUS_APP_NAME = "web";
|
||||
const server = startAdmin(false);
|
||||
const server = startAdmin();
|
||||
process.env.WRNEXUS_INTERNAL_ORIGINS = JSON.stringify({
|
||||
admin: `http://127.0.0.1:${server.port}`,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user