@@ -12,6 +12,7 @@ import {
12
12
getWebApi ,
13
13
invalidateWebApi ,
14
14
repositoryHasFile ,
15
+ validateRepository ,
15
16
} from "./azdoClient" ;
16
17
import * as azdoClient from "./azdoClient" ;
17
18
import { AzureDevOpsOpts } from "./git" ;
@@ -144,6 +145,57 @@ describe("test getBuildApi function", () => {
144
145
} ) ;
145
146
} ) ;
146
147
148
+ describe ( "validateRepository" , ( ) => {
149
+ test ( "repository exists" , async ( ) => {
150
+ const getRepositoryFunc = jest . spyOn ( azure , "GitAPI" ) ;
151
+ getRepositoryFunc . mockReturnValueOnce (
152
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
153
+ Promise . resolve ( { getRepository : ( ) => ( { id : "3839fjfkj" } ) } as any )
154
+ ) ;
155
+ const getItemFunc = jest . spyOn ( azure , "GitAPI" ) ;
156
+ getItemFunc . mockReturnValueOnce (
157
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
158
+ Promise . resolve ( { getItem : ( ) => ( { commitId : "3839fjfkj" } ) } as any )
159
+ ) ;
160
+ const accessOpts : AzureDevOpsOpts = {
161
+ orgName : "testOrg" ,
162
+ personalAccessToken : "mytoken" ,
163
+ project : "testProject" ,
164
+ } ;
165
+
166
+ await expect (
167
+ validateRepository (
168
+ "my-project" ,
169
+ "myFile" ,
170
+ "master" ,
171
+ "my-repo" ,
172
+ accessOpts
173
+ )
174
+ ) . resolves . not . toThrow ( ) ;
175
+ } ) ;
176
+ test ( "repository does not exist" , async ( ) => {
177
+ const createPullRequestFunc = jest . spyOn ( azure , "GitAPI" ) ;
178
+ createPullRequestFunc . mockReturnValueOnce (
179
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
180
+ Promise . resolve ( { getRepository : ( ) => null } as any )
181
+ ) ;
182
+ const accessOpts : AzureDevOpsOpts = {
183
+ orgName : "testOrg" ,
184
+ personalAccessToken : "mytoken" ,
185
+ project : "testProject" ,
186
+ } ;
187
+ await expect (
188
+ validateRepository (
189
+ "my-project" ,
190
+ "myFile" ,
191
+ "master" ,
192
+ "my-repo" ,
193
+ accessOpts
194
+ )
195
+ ) . rejects . toThrow ( ) ;
196
+ } ) ;
197
+ } ) ;
198
+
147
199
describe ( "repositoryHasFile" , ( ) => {
148
200
test ( "repository contains the given file" , async ( ) => {
149
201
const createPullRequestFunc = jest . spyOn ( azure , "GitAPI" ) ;
0 commit comments