@@ -244,4 +244,120 @@ describe("checkWritePermissions", () => {
244244 "Failed to check permissions for test-user:" ,
245245 ) ;
246246 } ) ;
247+
248+ test ( "should grant write permissions to users with admin access" , async ( ) => {
249+ const mockOctokit = {
250+ users : {
251+ getByUsername : async ( ) => ( {
252+ data : { type : "User" } ,
253+ } ) ,
254+ } ,
255+ repos : {
256+ getCollaboratorPermissionLevel : async ( ) => ( {
257+ data : { permission : "admin" } ,
258+ } ) ,
259+ } ,
260+ } as any ;
261+
262+ const context = createContext ( "admin-user" ) ;
263+ const result = await checkWritePermissions ( mockOctokit , context ) ;
264+
265+ expect ( result ) . toBe ( true ) ;
266+ } ) ;
267+
268+ test ( "should grant write permissions to bots with admin access via collaborator" , async ( ) => {
269+ const mockOctokit = {
270+ users : {
271+ getByUsername : async ( ) => ( {
272+ data : { type : "Bot" } ,
273+ } ) ,
274+ } ,
275+ repos : {
276+ getCollaboratorPermissionLevel : async ( ) => ( {
277+ data : { permission : "admin" } ,
278+ } ) ,
279+ } ,
280+ } as any ;
281+
282+ const context = createContext ( "admin-bot" ) ;
283+ const result = await checkWritePermissions ( mockOctokit , context ) ;
284+
285+ expect ( result ) . toBe ( true ) ;
286+ } ) ;
287+
288+ test ( "should grant write permissions to bots with admin access via installation" , async ( ) => {
289+ const mockOctokit = {
290+ users : {
291+ getByUsername : async ( ) => ( {
292+ data : { type : "Bot" } ,
293+ } ) ,
294+ } ,
295+ repos : {
296+ getCollaboratorPermissionLevel : async ( ) => {
297+ throw new Error ( "Not found" ) ;
298+ } ,
299+ } ,
300+ apps : {
301+ getRepoInstallation : async ( ) => ( {
302+ data : {
303+ id : 123 ,
304+ permissions : { contents : "admin" } ,
305+ } ,
306+ } ) ,
307+ } ,
308+ } as any ;
309+
310+ const context = createContext ( "admin-bot" ) ;
311+ const result = await checkWritePermissions ( mockOctokit , context ) ;
312+
313+ expect ( result ) . toBe ( true ) ;
314+ } ) ;
315+
316+ test ( "should continue when getBotActorType fails" , async ( ) => {
317+ const mockOctokit = {
318+ users : {
319+ getByUsername : async ( ) => {
320+ throw new Error ( "User not found" ) ;
321+ } ,
322+ } ,
323+ repos : {
324+ getCollaboratorPermissionLevel : async ( ) => ( {
325+ data : { permission : "write" } ,
326+ } ) ,
327+ } ,
328+ } as any ;
329+
330+ const context = createContext ( "unknown-user" ) ;
331+ const result = await checkWritePermissions ( mockOctokit , context ) ;
332+
333+ expect ( result ) . toBe ( true ) ;
334+ } ) ;
335+
336+ test ( "should handle installation without permissions object" , async ( ) => {
337+ const mockOctokit = {
338+ users : {
339+ getByUsername : async ( ) => ( {
340+ data : { type : "Bot" } ,
341+ } ) ,
342+ } ,
343+ repos : {
344+ getCollaboratorPermissionLevel : async ( ) => {
345+ throw new Error ( "Not found" ) ;
346+ } ,
347+ } ,
348+ apps : {
349+ getRepoInstallation : async ( ) => ( {
350+ data : {
351+ id : 123 ,
352+ // permissions is undefined
353+ } ,
354+ } ) ,
355+ } ,
356+ } as any ;
357+
358+ const context = createContext ( "bot-no-perms" ) ;
359+ const result = await checkWritePermissions ( mockOctokit , context ) ;
360+
361+ expect ( result ) . toBe ( false ) ;
362+ } ) ;
247363} ) ;
0 commit comments