44using NSubstitute . Extensions ;
55using NUnit . Framework ;
66using Paratext . Data ;
7+ using Paratext . Data . Repository ;
78using Paratext . Data . Users ;
89using SIL . XForge . Scripture . Models ;
910using SIL . XForge . Services ;
@@ -13,6 +14,11 @@ namespace SIL.XForge.Scripture.Services;
1314[ TestFixture ]
1415public class JwtInternetSharedRepositorySourceTests
1516{
17+ private const string RepoPath = "/sync/abc123/target" ;
18+ private const string ProjectName = "TestProject" ;
19+ private const string ProjectId = "4011111111111111111111111111111111111111" ;
20+ private const string NewTipRevision = "bbb2222222222222222222222222222222222222" ;
21+
1622 [ Test ]
1723 public void CanUserAuthenticateToPTArchives_Works ( )
1824 {
@@ -50,10 +56,48 @@ public void CanUserAuthenticateToPTArchives_Works()
5056 ) ;
5157 }
5258
59+ [ Test ]
60+ public void GetOutgoingRevisions_ReturnsDraftRevisions ( )
61+ {
62+ var env = new TestEnvironment ( ) ;
63+ SharedProject sharedProject = new SharedProject
64+ {
65+ SendReceiveId = HexId . FromStr ( ProjectId ) ,
66+ ScrTextName = ProjectName ,
67+ Repository = TestEnvironment . CreatePushRepo ( HexId . FromStr ( ProjectId ) , ProjectName ) ,
68+ } ;
69+ string [ ] expectedRevisions = [ NewTipRevision ] ;
70+ env . MockHgWrapper . GetDraftRevisions ( RepoPath ) . Returns ( expectedRevisions ) ;
71+
72+ // SUT
73+ string [ ] result = env . RepoSource . GetOutgoingRevisions ( RepoPath , sharedProject ) ;
74+
75+ Assert . That ( result , Is . EqualTo ( expectedRevisions ) ) ;
76+ }
77+
78+ [ Test ]
79+ public void GetOutgoingRevisions_NoDraftRevisions_ReturnsEmpty ( )
80+ {
81+ var env = new TestEnvironment ( ) ;
82+ SharedProject sharedProject = new SharedProject
83+ {
84+ SendReceiveId = HexId . FromStr ( ProjectId ) ,
85+ ScrTextName = ProjectName ,
86+ Repository = TestEnvironment . CreatePushRepo ( HexId . FromStr ( ProjectId ) , ProjectName ) ,
87+ } ;
88+ env . MockHgWrapper . GetDraftRevisions ( RepoPath ) . Returns ( [ ] ) ;
89+
90+ // SUT
91+ string [ ] result = env . RepoSource . GetOutgoingRevisions ( RepoPath , sharedProject ) ;
92+
93+ Assert . That ( result , Is . Empty ) ;
94+ }
95+
5396 private class TestEnvironment
5497 {
5598 public readonly JwtInternetSharedRepositorySource RepoSource ;
5699 public readonly IRESTClient MockPTArchivesClient ;
100+ public readonly IHgWrapper MockHgWrapper ;
57101
58102 public TestEnvironment ( )
59103 {
@@ -63,16 +107,20 @@ public TestEnvironment()
63107 "applicationName" ,
64108 "jwtToken"
65109 ) ;
110+ MockHgWrapper = Substitute . For < IHgWrapper > ( ) ;
66111 RepoSource = Substitute . ForPartsOf < JwtInternetSharedRepositorySource > (
67112 "access-token" ,
68113 mockPTRegistryClient ,
69- Substitute . For < IHgWrapper > ( ) ,
114+ MockHgWrapper ,
70115 ptUser ,
71116 "sr-server-uri" ,
72117 new MockLogger < InternetSharedRepositorySourceProvider > ( )
73118 ) ;
74119 MockPTArchivesClient = Substitute . For < RESTClient > ( "pt-archives-server.example.com" , "product-version-123" ) ;
75120 RepoSource . Configure ( ) . GetClient ( ) . Returns ( MockPTArchivesClient ) ;
76121 }
122+
123+ public static SharedRepository CreatePushRepo ( HexId ptProjectId , string projectName ) =>
124+ new SharedRepository { SendReceiveId = ptProjectId , ScrTextName = projectName } ;
77125 }
78126}
0 commit comments