27 lines
1.2 KiB
TypeScript
27 lines
1.2 KiB
TypeScript
// SPDX-License-Identifier: LicenseRef-ConusAI-Template-1.0
|
|
// Two people's first paints, one server process. `useCan` caches a person's grants on the data client, so
|
|
// a client shared across renders would answer the second person with the first person's grants.
|
|
|
|
import { Can } from "@conusai-kit/ui/data"
|
|
import { createElement } from "react"
|
|
import { renderToString } from "react-dom/server"
|
|
import { describe, expect, it } from "vitest"
|
|
import { AppTransport } from "../apps/web/src/ui/transport.js"
|
|
|
|
const scope = { org: "acme", workspace: "main" }
|
|
const firstPaint = (permissions: readonly `${string}.${string}.${string}`[]): string =>
|
|
renderToString(
|
|
createElement(AppTransport, {
|
|
permissions: { scope, seed: { scope, permissions: [...permissions], revision: "1" } },
|
|
children: createElement(Can, { permission: "notes.note.write", fallback: "reads only", children: "writes" }),
|
|
}),
|
|
)
|
|
|
|
describe("a server render's permissions", () => {
|
|
it("are the person's own, whoever the same process rendered first", () => {
|
|
expect(firstPaint(["notes.note.write"])).toContain("writes")
|
|
expect(firstPaint([])).toContain("reads only")
|
|
expect(firstPaint(["notes.note.write"])).toContain("writes")
|
|
})
|
|
})
|