Move promptAddItem to extension API (#19423)

* Move addItem to extension API

* add noneDeployScripts
This commit is contained in:
Charles Gagnon
2022-05-19 11:25:10 -07:00
committed by GitHub
parent 97a4ecdfbb
commit f2b623b3b2
8 changed files with 111 additions and 82 deletions

View File

@@ -8,7 +8,6 @@ import * as path from 'path';
import * as os from 'os';
import * as sinon from 'sinon';
import * as baselines from './baselines/baselines';
import * as templates from '../templates/templates';
import * as testUtils from './testUtils';
import * as constants from '../common/constants';
@@ -17,7 +16,7 @@ import { Project } from '../models/project';
import { exists, convertSlashesForSqlProj, getWellKnownDatabaseSources } from '../common/utils';
import { Uri, window } from 'vscode';
import { IDacpacReferenceSettings, IProjectReferenceSettings, ISystemDatabaseReferenceSettings } from '../models/IDatabaseReferenceSettings';
import { SqlTargetPlatform } from 'sqldbproj';
import { ItemType, SqlTargetPlatform } from 'sqldbproj';
import { EntryType, SystemDatabaseReferenceProjectEntry, SqlProjectReferenceProjectEntry, SystemDatabase } from '../models/projectEntry';
let projFilePath: string;
@@ -110,7 +109,7 @@ describe('Project: sqlproj content operations', function (): void {
await project.addFolderItem(folderPath);
await project.addScriptItem(scriptPath, scriptContents);
await project.addScriptItem(scriptPathTagged, scriptContentsTagged, templates.externalStreamingJob);
await project.addScriptItem(scriptPathTagged, scriptContentsTagged, ItemType.externalStreamingJob);
const newProject = await Project.openProject(projFilePath);
@@ -542,8 +541,8 @@ describe('Project: sqlproj content operations', function (): void {
const fileContents = ' ';
await project.addFolderItem(folderPath);
await project.addScriptItem(preDeploymentScriptFilePath, fileContents, templates.preDeployScript);
await project.addScriptItem(postDeploymentScriptFilePath, fileContents, templates.postDeployScript);
await project.addScriptItem(preDeploymentScriptFilePath, fileContents, ItemType.preDeployScript);
await project.addScriptItem(postDeploymentScriptFilePath, fileContents, ItemType.postDeployScript);
const newProject = await Project.openProject(projFilePath);
@@ -565,13 +564,13 @@ describe('Project: sqlproj content operations', function (): void {
const fileContents = ' ';
await project.addFolderItem(folderPath);
await project.addScriptItem(preDeploymentScriptFilePath, fileContents, templates.preDeployScript);
await project.addScriptItem(postDeploymentScriptFilePath, fileContents, templates.postDeployScript);
await project.addScriptItem(preDeploymentScriptFilePath, fileContents, ItemType.preDeployScript);
await project.addScriptItem(postDeploymentScriptFilePath, fileContents, ItemType.postDeployScript);
await project.addScriptItem(preDeploymentScriptFilePath2, fileContents, templates.preDeployScript);
await project.addScriptItem(preDeploymentScriptFilePath2, fileContents, ItemType.preDeployScript);
should(stub.calledWith(constants.deployScriptExists(constants.PreDeploy))).be.true(`showInformationMessage not called with expected message '${constants.deployScriptExists(constants.PreDeploy)}' Actual '${stub.getCall(0).args[0]}'`);
await project.addScriptItem(postDeploymentScriptFilePath2, fileContents, templates.postDeployScript);
await project.addScriptItem(postDeploymentScriptFilePath2, fileContents, ItemType.postDeployScript);
should(stub.calledWith(constants.deployScriptExists(constants.PostDeploy))).be.true(`showInformationMessage not called with expected message '${constants.deployScriptExists(constants.PostDeploy)}' Actual '${stub.getCall(0).args[0]}'`);
const newProject = await Project.openProject(projFilePath);
@@ -1026,9 +1025,9 @@ describe('Project: sdk style project content operations', function (): void {
projFilePath = await testUtils.createTestSqlProjFile(baselines.newSdkStyleProjectSdkNodeBaseline, folderPath);
const project: Project = await Project.openProject(projFilePath);
await project.addScriptItem('Script.PreDeployment1.sql', 'fake contents', templates.preDeployScript);
await project.addScriptItem('Script.PreDeployment2.sql', 'fake contents', templates.preDeployScript);
await project.addScriptItem('Script.PostDeployment1.sql', 'fake contents', templates.postDeployScript);
await project.addScriptItem('Script.PreDeployment1.sql', 'fake contents', ItemType.preDeployScript);
await project.addScriptItem('Script.PreDeployment2.sql', 'fake contents', ItemType.preDeployScript);
await project.addScriptItem('Script.PostDeployment1.sql', 'fake contents', ItemType.postDeployScript);
// verify they were added to the sqlproj
let projFileText = (await fs.readFile(projFilePath)).toString();
@@ -1119,7 +1118,7 @@ describe('Project: sdk style project content operations', function (): void {
const otherFolderPath = 'OtherFolder\\';
await project.addScriptItem(scriptPath, scriptContents);
await project.addScriptItem(scriptPathTagged, scriptContentsTagged, templates.externalStreamingJob);
await project.addScriptItem(scriptPathTagged, scriptContentsTagged, ItemType.externalStreamingJob);
await project.addScriptItem(outsideFolderScriptPath, outsideFolderScriptContents);
await project.addFolderItem(otherFolderPath);

View File

@@ -30,7 +30,7 @@ import { AddDatabaseReferenceDialog } from '../dialogs/addDatabaseReferenceDialo
import { IDacpacReferenceSettings } from '../models/IDatabaseReferenceSettings';
import { CreateProjectFromDatabaseDialog } from '../dialogs/createProjectFromDatabaseDialog';
import { ImportDataModel } from '../models/api/import';
import { SqlTargetPlatform } from 'sqldbproj';
import { ItemType, SqlTargetPlatform } from 'sqldbproj';
import { SystemDatabaseReferenceProjectEntry, SystemDatabase, EntryType, FileProjectEntry } from '../models/projectEntry';
let testContext: TestContext;
@@ -96,7 +96,7 @@ describe('ProjectsController', function (): void {
const project = new Project('FakePath');
should(project.files.length).equal(0);
await projController.addItemPrompt(new Project('FakePath'), '', templates.script);
await projController.addItemPrompt(new Project('FakePath'), '', ItemType.script);
should(project.files.length).equal(0, 'Expected to return without throwing an exception or adding a file when an empty/undefined name is provided.');
should(showErrorMessageSpy.notCalled).be.true('showErrorMessage should not have been called');
showInputBoxStub.restore();
@@ -112,9 +112,9 @@ describe('ProjectsController', function (): void {
const project = await testUtils.createTestProject(baselines.newProjectFileBaseline);
should(project.files.length).equal(0, 'There should be no files');
await projController.addItemPrompt(project, '', templates.script);
await projController.addItemPrompt(project, '', ItemType.script);
should(project.files.length).equal(1, 'File should be successfully added');
await projController.addItemPrompt(project, '', templates.script);
await projController.addItemPrompt(project, '', ItemType.script);
const msg = constants.fileAlreadyExists(tableName);
should(spy.calledOnce).be.true('showErrorMessage should have been called exactly once');
should(spy.calledWith(msg)).be.true(`showErrorMessage not called with expected message '${msg}' Actual '${spy.getCall(0).args[0]}'`);
@@ -327,13 +327,13 @@ describe('ProjectsController', function (): void {
sinon.stub(vscode.window, 'showInputBox').resolves(preDeployScriptName);
should(project.preDeployScripts.length).equal(0, 'There should be no pre deploy scripts');
await projController.addItemPrompt(project, '', templates.preDeployScript);
await projController.addItemPrompt(project, '', ItemType.preDeployScript);
should(project.preDeployScripts.length).equal(1, `Pre deploy script should be successfully added. ${project.preDeployScripts.length}, ${project.files.length}`);
sinon.restore();
sinon.stub(vscode.window, 'showInputBox').resolves(postDeployScriptName);
should(project.postDeployScripts.length).equal(0, 'There should be no post deploy scripts');
await projController.addItemPrompt(project, '', templates.postDeployScript);
await projController.addItemPrompt(project, '', ItemType.postDeployScript);
should(project.postDeployScripts.length).equal(1, 'Post deploy script should be successfully added');
});
@@ -739,9 +739,9 @@ async function setupDeleteExcludeTest(proj: Project): Promise<[FileProjectEntry,
const scriptEntry = await proj.addScriptItem('UpperFolder/LowerFolder/someScript.sql', 'not a real script');
await proj.addScriptItem('UpperFolder/LowerFolder/someOtherScript.sql', 'Also not a real script');
await proj.addScriptItem('../anotherScript.sql', 'Also not a real script');
const preDeployEntry = await proj.addScriptItem('Script.PreDeployment1.sql', 'pre-deployment stuff', templates.preDeployScript);
const noneEntry = await proj.addScriptItem('Script.PreDeployment2.sql', 'more pre-deployment stuff', templates.preDeployScript);
const postDeployEntry = await proj.addScriptItem('Script.PostDeployment1.sql', 'post-deployment stuff', templates.postDeployScript);
const preDeployEntry = await proj.addScriptItem('Script.PreDeployment1.sql', 'pre-deployment stuff', ItemType.preDeployScript);
const noneEntry = await proj.addScriptItem('Script.PreDeployment2.sql', 'more pre-deployment stuff', ItemType.preDeployScript);
const postDeployEntry = await proj.addScriptItem('Script.PostDeployment1.sql', 'post-deployment stuff', ItemType.postDeployScript);
const projTreeRoot = new ProjectRootTreeItem(proj);
sinon.stub(vscode.window, 'showWarningMessage').returns(<any>Promise.resolve(constants.yesString));