@@ -23,55 +23,56 @@ describe("databaseFetcher", () => {
2323 request : mockRequest ,
2424 } as unknown as Octokit . Octokit ;
2525
26+ // We can't make the real octokit request (since we need credentials), so we mock the response.
27+ const successfullMockApiResponse = {
28+ data : [
29+ {
30+ id : 1495869 ,
31+ name : "csharp-database" ,
32+ language : "csharp" ,
33+ uploader : { } ,
34+ content_type : "application/zip" ,
35+ state : "uploaded" ,
36+ size : 55599715 ,
37+ created_at : "2022-03-24T10:46:24Z" ,
38+ updated_at : "2022-03-24T10:46:27Z" ,
39+ url : "https://api.github.com/repositories/143040428/code-scanning/codeql/databases/csharp" ,
40+ } ,
41+ {
42+ id : 1100671 ,
43+ name : "database.zip" ,
44+ language : "javascript" ,
45+ uploader : { } ,
46+ content_type : "application/zip" ,
47+ state : "uploaded" ,
48+ size : 29294434 ,
49+ created_at : "2022-03-01T16:00:04Z" ,
50+ updated_at : "2022-03-01T16:00:06Z" ,
51+ url : "https://api.github.com/repositories/143040428/code-scanning/codeql/databases/javascript" ,
52+ } ,
53+ {
54+ id : 648738 ,
55+ name : "ql-database" ,
56+ language : "ql" ,
57+ uploader : { } ,
58+ content_type : "application/json; charset=utf-8" ,
59+ state : "uploaded" ,
60+ size : 39735500 ,
61+ created_at : "2022-02-02T09:38:50Z" ,
62+ updated_at : "2022-02-02T09:38:51Z" ,
63+ url : "https://api.github.com/repositories/143040428/code-scanning/codeql/databases/ql" ,
64+ } ,
65+ ] ,
66+ } ;
67+
2668 beforeEach ( ( ) => {
2769 quickPickSpy = jest
2870 . spyOn ( window , "showQuickPick" )
2971 . mockResolvedValue ( undefined ) ;
3072 } ) ;
3173
3274 it ( "should convert a GitHub nwo to a database url" , async ( ) => {
33- // We can't make the real octokit request (since we need credentials), so we mock the response.
34- const mockApiResponse = {
35- data : [
36- {
37- id : 1495869 ,
38- name : "csharp-database" ,
39- language : "csharp" ,
40- uploader : { } ,
41- content_type : "application/zip" ,
42- state : "uploaded" ,
43- size : 55599715 ,
44- created_at : "2022-03-24T10:46:24Z" ,
45- updated_at : "2022-03-24T10:46:27Z" ,
46- url : "https://api.github.com/repositories/143040428/code-scanning/codeql/databases/csharp" ,
47- } ,
48- {
49- id : 1100671 ,
50- name : "database.zip" ,
51- language : "javascript" ,
52- uploader : { } ,
53- content_type : "application/zip" ,
54- state : "uploaded" ,
55- size : 29294434 ,
56- created_at : "2022-03-01T16:00:04Z" ,
57- updated_at : "2022-03-01T16:00:06Z" ,
58- url : "https://api.github.com/repositories/143040428/code-scanning/codeql/databases/javascript" ,
59- } ,
60- {
61- id : 648738 ,
62- name : "ql-database" ,
63- language : "ql" ,
64- uploader : { } ,
65- content_type : "application/json; charset=utf-8" ,
66- state : "uploaded" ,
67- size : 39735500 ,
68- created_at : "2022-02-02T09:38:50Z" ,
69- updated_at : "2022-02-02T09:38:51Z" ,
70- url : "https://api.github.com/repositories/143040428/code-scanning/codeql/databases/ql" ,
71- } ,
72- ] ,
73- } ;
74- mockRequest . mockResolvedValue ( mockApiResponse ) ;
75+ mockRequest . mockResolvedValue ( successfullMockApiResponse ) ;
7576 quickPickSpy . mockResolvedValue ( mockedQuickPickItem ( "javascript" ) ) ;
7677 const githubRepo = "github/codeql" ;
7778 const result = await convertGithubNwoToDatabaseUrl (
@@ -127,6 +128,45 @@ describe("databaseFetcher", () => {
127128 ) . rejects . toThrow ( / U n a b l e t o g e t d a t a b a s e / ) ;
128129 expect ( progressSpy ) . toBeCalledTimes ( 1 ) ;
129130 } ) ;
131+
132+ describe ( "when language is already provided" , ( ) => {
133+ describe ( "when language is valid" , ( ) => {
134+ it ( "should not prompt the user" , async ( ) => {
135+ mockRequest . mockResolvedValue ( successfullMockApiResponse ) ;
136+ const githubRepo = "github/codeql" ;
137+ await convertGithubNwoToDatabaseUrl (
138+ githubRepo ,
139+ octokit ,
140+ progressSpy ,
141+ "javascript" ,
142+ ) ;
143+ expect ( quickPickSpy ) . not . toHaveBeenCalled ( ) ;
144+ } ) ;
145+ } ) ;
146+
147+ describe ( "when language is invalid" , ( ) => {
148+ it ( "should prompt for language" , async ( ) => {
149+ mockRequest . mockResolvedValue ( successfullMockApiResponse ) ;
150+ const githubRepo = "github/codeql" ;
151+ await convertGithubNwoToDatabaseUrl (
152+ githubRepo ,
153+ octokit ,
154+ progressSpy ,
155+ "invalid-language" ,
156+ ) ;
157+ expect ( quickPickSpy ) . toHaveBeenCalled ( ) ;
158+ } ) ;
159+ } ) ;
160+ } ) ;
161+
162+ describe ( "when language is not provided" , ( ) => {
163+ it ( "should prompt for language" , async ( ) => {
164+ mockRequest . mockResolvedValue ( successfullMockApiResponse ) ;
165+ const githubRepo = "github/codeql" ;
166+ await convertGithubNwoToDatabaseUrl ( githubRepo , octokit , progressSpy ) ;
167+ expect ( quickPickSpy ) . toHaveBeenCalled ( ) ;
168+ } ) ;
169+ } ) ;
130170 } ) ;
131171
132172 describe ( "findDirWithFile" , ( ) => {
0 commit comments