test: add unit tests for buildAllowAttribute (#541)

This commit is contained in:
Suriya Prakash 2026-04-24 16:06:00 +05:30 • committed by GitHub
commit 0f6d653b4a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -18,6 +18,7 @@ import { App } from "./app";
import { LATEST_PROTOCOL_VERSION } from "./types";
import {
AppBridge,
buildAllowAttribute,
getToolUiResourceUri,
isToolVisibilityModelOnly,
isToolVisibilityAppOnly,
@ -2786,3 +2787,54 @@ describe("isToolVisibilityAppOnly", () => {
});
});
});
describe("buildAllowAttribute", () => {
describe("returns empty string", () => {
it("when permissions is undefined", () => {
expect(buildAllowAttribute(undefined)).toBe("");
});
it("when permissions object is empty", () => {
expect(buildAllowAttribute({})).toBe("");
});
});
describe("returns a single permission directive", () => {
it("when only camera is set", () => {
expect(buildAllowAttribute({ camera: {} })).toBe("camera");
});
it("when only microphone is set", () => {
expect(buildAllowAttribute({ microphone: {} })).toBe("microphone");
});
it("when only geolocation is set", () => {
expect(buildAllowAttribute({ geolocation: {} })).toBe("geolocation");
});
it("when only clipboardWrite is set, maps to clipboard-write", () => {
expect(buildAllowAttribute({ clipboardWrite: {} })).toBe(
"clipboard-write",
);
});
});
describe("returns multiple directives joined with '; '", () => {
it("when camera and microphone are set", () => {
expect(buildAllowAttribute({ camera: {}, microphone: {} })).toBe(
"camera; microphone",
);
});
it("when all permissions are set", () => {
expect(
buildAllowAttribute({
camera: {},
microphone: {},
geolocation: {},
clipboardWrite: {},
}),
).toBe("camera; microphone; geolocation; clipboard-write");
});
});
});