@@ -10,6 +10,7 @@ import { describe, expect, it } from "vite-plus/test";
1010import {
1111 canEditPullRequestChangeRequest ,
1212 canEditPullRequestComment ,
13+ canResolvePullRequestThread ,
1314} from "./pullRequestEditing.logic" ;
1415
1516type Subject = Pick < PullRequestDetail , "author" | "capabilities" | "viewer" | "viewerPermissions" > ;
@@ -89,6 +90,33 @@ describe("canEditPullRequestChangeRequest", () => {
8990 ) . toBe ( true ) ;
9091 } ) ;
9192
93+ it ( "follows the host's own answer about the reader over authorship and merge access" , ( ) => {
94+ expect (
95+ canEditPullRequestChangeRequest (
96+ subject ( {
97+ author : actor ( "someone-else" ) ,
98+ viewerPermissions : permissions ( { editChangeRequest : true } ) ,
99+ } ) ,
100+ ) ,
101+ ) . toBe ( true ) ;
102+ expect (
103+ canEditPullRequestChangeRequest (
104+ subject ( {
105+ viewerPermissions : permissions ( { actions : [ "merge" ] , editChangeRequest : false } ) ,
106+ } ) ,
107+ ) ,
108+ ) . toBe ( false ) ;
109+ // The host can't rewrite change requests at all, so the reader's answer can't widen that.
110+ expect (
111+ canEditPullRequestChangeRequest (
112+ subject ( {
113+ capabilities : capabilities ( { changeRequest : false , comment : true } ) ,
114+ viewerPermissions : permissions ( { editChangeRequest : true } ) ,
115+ } ) ,
116+ ) ,
117+ ) . toBe ( false ) ;
118+ } ) ;
119+
92120 it ( "refuses a reader who neither wrote it nor may merge it" , ( ) => {
93121 expect (
94122 canEditPullRequestChangeRequest (
@@ -146,6 +174,23 @@ describe("canEditPullRequestComment", () => {
146174 ) ;
147175 } ) ;
148176
177+ it ( "follows the host's own answer about a remark over authorship" , ( ) => {
178+ expect ( canEditPullRequestComment ( subject ( ) , comment ( { canEdit : false } ) ) ) . toBe ( false ) ;
179+ expect (
180+ canEditPullRequestComment (
181+ subject ( ) ,
182+ comment ( { author : actor ( "someone-else" ) , canEdit : true } ) ,
183+ ) ,
184+ ) . toBe ( true ) ;
185+ // The host can't rewrite remarks at all, so its per-remark answer can't widen that.
186+ expect (
187+ canEditPullRequestComment (
188+ subject ( { capabilities : capabilities ( { changeRequest : true , comment : false } ) } ) ,
189+ comment ( { canEdit : true } ) ,
190+ ) ,
191+ ) . toBe ( false ) ;
192+ } ) ;
193+
149194 it ( "refuses a remark the host attributes to nobody" , ( ) => {
150195 expect ( canEditPullRequestComment ( subject ( ) , comment ( { author : null } ) ) ) . toBe ( false ) ;
151196 } ) ;
@@ -170,3 +215,24 @@ describe("canEditPullRequestComment", () => {
170215 expect ( canEditPullRequestComment ( subject ( { viewer : undefined } ) , comment ( ) ) ) . toBe ( false ) ;
171216 } ) ;
172217} ) ;
218+
219+ describe ( "canResolvePullRequestThread" , ( ) => {
220+ it ( "uses the reader's repository-wide permission where the host says nothing per thread" , ( ) => {
221+ expect ( canResolvePullRequestThread ( subject ( ) , { } ) ) . toBe ( true ) ;
222+ expect (
223+ canResolvePullRequestThread (
224+ subject ( { viewerPermissions : permissions ( { resolve : false } ) } ) ,
225+ { } ,
226+ ) ,
227+ ) . toBe ( false ) ;
228+ } ) ;
229+
230+ it ( "only narrows the reader's permission with the host's answer for one thread" , ( ) => {
231+ expect ( canResolvePullRequestThread ( subject ( ) , { canResolve : false } ) ) . toBe ( false ) ;
232+ expect (
233+ canResolvePullRequestThread ( subject ( { viewerPermissions : permissions ( { resolve : false } ) } ) , {
234+ canResolve : true ,
235+ } ) ,
236+ ) . toBe ( false ) ;
237+ } ) ;
238+ } ) ;
0 commit comments