@@ -212,3 +212,69 @@ describe("rewriting what has already been said", () => {
212212 } ) ,
213213 ) ;
214214} ) ;
215+
216+ describe ( "expanding unchanged lines" , ( ) => {
217+ const change = {
218+ cwd : "/w" ,
219+ repository : "acme/web" ,
220+ host : "gitlab.com" ,
221+ number : 7 ,
222+ changeType : "change" as const ,
223+ oldPath : "src/page.ts" ,
224+ newPath : "src/page.ts" ,
225+ } ;
226+
227+ it . effect ( "reads both sides of a file through the merge request or one of its commits" , ( ) =>
228+ Effect . gen ( function * ( ) {
229+ const getMergeRequestDiffFileContents = vi . fn ( ( ) =>
230+ Effect . succeed ( { oldContents : "before\n" , newContents : "after\n" } ) ,
231+ ) ;
232+ const provider = yield * make . pipe (
233+ Effect . provide (
234+ Layer . mock ( GitLabPullRequestCli . GitLabPullRequestCli ) ( {
235+ getMergeRequestDiffFileContents,
236+ } ) ,
237+ ) ,
238+ ) ;
239+ assert . isDefined ( provider . getDiffFileContents ) ;
240+ const oneCommit = { ...change , commit : "a1b2c3d" } ;
241+
242+ expect ( yield * provider . getDiffFileContents ( change ) ) . toEqual ( {
243+ oldContents : "before\n" ,
244+ newContents : "after\n" ,
245+ } ) ;
246+ yield * provider . getDiffFileContents ( oneCommit ) ;
247+ expect ( getMergeRequestDiffFileContents ) . toHaveBeenNthCalledWith ( 1 , change ) ;
248+ expect ( getMergeRequestDiffFileContents ) . toHaveBeenNthCalledWith ( 2 , oneCommit ) ;
249+ } ) ,
250+ ) ;
251+
252+ it . effect ( "reports a file GitLab cannot expand as a failed read" , ( ) =>
253+ Effect . gen ( function * ( ) {
254+ const provider = yield * make . pipe (
255+ Effect . provide (
256+ Layer . mock ( GitLabPullRequestCli . GitLabPullRequestCli ) ( {
257+ getMergeRequestDiffFileContents : ( ) =>
258+ Effect . fail (
259+ new GitLabPullRequestCli . GitLabDiffFileContentsUnavailableError ( {
260+ command : "glab" ,
261+ cwd : "/w" ,
262+ path : "assets/logo.png" ,
263+ reason : "binary" ,
264+ } ) ,
265+ ) ,
266+ } ) ,
267+ ) ,
268+ ) ;
269+ assert . isDefined ( provider . getDiffFileContents ) ;
270+
271+ expect ( yield * Effect . flip ( provider . getDiffFileContents ( change ) ) ) . toMatchObject ( {
272+ _tag : "PullRequestProviderError" ,
273+ provider : "gitlab" ,
274+ operation : "getDiffFileContents" ,
275+ reason : "failed" ,
276+ detail : "The diff file 'assets/logo.png' is binary." ,
277+ } ) ;
278+ } ) ,
279+ ) ;
280+ } ) ;
0 commit comments