mirror of
https://github.com/alkimake/paperclip.git
synced 2026-06-16 02:40:39 +09:00
43 lines
1.5 KiB
TypeScript
43 lines
1.5 KiB
TypeScript
|
|
import { describe, expect, it, vi } from "vitest";
|
||
|
|
import { createHostClientHandlers } from "../../../packages/plugins/sdk/src/host-client-factory.js";
|
||
|
|
|
||
|
|
describe("plugin config bridge scoping", () => {
|
||
|
|
it("falls back to the invocation company scope for config.get when the worker omits companyId", async () => {
|
||
|
|
const getConfig = vi.fn(async (params: { companyId?: string | null }) => ({
|
||
|
|
scope: params.companyId ?? null,
|
||
|
|
}));
|
||
|
|
|
||
|
|
const handlers = createHostClientHandlers({
|
||
|
|
pluginId: "test.plugin",
|
||
|
|
capabilities: [],
|
||
|
|
services: {
|
||
|
|
config: { get: getConfig },
|
||
|
|
} as never,
|
||
|
|
});
|
||
|
|
|
||
|
|
await expect(
|
||
|
|
handlers["config.get"]({}, { invocationScope: { companyId: "company-a" } }),
|
||
|
|
).resolves.toEqual({ scope: "company-a" });
|
||
|
|
expect(getConfig).toHaveBeenCalledWith({ companyId: "company-a" });
|
||
|
|
});
|
||
|
|
|
||
|
|
it("preserves an explicit global config.get request even inside a company-scoped invocation", async () => {
|
||
|
|
const getConfig = vi.fn(async (params: { companyId?: string | null }) => ({
|
||
|
|
scope: params.companyId ?? null,
|
||
|
|
}));
|
||
|
|
|
||
|
|
const handlers = createHostClientHandlers({
|
||
|
|
pluginId: "test.plugin",
|
||
|
|
capabilities: [],
|
||
|
|
services: {
|
||
|
|
config: { get: getConfig },
|
||
|
|
} as never,
|
||
|
|
});
|
||
|
|
|
||
|
|
await expect(
|
||
|
|
handlers["config.get"]({ companyId: null }, { invocationScope: { companyId: "company-a" } }),
|
||
|
|
).resolves.toEqual({ scope: null });
|
||
|
|
expect(getConfig).toHaveBeenCalledWith({ companyId: null });
|
||
|
|
});
|
||
|
|
});
|