@@ -18,6 +18,7 @@ import { App } from "./app";
1818import { LATEST_PROTOCOL_VERSION } from "./types" ;
1919import {
2020 AppBridge ,
21+ buildAllowAttribute ,
2122 getToolUiResourceUri ,
2223 isToolVisibilityModelOnly ,
2324 isToolVisibilityAppOnly ,
@@ -2786,3 +2787,54 @@ describe("isToolVisibilityAppOnly", () => {
27862787 } ) ;
27872788 } ) ;
27882789} ) ;
2790+
2791+ describe ( "buildAllowAttribute" , ( ) => {
2792+ describe ( "returns empty string" , ( ) => {
2793+ it ( "when permissions is undefined" , ( ) => {
2794+ expect ( buildAllowAttribute ( undefined ) ) . toBe ( "" ) ;
2795+ } ) ;
2796+
2797+ it ( "when permissions object is empty" , ( ) => {
2798+ expect ( buildAllowAttribute ( { } ) ) . toBe ( "" ) ;
2799+ } ) ;
2800+ } ) ;
2801+
2802+ describe ( "returns a single permission directive" , ( ) => {
2803+ it ( "when only camera is set" , ( ) => {
2804+ expect ( buildAllowAttribute ( { camera : { } } ) ) . toBe ( "camera" ) ;
2805+ } ) ;
2806+
2807+ it ( "when only microphone is set" , ( ) => {
2808+ expect ( buildAllowAttribute ( { microphone : { } } ) ) . toBe ( "microphone" ) ;
2809+ } ) ;
2810+
2811+ it ( "when only geolocation is set" , ( ) => {
2812+ expect ( buildAllowAttribute ( { geolocation : { } } ) ) . toBe ( "geolocation" ) ;
2813+ } ) ;
2814+
2815+ it ( "when only clipboardWrite is set, maps to clipboard-write" , ( ) => {
2816+ expect ( buildAllowAttribute ( { clipboardWrite : { } } ) ) . toBe (
2817+ "clipboard-write" ,
2818+ ) ;
2819+ } ) ;
2820+ } ) ;
2821+
2822+ describe ( "returns multiple directives joined with '; '" , ( ) => {
2823+ it ( "when camera and microphone are set" , ( ) => {
2824+ expect ( buildAllowAttribute ( { camera : { } , microphone : { } } ) ) . toBe (
2825+ "camera; microphone" ,
2826+ ) ;
2827+ } ) ;
2828+
2829+ it ( "when all permissions are set" , ( ) => {
2830+ expect (
2831+ buildAllowAttribute ( {
2832+ camera : { } ,
2833+ microphone : { } ,
2834+ geolocation : { } ,
2835+ clipboardWrite : { } ,
2836+ } ) ,
2837+ ) . toBe ( "camera; microphone; geolocation; clipboard-write" ) ;
2838+ } ) ;
2839+ } ) ;
2840+ } ) ;
0 commit comments