@@ -312,18 +312,24 @@ defmodule AdoCli.CLI.PullRequestsTest do
312312 end
313313
314314 test "fetches the full diff with --file" , % { server: server } do
315- iterations_body = ~s( {"value":[{"id":1}]})
315+ iterations_body =
316+ JSON . encode! ( % {
317+ "value" => [
318+ % {
319+ "id" => 1 ,
320+ "sourceRefCommit" => % { "commitId" => "src" } ,
321+ "targetRefCommit" => % { "commitId" => "tgt" }
322+ }
323+ ]
324+ } )
316325
317326 changes_body =
318327 JSON . encode! ( % {
319- "value " => [
328+ "changeEntries " => [
320329 % { "changeId" => 101 , "changeType" => 2 , "item" => % { "path" => "/src/foo.ex" } }
321330 ]
322331 } )
323332
324- diff_content =
325- "@@ -1,3 +1,5 @@\\ n defmodule Foo do\\ n+ @moduledoc\\ n+ New doc\\ n def hello\\ n end\\ n"
326-
327333 TestServer . expect (
328334 server ,
329335 "GET" ,
@@ -338,11 +344,34 @@ defmodule AdoCli.CLI.PullRequestsTest do
338344 fn conn -> Plug.Conn . resp ( conn , 200 , changes_body ) end
339345 )
340346
347+ # fetch_iteration_data calls iterations again
348+ TestServer . expect (
349+ server ,
350+ "GET" ,
351+ api ( "/testorg/_apis/git/repositories/test/pullRequests/1/iterations" ) ,
352+ fn conn -> Plug.Conn . resp ( conn , 200 , iterations_body ) end
353+ )
354+
355+ # Old file content (targetRefCommit)
356+ TestServer . expect (
357+ server ,
358+ "GET" ,
359+ api ( "/testorg/_apis/git/repositories/test/items" ) ,
360+ fn conn -> Plug.Conn . resp ( conn , 200 , "defmodule Foo do\n def hello\n end\n " ) end
361+ )
362+
363+ # New file content (sourceRefCommit)
341364 TestServer . expect (
342365 server ,
343366 "GET" ,
344- api ( "/testorg/_apis/git/repositories/test/pullRequests/1/iterations/1/changes/101" ) ,
345- fn conn -> Plug.Conn . resp ( conn , 200 , diff_content ) end
367+ api ( "/testorg/_apis/git/repositories/test/items" ) ,
368+ fn conn ->
369+ Plug.Conn . resp (
370+ conn ,
371+ 200 ,
372+ "defmodule Foo do\n @moduledoc\n New doc\n def hello\n end\n "
373+ )
374+ end
346375 )
347376
348377 output =
@@ -356,16 +385,25 @@ defmodule AdoCli.CLI.PullRequestsTest do
356385 end )
357386
358387 assert_receive { :cli_mate_shell , :halt , 0 } , 500
388+ assert output =~ "+++ b/src/foo.ex"
359389 assert output =~ "@moduledoc"
360- assert output =~ "New doc"
361390 end
362391
363392 test "strips leading slash when matching --file" , % { server: server } do
364- iterations_body = ~s( {"value":[{"id":1}]})
393+ iterations_body =
394+ JSON . encode! ( % {
395+ "value" => [
396+ % {
397+ "id" => 1 ,
398+ "sourceRefCommit" => % { "commitId" => "src" } ,
399+ "targetRefCommit" => % { "commitId" => "tgt" }
400+ }
401+ ]
402+ } )
365403
366404 changes_body =
367405 JSON . encode! ( % {
368- "value " => [
406+ "changeEntries " => [
369407 % { "changeId" => 101 , "changeType" => 2 , "item" => % { "path" => "/src/foo.ex" } }
370408 ]
371409 } )
@@ -387,8 +425,22 @@ defmodule AdoCli.CLI.PullRequestsTest do
387425 TestServer . expect (
388426 server ,
389427 "GET" ,
390- api ( "/testorg/_apis/git/repositories/test/pullRequests/1/iterations/1/changes/101" ) ,
391- fn conn -> Plug.Conn . resp ( conn , 200 , "DIFF_CONTENT" ) end
428+ api ( "/testorg/_apis/git/repositories/test/pullRequests/1/iterations" ) ,
429+ fn conn -> Plug.Conn . resp ( conn , 200 , iterations_body ) end
430+ )
431+
432+ TestServer . expect (
433+ server ,
434+ "GET" ,
435+ api ( "/testorg/_apis/git/repositories/test/items" ) ,
436+ fn conn -> Plug.Conn . resp ( conn , 200 , "old" ) end
437+ )
438+
439+ TestServer . expect (
440+ server ,
441+ "GET" ,
442+ api ( "/testorg/_apis/git/repositories/test/items" ) ,
443+ fn conn -> Plug.Conn . resp ( conn , 200 , "new" ) end
392444 )
393445
394446 output =
@@ -402,7 +454,7 @@ defmodule AdoCli.CLI.PullRequestsTest do
402454 end )
403455
404456 assert_receive { :cli_mate_shell , :halt , 0 } , 500
405- assert output =~ "DIFF_CONTENT "
457+ assert output =~ "diff --git "
406458 end
407459
408460 test "halts 1 with a clear error when --file matches no change" , % { server: server } do
@@ -459,15 +511,32 @@ defmodule AdoCli.CLI.PullRequestsTest do
459511 end
460512
461513 test "uses --iteration N when provided" , % { server: server } do
462- # No /iterations GET expected (we passed --iteration
463- # explicitly), just the /changes for iteration 3.
464- changes_body =
514+ iterations_body =
465515 JSON . encode! ( % {
466516 "value" => [
517+ % {
518+ "id" => 3 ,
519+ "sourceRefCommit" => % { "commitId" => "src" } ,
520+ "targetRefCommit" => % { "commitId" => "tgt" }
521+ }
522+ ]
523+ } )
524+
525+ changes_body =
526+ JSON . encode! ( % {
527+ "changeEntries" => [
467528 % { "changeId" => 301 , "changeType" => 2 , "item" => % { "path" => "/x.ex" } }
468529 ]
469530 } )
470531
532+ # resolve_iteration with explicit id
533+ TestServer . expect (
534+ server ,
535+ "GET" ,
536+ api ( "/testorg/_apis/git/repositories/test/pullRequests/1/iterations" ) ,
537+ fn conn -> Plug.Conn . resp ( conn , 200 , iterations_body ) end
538+ )
539+
471540 TestServer . expect (
472541 server ,
473542 "GET" ,
@@ -488,16 +557,33 @@ defmodule AdoCli.CLI.PullRequestsTest do
488557 end
489558
490559 test "--unified emits all file diffs concatenated" , % { server: server } do
491- iterations_body = ~s( {"value":[{"id":1}]})
560+ iterations_body =
561+ JSON . encode! ( % {
562+ "value" => [
563+ % {
564+ "id" => 1 ,
565+ "sourceRefCommit" => % { "commitId" => "src" } ,
566+ "targetRefCommit" => % { "commitId" => "tgt" }
567+ }
568+ ]
569+ } )
492570
493571 changes_body =
494572 JSON . encode! ( % {
495- "value " => [
573+ "changeEntries " => [
496574 % { "changeId" => 401 , "changeType" => 2 , "item" => % { "path" => "/a.ex" } } ,
497575 % { "changeId" => 402 , "changeType" => 2 , "item" => % { "path" => "/b.ex" } }
498576 ]
499577 } )
500578
579+ diffs_body =
580+ JSON . encode! ( % {
581+ "changes" => [
582+ % { "item" => % { "path" => "/a.ex" , "objectId" => "a1" , "originalObjectId" => "a0" } } ,
583+ % { "item" => % { "path" => "/b.ex" , "objectId" => "b1" , "originalObjectId" => "b0" } }
584+ ]
585+ } )
586+
501587 TestServer . expect (
502588 server ,
503589 "GET" ,
@@ -512,18 +598,49 @@ defmodule AdoCli.CLI.PullRequestsTest do
512598 fn conn -> Plug.Conn . resp ( conn , 200 , changes_body ) end
513599 )
514600
601+ # fetch_iteration_data re-fetches iterations
602+ TestServer . expect (
603+ server ,
604+ "GET" ,
605+ api ( "/testorg/_apis/git/repositories/test/pullRequests/1/iterations" ) ,
606+ fn conn -> Plug.Conn . resp ( conn , 200 , iterations_body ) end
607+ )
608+
609+ TestServer . expect (
610+ server ,
611+ "GET" ,
612+ api ( "/testorg/_apis/git/repositories/test/diffs/commits" ) ,
613+ fn conn -> Plug.Conn . resp ( conn , 200 , diffs_body ) end
614+ )
615+
616+ # Old/new content for a.ex
617+ TestServer . expect (
618+ server ,
619+ "GET" ,
620+ api ( "/testorg/_apis/git/repositories/test/items" ) ,
621+ fn conn -> Plug.Conn . resp ( conn , 200 , "old content\n " ) end
622+ )
623+
624+ TestServer . expect (
625+ server ,
626+ "GET" ,
627+ api ( "/testorg/_apis/git/repositories/test/items" ) ,
628+ fn conn -> Plug.Conn . resp ( conn , 200 , "old content\n new line\n " ) end
629+ )
630+
631+ # Old/new content for b.ex
515632 TestServer . expect (
516633 server ,
517634 "GET" ,
518- api ( "/testorg/_apis/git/repositories/test/pullRequests/1/iterations/1/changes/401 " ) ,
519- fn conn -> Plug.Conn . resp ( conn , 200 , "DIFF_A " ) end
635+ api ( "/testorg/_apis/git/repositories/test/items " ) ,
636+ fn conn -> Plug.Conn . resp ( conn , 200 , "b old \n " ) end
520637 )
521638
522639 TestServer . expect (
523640 server ,
524641 "GET" ,
525- api ( "/testorg/_apis/git/repositories/test/pullRequests/1/iterations/1/changes/402 " ) ,
526- fn conn -> Plug.Conn . resp ( conn , 200 , "DIFF_B " ) end
642+ api ( "/testorg/_apis/git/repositories/test/items " ) ,
643+ fn conn -> Plug.Conn . resp ( conn , 200 , "b new \n " ) end
527644 )
528645
529646 output =
@@ -537,8 +654,9 @@ defmodule AdoCli.CLI.PullRequestsTest do
537654 end )
538655
539656 assert_receive { :cli_mate_shell , :halt , 0 } , 500
540- assert output =~ "DIFF_A"
541- assert output =~ "DIFF_B"
657+ assert output =~ "diff --git"
658+ assert output =~ "+++ b/a.ex"
659+ assert output =~ "+++ b/b.ex"
542660 end
543661
544662 test "halts 1 when the PR has no iterations" , % { server: server } do
0 commit comments