@@ -31,7 +31,7 @@ describe('repository-selection', function() {
3131 } ) ;
3232
3333 it ( 'should allow selection from repo lists from your pre-defined config' , async ( ) => {
34- // fake return values
34+ // Fake return values
3535 quickPickSpy . resolves (
3636 { repositories : [ 'foo/bar' , 'foo/baz' ] }
3737 ) ;
@@ -42,18 +42,19 @@ describe('repository-selection', function() {
4242 }
4343 ) ;
4444
45- // make the function call
45+ // Make the function call
4646 const repoSelection = await mod . getRepositorySelection ( ) ;
4747
4848 // Check that the return value is correct
4949 expect ( repoSelection . repositoryLists ) . to . be . undefined ;
50+ expect ( repoSelection . owners ) . to . be . undefined ;
5051 expect ( repoSelection . repositories ) . to . deep . eq (
5152 [ 'foo/bar' , 'foo/baz' ]
5253 ) ;
5354 } ) ;
5455
5556 it ( 'should allow selection from repo lists defined at the system level' , async ( ) => {
56- // fake return values
57+ // Fake return values
5758 quickPickSpy . resolves (
5859 { repositoryList : 'top_100' }
5960 ) ;
@@ -64,42 +65,91 @@ describe('repository-selection', function() {
6465 }
6566 ) ;
6667
67- // make the function call
68+ // Make the function call
6869 const repoSelection = await mod . getRepositorySelection ( ) ;
6970
7071 // Check that the return value is correct
7172 expect ( repoSelection . repositories ) . to . be . undefined ;
73+ expect ( repoSelection . owners ) . to . be . undefined ;
7274 expect ( repoSelection . repositoryLists ) . to . deep . eq (
7375 [ 'top_100' ]
7476 ) ;
7577 } ) ;
7678
77- // Test the regex in various "good" cases
79+ // Test the owner regex in various "good" cases
80+ const goodOwners = [
81+ 'owner' ,
82+ 'owner-with-hyphens' ,
83+ 'ownerWithNumbers58' ,
84+ 'owner_with_underscores' ,
85+ 'owner.with.periods.'
86+ ] ;
87+ goodOwners . forEach ( owner => {
88+ it ( `should run on a valid owner that you enter in the text box: ${ owner } ` , async ( ) => {
89+ // Fake return values
90+ quickPickSpy . resolves (
91+ { useAllReposOfOwner : true }
92+ ) ;
93+ getRemoteRepositoryListsSpy . returns ( { } ) ; // no pre-defined repo lists
94+ showInputBoxSpy . resolves ( owner ) ;
95+
96+ // Make the function call
97+ const repoSelection = await mod . getRepositorySelection ( ) ;
98+
99+ // Check that the return value is correct
100+ expect ( repoSelection . repositories ) . to . be . undefined ;
101+ expect ( repoSelection . repositoryLists ) . to . be . undefined ;
102+ expect ( repoSelection . owners ) . to . deep . eq ( [ owner ] ) ;
103+ } ) ;
104+ } ) ;
105+
106+ // Test the owner regex in various "bad" cases
107+ const badOwners = [
108+ 'invalid&owner' ,
109+ 'owner-with-repo/repo'
110+ ] ;
111+ badOwners . forEach ( owner => {
112+ it ( `should show an error message if you enter an invalid owner in the text box: ${ owner } ` , async ( ) => {
113+ // Fake return values
114+ quickPickSpy . resolves (
115+ { useAllReposOfOwner : true }
116+ ) ;
117+ getRemoteRepositoryListsSpy . returns ( { } ) ; // no pre-defined repo lists
118+ showInputBoxSpy . resolves ( owner ) ;
119+
120+ // Function call should throw a UserCancellationException
121+ await expect ( mod . getRepositorySelection ( ) ) . to . be . rejectedWith ( Error , `Invalid user or organization: ${ owner } ` ) ;
122+ } ) ;
123+ } ) ;
124+
125+ // Test the repo regex in various "good" cases
78126 const goodRepos = [
79127 'owner/repo' ,
80128 'owner_with.symbols-/repo.with-symbols_' ,
81129 'ownerWithNumbers58/repoWithNumbers37'
82130 ] ;
83131 goodRepos . forEach ( repo => {
84132 it ( `should run on a valid repo that you enter in the text box: ${ repo } ` , async ( ) => {
85- // fake return values
133+ // Fake return values
86134 quickPickSpy . resolves (
87- { useCustomRepository : true }
135+ { useCustomRepo : true }
88136 ) ;
89137 getRemoteRepositoryListsSpy . returns ( { } ) ; // no pre-defined repo lists
90138 showInputBoxSpy . resolves ( repo ) ;
91139
92- // make the function call
140+ // Make the function call
93141 const repoSelection = await mod . getRepositorySelection ( ) ;
94142
95143 // Check that the return value is correct
144+ expect ( repoSelection . repositoryLists ) . to . be . undefined ;
145+ expect ( repoSelection . owners ) . to . be . undefined ;
96146 expect ( repoSelection . repositories ) . to . deep . equal (
97147 [ repo ]
98148 ) ;
99149 } ) ;
100150 } ) ;
101151
102- // Test the regex in various "bad" cases
152+ // Test the repo regex in various "bad" cases
103153 const badRepos = [
104154 'invalid*owner/repo' ,
105155 'owner/repo+some&invalid&stuff' ,
@@ -108,14 +158,14 @@ describe('repository-selection', function() {
108158 ] ;
109159 badRepos . forEach ( repo => {
110160 it ( `should show an error message if you enter an invalid repo in the text box: ${ repo } ` , async ( ) => {
111- // fake return values
161+ // Fake return values
112162 quickPickSpy . resolves (
113- { useCustomRepository : true }
163+ { useCustomRepo : true }
114164 ) ;
115165 getRemoteRepositoryListsSpy . returns ( { } ) ; // no pre-defined repo lists
116166 showInputBoxSpy . resolves ( repo ) ;
117167
118- // function call should throw a UserCancellationException
168+ // Function call should throw a UserCancellationException
119169 await expect ( mod . getRepositorySelection ( ) ) . to . be . rejectedWith ( UserCancellationException , 'Invalid repository format' ) ;
120170 } ) ;
121171 } ) ;
0 commit comments