@@ -875,7 +875,14 @@ it.effect(
875875 let generation = 1 ;
876876 const helperPaths : string [ ] = [ ] ;
877877 const lookups : string [ ] = [ ] ;
878- const requests : Array < { operation : string ; authorization : string | undefined } > = [ ] ;
878+ const requests : Array < {
879+ operation : string ;
880+ authorization : string | undefined ;
881+ repository : string | undefined ;
882+ credentialRepository : string | undefined ;
883+ fingerprint : string | undefined ;
884+ scope : string ;
885+ } > = [ ] ;
879886 const host = TestSourceControlHost . layer ( {
880887 process : {
881888 run : ( input ) =>
@@ -899,25 +906,48 @@ it.effect(
899906 const http = Layer . succeed (
900907 HttpClient . HttpClient ,
901908 HttpClient . make ( ( request ) =>
902- Effect . sync ( ( ) => {
909+ Effect . gen ( function * ( ) {
903910 const operation = request . url . endsWith ( "/user" )
904911 ? "user"
905912 : request . body . _tag === "Uint8Array"
906913 ? new TextDecoder ( ) . decode ( request . body . body )
907914 : "" ;
908- requests . push ( { operation, authorization : request . headers . authorization } ) ;
915+ const pin = yield * GitHubRequestPolicy . PinnedGitHubCredential ;
916+ requests . push ( {
917+ operation,
918+ authorization : request . headers . authorization ,
919+ repository : pin ?. repository ,
920+ credentialRepository : pin ?. credentialRepository ,
921+ fingerprint : pin ?. credentialFingerprint ,
922+ scope : yield * SourceControlRateLimit . CredentialScope ,
923+ } ) ;
909924 return HttpClientResponse . fromWeb (
910925 request ,
911926 new Response (
912927 JSON . stringify (
913928 operation === "user"
914929 ? { id : 101 , login : "Chinoman10" }
915- : {
916- data : {
917- repository : { pullRequest : { id : "PR_1" } } ,
918- _0_markFileAsViewed : { clientMutationId : null } ,
930+ : operation . includes ( "PullRequestFileStats" )
931+ ? {
932+ data : {
933+ repository : {
934+ pullRequest : {
935+ files : {
936+ nodes : [
937+ { path : "src/private.ts" , additions : generation , deletions : 1 } ,
938+ ] ,
939+ pageInfo : { hasNextPage : false , endCursor : null } ,
940+ } ,
941+ } ,
942+ } ,
943+ } ,
944+ }
945+ : {
946+ data : {
947+ repository : { pullRequest : { id : "PR_1" } } ,
948+ _0_markFileAsViewed : { clientMutationId : null } ,
949+ } ,
919950 } ,
920- } ,
921951 ) ,
922952 { headers : { "content-type" : "application/json" } } ,
923953 ) ,
@@ -978,6 +1008,7 @@ it.effect(
9781008 getReviewThreadComments : ( input ) =>
9791009 lookup ( input ) . pipe ( Effect . as ( { comments : [ ] , nextCursor : null } ) ) ,
9801010 setFilesViewed : native . setFilesViewed ! ,
1011+ getFileStats : native . getFileStats ! ,
9811012 } ) ;
9821013 const service = yield * makeService ( {
9831014 projects : [
@@ -998,9 +1029,30 @@ it.effect(
9981029 [ "ownera/repo" ] ,
9991030 ) ;
10001031 assert . strictEqual ( ( yield * service . detail ( ref ) ) . body , "fake-OwnerA-1" ) ;
1032+ const firstBreakdown = yield * service . changeBreakdown ( ref ) ;
1033+ assert . deepStrictEqual ( firstBreakdown ?. code , { additions : 1 , deletions : 1 } ) ;
1034+ assert . deepStrictEqual ( yield * service . changeBreakdown ( ref ) , firstBreakdown ) ;
10011035 yield * credentials . invalidate ( "github.com" , "ownera/repo" ) ;
10021036 generation = 2 ;
10031037 assert . strictEqual ( ( yield * service . detail ( ref ) ) . body , "fake-OwnerA-2" ) ;
1038+ const secondBreakdown = yield * service . changeBreakdown ( ref ) ;
1039+ assert . deepStrictEqual ( secondBreakdown ?. code , { additions : 2 , deletions : 1 } ) ;
1040+ assert . deepStrictEqual ( yield * service . changeBreakdown ( ref ) , secondBreakdown ) ;
1041+ const fileStatsRequests = requests . filter ( ( request ) =>
1042+ request . operation . includes ( "PullRequestFileStats" ) ,
1043+ ) ;
1044+ assert . strictEqual ( fileStatsRequests . length , 2 ) ;
1045+ assert . deepStrictEqual (
1046+ fileStatsRequests . map ( ( request ) => request . authorization ) ,
1047+ [ "Bearer fake-OwnerA-1" , "Bearer fake-OwnerA-2" ] ,
1048+ ) ;
1049+ assert . notStrictEqual ( fileStatsRequests [ 0 ] ?. fingerprint , fileStatsRequests [ 1 ] ?. fingerprint ) ;
1050+ for ( const request of fileStatsRequests ) {
1051+ assert . strictEqual ( request . repository , "ownera/repo" ) ;
1052+ assert . strictEqual ( request . credentialRepository , "ownera/repo" ) ;
1053+ assert . ok ( request . fingerprint ) ;
1054+ assert . strictEqual ( request . scope , request . fingerprint ) ;
1055+ }
10041056 assert . strictEqual (
10051057 ( yield * service . listStats ( { refs : [ ref ] } ) ) . stats [ 0 ] ?. repository ,
10061058 "ownera/repo" ,
@@ -1370,19 +1422,30 @@ it.effect.each([false, true])(
13701422 const reads : string [ ] = [ ] ;
13711423 const service = yield * makeService ( {
13721424 projects : [
1373- project ( { id : "p1" , title : "web" , workspaceRoot : "/a" , repository : "acme/web" } ) ,
1425+ project ( {
1426+ id : "p1" ,
1427+ title : "web" ,
1428+ workspaceRoot : "/a" ,
1429+ repository : "acme/web" ,
1430+ remoteUrl : "https://github.com/Acme/Web.git" ,
1431+ } ) ,
13741432 ] ,
13751433 providers : [
13761434 fakeProvider ( SourceControlProviderKind . make ( "github" ) , {
1377- withVerifiedCredential : ( _ , use ) =>
1378- Effect . suspend ( ( ) =>
1379- use ( { accountId : "101" , viewer : "octocat" , credentialFingerprint : credential } ) ,
1380- ) ,
1435+ withVerifiedCredential : ( input , use ) =>
1436+ Effect . suspend ( ( ) => {
1437+ assert . strictEqual ( input . repository , "Acme/Web" ) ;
1438+ return use ( {
1439+ accountId : "101" ,
1440+ viewer : "octocat" ,
1441+ credentialFingerprint : credential ,
1442+ } ) ;
1443+ } ) ,
13811444 getFileStats : ( input ) =>
13821445 Effect . sync ( ( ) => {
13831446 assert . deepStrictEqual ( input , {
13841447 cwd : "/a" ,
1385- repository : "acme/web " ,
1448+ repository : "Acme/Web " ,
13861449 host : "github.com" ,
13871450 number : 1 ,
13881451 } ) ;
0 commit comments