Skip to content

Commit 9fa6d99

Browse files
Have the skeleton query wizard call promptImportGithubDatabase so we can make more methods private
1 parent f29aff6 commit 9fa6d99

File tree

4 files changed

+29
-74
lines changed

4 files changed

+29
-74
lines changed

extensions/ql-vscode/src/databases/database-fetcher.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,11 @@ export class DatabaseFetcher {
108108
public async promptImportGithubDatabase(
109109
progress: ProgressCallback,
110110
language?: string,
111+
suggestedRepoNwo?: string,
111112
makeSelected = true,
112113
addSourceArchiveFolder = addDatabaseSourceToWorkspace(),
113114
): Promise<DatabaseItem | undefined> {
114-
const githubRepo = await this.askForGitHubRepo(progress);
115+
const githubRepo = await this.askForGitHubRepo(progress, suggestedRepoNwo);
115116
if (!githubRepo) {
116117
return;
117118
}
@@ -138,7 +139,7 @@ export class DatabaseFetcher {
138139
return;
139140
}
140141

141-
public async askForGitHubRepo(
142+
private async askForGitHubRepo(
142143
progress?: ProgressCallback,
143144
suggestedValue?: string,
144145
): Promise<string | undefined> {
@@ -171,7 +172,7 @@ export class DatabaseFetcher {
171172
* @param makeSelected make the new database selected in the databases panel (default: true)
172173
* @param addSourceArchiveFolder whether to add a workspace folder containing the source archive to the workspace
173174
**/
174-
public async downloadGitHubDatabase(
175+
private async downloadGitHubDatabase(
175176
githubRepo: string,
176177
progress: ProgressCallback,
177178
language?: string,

extensions/ql-vscode/src/local-queries/skeleton-query-wizard.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -371,19 +371,10 @@ export class SkeletonQueryWizard {
371371
});
372372

373373
const githubRepoNwo = QUERY_LANGUAGE_TO_DATABASE_REPO[this.language];
374-
const chosenRepo = await this.databaseFetcher.askForGitHubRepo(
375-
undefined,
376-
githubRepoNwo,
377-
);
378-
379-
if (!chosenRepo) {
380-
throw new UserCancellationException("No GitHub repository provided");
381-
}
382-
383-
await this.databaseFetcher.downloadGitHubDatabase(
384-
chosenRepo,
374+
await this.databaseFetcher.promptImportGithubDatabase(
385375
progress,
386376
this.language,
377+
githubRepoNwo,
387378
);
388379
}
389380

extensions/ql-vscode/src/model-editor/model-editor-view.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -925,6 +925,7 @@ export class ModelEditorView extends AbstractWebview<
925925
const addedDatabase = await databaseFetcher.promptImportGithubDatabase(
926926
progress,
927927
this.databaseItem.language,
928+
undefined,
928929
makeSelected,
929930
false,
930931
);

extensions/ql-vscode/test/vscode-tests/cli-integration/local-queries/skeleton-query-wizard.test.ts

Lines changed: 22 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,8 @@ describe("SkeletonQueryWizard", () => {
5656
let createExampleQlFileSpy: jest.SpiedFunction<
5757
typeof QlPackGenerator.prototype.createExampleQlFile
5858
>;
59-
let downloadGitHubDatabaseSpy: jest.SpiedFunction<
60-
DatabaseFetcher["downloadGitHubDatabase"]
61-
>;
62-
let askForGitHubRepoSpy: jest.SpiedFunction<
63-
DatabaseFetcher["askForGitHubRepo"]
59+
let promptImportGithubDatabaseSpy: jest.SpiedFunction<
60+
DatabaseFetcher["promptImportGithubDatabase"]
6461
>;
6562
let openTextDocumentSpy: jest.SpiedFunction<
6663
typeof workspace.openTextDocument
@@ -141,8 +138,8 @@ describe("SkeletonQueryWizard", () => {
141138
createExampleQlFileSpy = jest
142139
.spyOn(QlPackGenerator.prototype, "createExampleQlFile")
143140
.mockResolvedValue(undefined);
144-
downloadGitHubDatabaseSpy = jest
145-
.spyOn(databaseFetcher, "downloadGitHubDatabase")
141+
promptImportGithubDatabaseSpy = jest
142+
.spyOn(databaseFetcher, "promptImportGithubDatabase")
146143
.mockResolvedValue(undefined);
147144
openTextDocumentSpy = jest
148145
.spyOn(workspace, "openTextDocument")
@@ -156,10 +153,6 @@ describe("SkeletonQueryWizard", () => {
156153
databaseFetcher,
157154
selectedItems,
158155
);
159-
160-
askForGitHubRepoSpy = jest
161-
.spyOn(databaseFetcher, "askForGitHubRepo")
162-
.mockResolvedValue(QUERY_LANGUAGE_TO_DATABASE_REPO[chosenLanguage]);
163156
});
164157

165158
afterEach(async () => {
@@ -210,7 +203,7 @@ describe("SkeletonQueryWizard", () => {
210203
title: "Download database",
211204
}),
212205
);
213-
expect(downloadGitHubDatabaseSpy).not.toHaveBeenCalled();
206+
expect(promptImportGithubDatabaseSpy).not.toHaveBeenCalled();
214207
});
215208

216209
it("should download database for selected language when selecting download in prompt", async () => {
@@ -227,7 +220,7 @@ describe("SkeletonQueryWizard", () => {
227220
await wizard.execute();
228221
await wizard.waitForDownload();
229222

230-
expect(downloadGitHubDatabaseSpy).toHaveBeenCalled();
223+
expect(promptImportGithubDatabaseSpy).toHaveBeenCalled();
231224
});
232225

233226
it("should open the query file", async () => {
@@ -336,7 +329,7 @@ describe("SkeletonQueryWizard", () => {
336329
it("should not download a new database for language", async () => {
337330
await wizard.execute();
338331

339-
expect(downloadGitHubDatabaseSpy).not.toHaveBeenCalled();
332+
expect(promptImportGithubDatabaseSpy).not.toHaveBeenCalled();
340333
});
341334

342335
it("should not select the database", async () => {
@@ -385,7 +378,7 @@ describe("SkeletonQueryWizard", () => {
385378
it("should not download a new database for language", async () => {
386379
await wizard.execute();
387380

388-
expect(downloadGitHubDatabaseSpy).not.toHaveBeenCalled();
381+
expect(promptImportGithubDatabaseSpy).not.toHaveBeenCalled();
389382
});
390383

391384
it("should select an existing database", async () => {
@@ -417,54 +410,23 @@ describe("SkeletonQueryWizard", () => {
417410
});
418411

419412
describe("if database is missing", () => {
420-
describe("if the user chooses to downloaded the suggested database from GitHub", () => {
421-
beforeEach(() => {
422-
showInformationMessageSpy.mockImplementation(
423-
async (_message, options, item) => {
424-
if (item === undefined) {
425-
return options as MessageItem;
426-
}
427-
428-
return item;
429-
},
430-
);
431-
});
432-
433-
it("should download a new database for language", async () => {
434-
await wizard.execute();
435-
await wizard.waitForDownload();
436-
437-
expect(askForGitHubRepoSpy).toHaveBeenCalled();
438-
expect(downloadGitHubDatabaseSpy).toHaveBeenCalled();
439-
});
413+
beforeEach(() => {
414+
showInformationMessageSpy.mockImplementation(
415+
async (_message, options, item) => {
416+
if (item === undefined) {
417+
return options as MessageItem;
418+
}
419+
420+
return item;
421+
},
422+
);
440423
});
441424

442-
describe("if the user choses to download a different database from GitHub than the one suggested", () => {
443-
beforeEach(() => {
444-
showInformationMessageSpy.mockImplementation(
445-
async (_message, options, item) => {
446-
if (item === undefined) {
447-
return options as MessageItem;
448-
}
449-
450-
return item;
451-
},
452-
);
453-
454-
const chosenGitHubRepo = "pickles-owner/pickles-repo";
455-
456-
askForGitHubRepoSpy = jest
457-
.spyOn(databaseFetcher, "askForGitHubRepo")
458-
.mockResolvedValue(chosenGitHubRepo);
459-
});
460-
461-
it("should download the newly chosen database", async () => {
462-
await wizard.execute();
463-
await wizard.waitForDownload();
425+
it("should download a new database for language", async () => {
426+
await wizard.execute();
427+
await wizard.waitForDownload();
464428

465-
expect(askForGitHubRepoSpy).toHaveBeenCalled();
466-
expect(downloadGitHubDatabaseSpy).toHaveBeenCalled();
467-
});
429+
expect(promptImportGithubDatabaseSpy).toHaveBeenCalled();
468430
});
469431
});
470432
});

0 commit comments

Comments
 (0)