Update action run return type (#15568)

* Update action run return type

* fix tests

* Update rest

* Add back null checks
This commit is contained in:
Charles Gagnon
2021-05-25 14:52:39 -07:00
committed by GitHub
parent 25352fa39c
commit 399406b732
29 changed files with 379 additions and 637 deletions

View File

@@ -47,17 +47,8 @@ export class JobsRefreshAction extends Action {
super(JobsRefreshAction.ID, JobsRefreshAction.LABEL, 'refreshIcon');
}
public run(context: IJobActionInfo): Promise<boolean> {
return new Promise<boolean>((resolve, reject) => {
if (context) {
if (context.component) {
context.component.refreshJobs();
}
resolve(true);
} else {
reject(false);
}
});
public async run(context?: IJobActionInfo): Promise<void> {
context?.component?.refreshJobs();
}
}
@@ -70,16 +61,9 @@ export class NewJobAction extends Action {
super(NewJobAction.ID, NewJobAction.LABEL, 'newStepIcon');
}
public run(context: IJobActionInfo): Promise<boolean> {
let component = context.component as JobsViewComponent;
return new Promise<boolean>(async (resolve, reject) => {
try {
await component.openCreateJobDialog();
resolve(true);
} catch (e) {
reject(e);
}
});
public async run(context: IJobActionInfo): Promise<void> {
const component = context.component as JobsViewComponent;
await component.openCreateJobDialog();
}
}
@@ -97,24 +81,19 @@ export class RunJobAction extends Action {
super(RunJobAction.ID, RunJobAction.LABEL, 'start');
}
public run(context: IJobActionInfo): Promise<boolean> {
public async run(context: IJobActionInfo): Promise<void> {
let jobName = context.targetObject.job.name;
let ownerUri = context.ownerUri;
let refreshAction = this.instantationService.createInstance(JobsRefreshAction);
this.telemetryService.sendActionEvent(TelemetryView.Agent, TelemetryAction.RunAgentJob);
return new Promise<boolean>((resolve, reject) => {
this.jobManagementService.jobAction(ownerUri, jobName, JobActions.Run).then(async (result) => {
if (result.success) {
let startMsg = nls.localize('jobSuccessfullyStarted', ": The job was successfully started.");
this.notificationService.info(jobName + startMsg);
await refreshAction.run(context);
resolve(true);
} else {
this.errorMessageService.showDialog(Severity.Error, errorLabel, result.errorMessage);
resolve(false);
}
});
});
const result = await this.jobManagementService.jobAction(ownerUri, jobName, JobActions.Run);
if (result.success) {
let startMsg = nls.localize('jobSuccessfullyStarted', ": The job was successfully started.");
this.notificationService.info(jobName + startMsg);
await refreshAction.run(context);
} else {
this.errorMessageService.showDialog(Severity.Error, errorLabel, result.errorMessage);
}
}
}
@@ -132,24 +111,19 @@ export class StopJobAction extends Action {
super(StopJobAction.ID, StopJobAction.LABEL, 'stop');
}
public run(context: IJobActionInfo): Promise<boolean> {
public async run(context: IJobActionInfo): Promise<void> {
let jobName = context.targetObject.name;
let ownerUri = context.ownerUri;
let refreshAction = this.instantationService.createInstance(JobsRefreshAction);
this.telemetryService.sendActionEvent(TelemetryView.Agent, TelemetryAction.StopAgentJob);
return new Promise<boolean>((resolve, reject) => {
this.jobManagementService.jobAction(ownerUri, jobName, JobActions.Stop).then(async (result) => {
if (result.success) {
await refreshAction.run(context);
let stopMsg = nls.localize('jobSuccessfullyStopped', ": The job was successfully stopped.");
this.notificationService.info(jobName + stopMsg);
resolve(true);
} else {
this.errorMessageService.showDialog(Severity.Error, 'Error', result.errorMessage);
resolve(false);
}
});
});
const result = await this.jobManagementService.jobAction(ownerUri, jobName, JobActions.Stop);
if (result.success) {
await refreshAction.run(context);
let stopMsg = nls.localize('jobSuccessfullyStopped', ": The job was successfully stopped.");
this.notificationService.info(jobName + stopMsg);
} else {
this.errorMessageService.showDialog(Severity.Error, 'Error', result.errorMessage);
}
}
}
@@ -163,12 +137,11 @@ export class EditJobAction extends Action {
super(EditJobAction.ID, EditJobAction.LABEL, 'edit');
}
public run(actionInfo: IJobActionInfo): Promise<boolean> {
this._commandService.executeCommand(
public async run(actionInfo: IJobActionInfo): Promise<void> {
await this._commandService.executeCommand(
'agent.openJobDialog',
actionInfo.ownerUri,
actionInfo.targetObject.job);
return Promise.resolve(true);
}
}
@@ -180,9 +153,8 @@ export class OpenMaterializedNotebookAction extends Action {
super(OpenMaterializedNotebookAction.ID, OpenMaterializedNotebookAction.LABEL, 'openNotebook');
}
public run(context: any): Promise<boolean> {
public async run(context: any): Promise<void> {
context.component.openNotebook(context.history);
return Promise.resolve(true);
}
}
@@ -199,24 +171,23 @@ export class DeleteJobAction extends Action {
super(DeleteJobAction.ID, DeleteJobAction.LABEL);
}
public run(actionInfo: IJobActionInfo): Promise<boolean> {
let self = this;
public async run(actionInfo: IJobActionInfo): Promise<void> {
let job = actionInfo.targetObject.job as azdata.AgentJobInfo;
self._notificationService.prompt(
this._notificationService.prompt(
Severity.Info,
nls.localize('jobaction.deleteJobConfirm', "Are you sure you'd like to delete the job '{0}'?", job.name),
[{
label: DeleteJobAction.LABEL,
run: () => {
this._telemetryService.sendActionEvent(TelemetryView.Agent, TelemetryAction.DeleteAgentJob);
self._jobService.deleteJob(actionInfo.ownerUri, actionInfo.targetObject.job).then(result => {
this._jobService.deleteJob(actionInfo.ownerUri, actionInfo.targetObject.job).then(result => {
if (!result || !result.success) {
let errorMessage = nls.localize("jobaction.failedToDeleteJob", "Could not delete job '{0}'.\nError: {1}",
job.name, result.errorMessage ? result.errorMessage : 'Unknown error');
self._errorMessageService.showDialog(Severity.Error, errorLabel, errorMessage);
this._errorMessageService.showDialog(Severity.Error, errorLabel, errorMessage);
} else {
let successMessage = nls.localize('jobaction.deletedJob', "The job was successfully deleted");
self._notificationService.info(successMessage);
this._notificationService.info(successMessage);
}
});
}
@@ -225,7 +196,6 @@ export class DeleteJobAction extends Action {
run: () => { }
}]
);
return Promise.resolve(true);
}
}
@@ -241,13 +211,11 @@ export class NewStepAction extends Action {
super(NewStepAction.ID, NewStepAction.LABEL, 'newStepIcon');
}
public run(context: JobHistoryComponent): Promise<boolean> {
public async run(context: JobHistoryComponent): Promise<void> {
let ownerUri = context.ownerUri;
let server = context.serverName;
let jobInfo = context.agentJobInfo;
return new Promise<boolean>((resolve, reject) => {
resolve(this._commandService.executeCommand('agent.openNewStepDialog', ownerUri, server, jobInfo, null));
});
await this._commandService.executeCommand('agent.openNewStepDialog', ownerUri, server, jobInfo, undefined);
}
}
@@ -265,26 +233,25 @@ export class DeleteStepAction extends Action {
super(DeleteStepAction.ID, DeleteStepAction.LABEL);
}
public run(actionInfo: IJobActionInfo): Promise<boolean> {
let self = this;
public async run(actionInfo: IJobActionInfo): Promise<void> {
let step = actionInfo.targetObject as azdata.AgentJobStepInfo;
let refreshAction = this.instantationService.createInstance(JobsRefreshAction);
self._notificationService.prompt(
this._notificationService.prompt(
Severity.Info,
nls.localize('jobaction.deleteStepConfirm', "Are you sure you'd like to delete the step '{0}'?", step.stepName),
[{
label: DeleteStepAction.LABEL,
run: () => {
this._telemetryService.sendActionEvent(TelemetryView.Agent, TelemetryAction.DeleteAgentJobStep);
self._jobService.deleteJobStep(actionInfo.ownerUri, actionInfo.targetObject).then(async (result) => {
this._jobService.deleteJobStep(actionInfo.ownerUri, actionInfo.targetObject).then(async (result) => {
if (!result || !result.success) {
let errorMessage = nls.localize('jobaction.failedToDeleteStep', "Could not delete step '{0}'.\nError: {1}",
step.stepName, result.errorMessage ? result.errorMessage : 'Unknown error');
self._errorMessageService.showDialog(Severity.Error, errorLabel, errorMessage);
this._errorMessageService.showDialog(Severity.Error, errorLabel, errorMessage);
await refreshAction.run(actionInfo);
} else {
let successMessage = nls.localize('jobaction.deletedStep', "The job step was successfully deleted");
self._notificationService.info(successMessage);
this._notificationService.info(successMessage);
}
});
}
@@ -293,7 +260,6 @@ export class DeleteStepAction extends Action {
run: () => { }
}]
);
return Promise.resolve(true);
}
}
@@ -308,16 +274,9 @@ export class NewAlertAction extends Action {
super(NewAlertAction.ID, NewAlertAction.LABEL, 'newStepIcon');
}
public run(context: IJobActionInfo): Promise<boolean> {
public async run(context: IJobActionInfo): Promise<void> {
let component = context.component as AlertsViewComponent;
return new Promise<boolean>((resolve, reject) => {
try {
component.openCreateAlertDialog();
resolve(true);
} catch (e) {
reject(e);
}
});
await component.openCreateAlertDialog();
}
}
@@ -331,13 +290,12 @@ export class EditAlertAction extends Action {
super(EditAlertAction.ID, EditAlertAction.LABEL);
}
public run(actionInfo: IJobActionInfo): Promise<boolean> {
this._commandService.executeCommand(
public async run(actionInfo: IJobActionInfo): Promise<void> {
await this._commandService.executeCommand(
'agent.openAlertDialog',
actionInfo.ownerUri,
actionInfo.targetObject.jobInfo,
actionInfo.targetObject.alertInfo);
return Promise.resolve(true);
}
}
@@ -355,33 +313,30 @@ export class DeleteAlertAction extends Action {
super(DeleteAlertAction.ID, DeleteAlertAction.LABEL);
}
public run(actionInfo: IJobActionInfo): Promise<boolean> {
let self = this;
public async run(actionInfo: IJobActionInfo): Promise<void> {
let alert = actionInfo.targetObject.alertInfo as azdata.AgentAlertInfo;
self._notificationService.prompt(
this._notificationService.prompt(
Severity.Info,
nls.localize('jobaction.deleteAlertConfirm', "Are you sure you'd like to delete the alert '{0}'?", alert.name),
[{
label: DeleteAlertAction.LABEL,
run: () => {
self._telemetryService.sendActionEvent(TelemetryView.Agent, TelemetryAction.DeleteAgentAlert);
self._jobService.deleteAlert(actionInfo.ownerUri, alert).then(result => {
if (!result || !result.success) {
let errorMessage = nls.localize("jobaction.failedToDeleteAlert", "Could not delete alert '{0}'.\nError: {1}",
alert.name, result.errorMessage ? result.errorMessage : 'Unknown error');
self._errorMessageService.showDialog(Severity.Error, errorLabel, errorMessage);
} else {
let successMessage = nls.localize('jobaction.deletedAlert', "The alert was successfully deleted");
self._notificationService.info(successMessage);
}
});
run: async () => {
this._telemetryService.sendActionEvent(TelemetryView.Agent, TelemetryAction.DeleteAgentAlert);
const result = await this._jobService.deleteAlert(actionInfo.ownerUri, alert);
if (!result || !result.success) {
let errorMessage = nls.localize("jobaction.failedToDeleteAlert", "Could not delete alert '{0}'.\nError: {1}",
alert.name, result.errorMessage ? result.errorMessage : 'Unknown error');
this._errorMessageService.showDialog(Severity.Error, errorLabel, errorMessage);
} else {
let successMessage = nls.localize('jobaction.deletedAlert', "The alert was successfully deleted");
this._notificationService.info(successMessage);
}
}
}, {
label: DeleteAlertAction.CancelLabel,
run: () => { }
}]
);
return Promise.resolve(true);
}
}
@@ -396,16 +351,9 @@ export class NewOperatorAction extends Action {
super(NewOperatorAction.ID, NewOperatorAction.LABEL, 'newStepIcon');
}
public run(context: IJobActionInfo): Promise<boolean> {
public async run(context: IJobActionInfo): Promise<void> {
let component = context.component as OperatorsViewComponent;
return new Promise<boolean>((resolve, reject) => {
try {
component.openCreateOperatorDialog();
resolve(true);
} catch (e) {
reject(e);
}
});
await component.openCreateOperatorDialog();
}
}
@@ -419,12 +367,11 @@ export class EditOperatorAction extends Action {
super(EditOperatorAction.ID, EditOperatorAction.LABEL);
}
public run(actionInfo: IJobActionInfo): Promise<boolean> {
this._commandService.executeCommand(
public async run(actionInfo: IJobActionInfo): Promise<void> {
await this._commandService.executeCommand(
'agent.openOperatorDialog',
actionInfo.ownerUri,
actionInfo.targetObject);
return Promise.resolve(true);
}
}
@@ -441,33 +388,30 @@ export class DeleteOperatorAction extends Action {
super(DeleteOperatorAction.ID, DeleteOperatorAction.LABEL);
}
public run(actionInfo: IJobActionInfo): Promise<boolean> {
const self = this;
public async run(actionInfo: IJobActionInfo): Promise<void> {
let operator = actionInfo.targetObject as azdata.AgentOperatorInfo;
self._notificationService.prompt(
this._notificationService.prompt(
Severity.Info,
nls.localize('jobaction.deleteOperatorConfirm', "Are you sure you'd like to delete the operator '{0}'?", operator.name),
[{
label: DeleteOperatorAction.LABEL,
run: () => {
self._telemetryService.sendActionEvent(TelemetryView.Agent, TelemetryAction.DeleteAgentOperator);
self._jobService.deleteOperator(actionInfo.ownerUri, actionInfo.targetObject).then(result => {
if (!result || !result.success) {
let errorMessage = nls.localize("jobaction.failedToDeleteOperator", "Could not delete operator '{0}'.\nError: {1}",
operator.name, result.errorMessage ? result.errorMessage : 'Unknown error');
self._errorMessageService.showDialog(Severity.Error, errorLabel, errorMessage);
} else {
let successMessage = nls.localize('joaction.deletedOperator', "The operator was deleted successfully");
self._notificationService.info(successMessage);
}
});
run: async () => {
this._telemetryService.sendActionEvent(TelemetryView.Agent, TelemetryAction.DeleteAgentOperator);
const result = await this._jobService.deleteOperator(actionInfo.ownerUri, actionInfo.targetObject);
if (!result || !result.success) {
let errorMessage = nls.localize("jobaction.failedToDeleteOperator", "Could not delete operator '{0}'.\nError: {1}",
operator.name, result.errorMessage ? result.errorMessage : 'Unknown error');
this._errorMessageService.showDialog(Severity.Error, errorLabel, errorMessage);
} else {
let successMessage = nls.localize('joaction.deletedOperator', "The operator was deleted successfully");
this._notificationService.info(successMessage);
}
}
}, {
label: DeleteAlertAction.CancelLabel,
run: () => { }
}]
);
return Promise.resolve(true);
}
}
@@ -483,16 +427,9 @@ export class NewProxyAction extends Action {
super(NewProxyAction.ID, NewProxyAction.LABEL, 'newStepIcon');
}
public run(context: IJobActionInfo): Promise<boolean> {
let component = context.component as ProxiesViewComponent;
return new Promise<boolean>((resolve, reject) => {
try {
component.openCreateProxyDialog();
resolve(true);
} catch (e) {
reject(e);
}
});
public async run(context: IJobActionInfo): Promise<void> {
const component = context.component as ProxiesViewComponent;
component.openCreateProxyDialog();
}
}
@@ -507,19 +444,15 @@ export class EditProxyAction extends Action {
super(EditProxyAction.ID, EditProxyAction.LABEL);
}
public run(actionInfo: IJobActionInfo): Promise<boolean> {
return Promise.resolve(this._jobManagementService.getCredentials(actionInfo.ownerUri).then((result) => {
if (result && result.credentials) {
this._commandService.executeCommand(
'agent.openProxyDialog',
actionInfo.ownerUri,
actionInfo.targetObject,
result.credentials);
return true;
} else {
return false;
}
}));
public async run(actionInfo: IJobActionInfo): Promise<void> {
const result = await this._jobManagementService.getCredentials(actionInfo.ownerUri);
if (result && result.credentials) {
await this._commandService.executeCommand(
'agent.openProxyDialog',
actionInfo.ownerUri,
actionInfo.targetObject,
result.credentials);
}
}
}
@@ -536,33 +469,30 @@ export class DeleteProxyAction extends Action {
super(DeleteProxyAction.ID, DeleteProxyAction.LABEL);
}
public run(actionInfo: IJobActionInfo): Promise<boolean> {
let self = this;
public async run(actionInfo: IJobActionInfo): Promise<void> {
let proxy = actionInfo.targetObject as azdata.AgentProxyInfo;
self._notificationService.prompt(
this._notificationService.prompt(
Severity.Info,
nls.localize('jobaction.deleteProxyConfirm', "Are you sure you'd like to delete the proxy '{0}'?", proxy.accountName),
[{
label: DeleteProxyAction.LABEL,
run: () => {
self._telemetryService.sendActionEvent(TelemetryView.Agent, TelemetryAction.DeleteAgentProxy);
self._jobService.deleteProxy(actionInfo.ownerUri, actionInfo.targetObject).then(result => {
if (!result || !result.success) {
let errorMessage = nls.localize("jobaction.failedToDeleteProxy", "Could not delete proxy '{0}'.\nError: {1}",
proxy.accountName, result.errorMessage ? result.errorMessage : 'Unknown error');
self._errorMessageService.showDialog(Severity.Error, errorLabel, errorMessage);
} else {
let successMessage = nls.localize('jobaction.deletedProxy', "The proxy was deleted successfully");
self._notificationService.info(successMessage);
}
});
run: async () => {
this._telemetryService.sendActionEvent(TelemetryView.Agent, TelemetryAction.DeleteAgentProxy);
const result = await this._jobService.deleteProxy(actionInfo.ownerUri, actionInfo.targetObject);
if (!result || !result.success) {
let errorMessage = nls.localize("jobaction.failedToDeleteProxy", "Could not delete proxy '{0}'.\nError: {1}",
proxy.accountName, result.errorMessage ? result.errorMessage : 'Unknown error');
this._errorMessageService.showDialog(Severity.Error, errorLabel, errorMessage);
} else {
let successMessage = nls.localize('jobaction.deletedProxy', "The proxy was deleted successfully");
this._notificationService.info(successMessage);
}
}
}, {
label: DeleteAlertAction.CancelLabel,
run: () => { }
}]
);
return Promise.resolve(true);
}
}
@@ -577,10 +507,9 @@ export class NewNotebookJobAction extends Action {
super(NewNotebookJobAction.ID, NewNotebookJobAction.LABEL, 'newStepIcon');
}
public async run(context: IJobActionInfo): Promise<boolean> {
public async run(context: IJobActionInfo): Promise<void> {
let component = context.component as NotebooksViewComponent;
await component.openCreateNotebookDialog();
return true;
}
}
@@ -594,12 +523,11 @@ export class EditNotebookJobAction extends Action {
super(EditNotebookJobAction.ID, EditNotebookJobAction.LABEL, 'edit');
}
public run(actionInfo: IJobActionInfo): Promise<boolean> {
this._commandService.executeCommand(
public async run(actionInfo: IJobActionInfo): Promise<void> {
await this._commandService.executeCommand(
'agent.openNotebookDialog',
actionInfo.ownerUri,
actionInfo.targetObject.job);
return Promise.resolve(true);
}
}
@@ -611,9 +539,8 @@ export class OpenTemplateNotebookAction extends Action {
super(OpenTemplateNotebookAction.ID, OpenTemplateNotebookAction.LABEL, 'opennotebook');
}
public run(actionInfo: any): Promise<boolean> {
public async run(actionInfo: any): Promise<void> {
actionInfo.component.openTemplateNotebook();
return Promise.resolve(true);
}
}
@@ -631,35 +558,32 @@ export class DeleteNotebookAction extends Action {
super(DeleteNotebookAction.ID, DeleteNotebookAction.LABEL);
}
public run(actionInfo: IJobActionInfo): Promise<boolean> {
let self = this;
public async run(actionInfo: IJobActionInfo): Promise<void> {
let notebook = actionInfo.targetObject.job as azdata.AgentNotebookInfo;
let refreshAction = this.instantationService.createInstance(JobsRefreshAction);
self._notificationService.prompt(
this._notificationService.prompt(
Severity.Info,
nls.localize('jobaction.deleteNotebookConfirm', "Are you sure you'd like to delete the notebook '{0}'?", notebook.name),
[{
label: DeleteNotebookAction.LABEL,
run: () => {
self._telemetryService.sendActionEvent(TelemetryView.Agent, TelemetryAction.DeleteAgentJob);
self._jobService.deleteNotebook(actionInfo.ownerUri, actionInfo.targetObject.job).then(async (result) => {
if (!result || !result.success) {
await refreshAction.run(actionInfo);
let errorMessage = nls.localize("jobaction.failedToDeleteNotebook", "Could not delete notebook '{0}'.\nError: {1}",
notebook.name, result.errorMessage ? result.errorMessage : 'Unknown error');
self._errorMessageService.showDialog(Severity.Error, errorLabel, errorMessage);
} else {
let successMessage = nls.localize('jobaction.deletedNotebook', "The notebook was successfully deleted");
self._notificationService.info(successMessage);
}
});
run: async () => {
this._telemetryService.sendActionEvent(TelemetryView.Agent, TelemetryAction.DeleteAgentJob);
const result = await this._jobService.deleteNotebook(actionInfo.ownerUri, actionInfo.targetObject.job);
if (!result || !result.success) {
await refreshAction.run(actionInfo);
let errorMessage = nls.localize("jobaction.failedToDeleteNotebook", "Could not delete notebook '{0}'.\nError: {1}",
notebook.name, result.errorMessage ? result.errorMessage : 'Unknown error');
this._errorMessageService.showDialog(Severity.Error, errorLabel, errorMessage);
} else {
let successMessage = nls.localize('jobaction.deletedNotebook', "The notebook was successfully deleted");
this._notificationService.info(successMessage);
}
}
}, {
label: DeleteAlertAction.CancelLabel,
run: () => { }
}]
);
return Promise.resolve(true);
}
}
@@ -672,9 +596,8 @@ export class PinNotebookMaterializedAction extends Action {
super(PinNotebookMaterializedAction.ID, PinNotebookMaterializedAction.LABEL);
}
public run(actionInfo: any): Promise<boolean> {
public async run(actionInfo: any): Promise<void> {
actionInfo.component.toggleNotebookPin(actionInfo.history, true);
return Promise.resolve(true);
}
}
@@ -686,9 +609,8 @@ export class DeleteMaterializedNotebookAction extends Action {
super(DeleteMaterializedNotebookAction.ID, DeleteMaterializedNotebookAction.LABEL);
}
public run(actionInfo: any): Promise<boolean> {
public async run(actionInfo: any): Promise<void> {
actionInfo.component.deleteMaterializedNotebook(actionInfo.history);
return Promise.resolve(true);
}
}
@@ -700,9 +622,8 @@ export class UnpinNotebookMaterializedAction extends Action {
super(UnpinNotebookMaterializedAction.ID, UnpinNotebookMaterializedAction.LABEL);
}
public run(actionInfo: any): Promise<boolean> {
public async run(actionInfo: any): Promise<void> {
actionInfo.component.toggleNotebookPin(actionInfo.history, false);
return Promise.resolve(true);
}
}
@@ -714,9 +635,8 @@ export class RenameNotebookMaterializedAction extends Action {
super(RenameNotebookMaterializedAction.ID, RenameNotebookMaterializedAction.LABEL);
}
public run(actionInfo: any): Promise<boolean> {
public async run(actionInfo: any): Promise<void> {
actionInfo.component.renameNotebook(actionInfo.history);
return Promise.resolve(true);
}
}
@@ -728,8 +648,7 @@ export class OpenLatestRunMaterializedNotebook extends Action {
super(OpenLatestRunMaterializedNotebook.ID, OpenLatestRunMaterializedNotebook.LABEL);
}
public run(actionInfo: IJobActionInfo): Promise<boolean> {
public async run(actionInfo: IJobActionInfo): Promise<void> {
actionInfo.component.openLastNRun(actionInfo.targetObject.job, 0, 1);
return Promise.resolve(true);
}
}

View File

@@ -108,11 +108,7 @@ suite('Job Management Actions', () => {
test('Edit Job Action', async () => {
mockEditJobAction = TypeMoq.Mock.ofType(EditJobAction, TypeMoq.MockBehavior.Strict, EditJobAction.ID, EditJobAction.LABEL);
let commandServiceCalled: boolean = false;
mockEditJobAction.setup(s => s.run(TypeMoq.It.isAny())).returns(() => {
commandServiceCalled = true;
return Promise.resolve(commandServiceCalled);
});
mockEditJobAction.setup(s => s.run(TypeMoq.It.isAny()));
mockEditJobAction.setup(s => s.id).returns(() => EditJobAction.ID);
mockEditJobAction.setup(s => s.label).returns(() => EditJobAction.LABEL);
assert.equal(mockEditJobAction.object.id, EditJobAction.ID);
@@ -120,14 +116,13 @@ suite('Job Management Actions', () => {
// Edit Job Action from Jobs View should open a dialog
await mockEditJobAction.object.run(null);
assert(commandServiceCalled);
mockEditJobAction.verify(s => s.run(TypeMoq.It.isAny()), TypeMoq.Times.once());
});
test('Run Job Action', async () => {
mockRunJobAction = TypeMoq.Mock.ofType(RunJobAction, TypeMoq.MockBehavior.Strict, RunJobAction.ID, RunJobAction.LABEL, null, null, mockJobManagementService);
mockRunJobAction.setup(s => s.run(TypeMoq.It.isAny())).returns(async () => {
let result = await mockJobManagementService.object.jobAction(null, null, null).then((result) => result.success);
return result;
await mockJobManagementService.object.jobAction(null, null, null);
});
mockRunJobAction.setup(s => s.id).returns(() => RunJobAction.ID);
@@ -143,8 +138,7 @@ suite('Job Management Actions', () => {
test('Stop Job Action', async () => {
mockStopJobAction = TypeMoq.Mock.ofType(StopJobAction, TypeMoq.MockBehavior.Strict, StopJobAction.ID, StopJobAction.LABEL, null, null, mockJobManagementService);
mockStopJobAction.setup(s => s.run(TypeMoq.It.isAny())).returns(async () => {
let result = await mockJobManagementService.object.jobAction(null, null, null).then((result) => result.success);
return result;
await mockJobManagementService.object.jobAction(null, null, null);
});
mockStopJobAction.setup(s => s.id).returns(() => RunJobAction.ID);
@@ -160,8 +154,7 @@ suite('Job Management Actions', () => {
test('Delete Job Action', async () => {
mockDeleteJobAction = TypeMoq.Mock.ofType(DeleteJobAction, TypeMoq.MockBehavior.Strict, DeleteJobAction.ID, DeleteJobAction.LABEL, null, null, mockJobManagementService);
mockDeleteJobAction.setup(s => s.run(TypeMoq.It.isAny())).returns(async () => {
let result = await mockJobManagementService.object.jobAction(null, null, null).then((result) => result.success);
return result;
await mockJobManagementService.object.jobAction(null, null, null);
});
mockDeleteJobAction.setup(s => s.id).returns(() => DeleteJobAction.ID);
@@ -177,11 +170,7 @@ suite('Job Management Actions', () => {
// Step Actions
test('New Step Action', async () => {
mockNewStepAction = TypeMoq.Mock.ofType(NewStepAction, TypeMoq.MockBehavior.Strict, NewJobAction.ID, NewJobAction.LABEL);
let commandServiceCalled = false;
mockNewStepAction.setup(s => s.run(TypeMoq.It.isAny())).returns(() => {
commandServiceCalled = true;
return Promise.resolve(commandServiceCalled);
});
mockNewStepAction.setup(s => s.run(TypeMoq.It.isAny()));
mockNewStepAction.setup(s => s.id).returns(() => NewJobAction.ID);
mockNewStepAction.setup(s => s.label).returns(() => NewJobAction.LABEL);
assert.equal(mockNewStepAction.object.id, NewJobAction.ID);
@@ -189,16 +178,13 @@ suite('Job Management Actions', () => {
// New Step Action should called command service
await mockNewStepAction.object.run(null);
assert(commandServiceCalled);
mockNewStepAction.verify(s => s.run(TypeMoq.It.isAny()), TypeMoq.Times.once());
});
test('Delete Step Action', async () => {
mockDeleteStepAction = TypeMoq.Mock.ofType(DeleteStepAction, TypeMoq.MockBehavior.Strict, DeleteStepAction.ID, DeleteStepAction.LABEL);
let commandServiceCalled = false;
mockDeleteStepAction.setup(s => s.run(TypeMoq.It.isAny())).returns(async () => {
commandServiceCalled = true;
await mockJobManagementService.object.deleteJobStep(null, null).then((result) => result.success);
return commandServiceCalled;
await mockJobManagementService.object.deleteJobStep(null, null);
});
mockDeleteStepAction.setup(s => s.id).returns(() => DeleteStepAction.ID);
mockDeleteStepAction.setup(s => s.label).returns(() => DeleteStepAction.LABEL);
@@ -207,7 +193,6 @@ suite('Job Management Actions', () => {
// Delete Step Action should called command service
await mockDeleteStepAction.object.run(null);
assert(commandServiceCalled);
mockJobManagementService.verify(s => s.deleteJobStep(null, null), TypeMoq.Times.once());
});
@@ -227,11 +212,7 @@ suite('Job Management Actions', () => {
test('Edit Alert Action', async () => {
mockEditAlertAction = TypeMoq.Mock.ofType(EditAlertAction, TypeMoq.MockBehavior.Strict, EditAlertAction.ID, EditAlertAction.LABEL);
let commandServiceCalled: boolean = false;
mockEditAlertAction.setup(s => s.run(TypeMoq.It.isAny())).returns(() => {
commandServiceCalled = true;
return Promise.resolve(commandServiceCalled);
});
mockEditAlertAction.setup(s => s.run(TypeMoq.It.isAny()));
mockEditAlertAction.setup(s => s.id).returns(() => EditAlertAction.ID);
mockEditAlertAction.setup(s => s.label).returns(() => EditAlertAction.LABEL);
assert.equal(mockEditAlertAction.object.id, EditAlertAction.ID);
@@ -239,16 +220,13 @@ suite('Job Management Actions', () => {
// Edit Alert Action from Jobs View should open a dialog
await mockEditAlertAction.object.run(null);
assert(commandServiceCalled);
mockEditAlertAction.verify(s => s.run(TypeMoq.It.isAny()), TypeMoq.Times.once());
});
test('Delete Alert Action', async () => {
mockDeleteAlertAction = TypeMoq.Mock.ofType(DeleteAlertAction, TypeMoq.MockBehavior.Strict, DeleteAlertAction.ID, DeleteAlertAction.LABEL, null, null, mockJobManagementService);
let commandServiceCalled = false;
mockDeleteAlertAction.setup(s => s.run(TypeMoq.It.isAny())).returns(async () => {
commandServiceCalled = true;
await mockJobManagementService.object.deleteAlert(null, null).then((result) => result.success);
return commandServiceCalled;
await mockJobManagementService.object.deleteAlert(null, null);
});
mockDeleteAlertAction.setup(s => s.id).returns(() => DeleteAlertAction.ID);
mockDeleteAlertAction.setup(s => s.label).returns(() => DeleteAlertAction.LABEL);
@@ -257,7 +235,6 @@ suite('Job Management Actions', () => {
// Delete Alert Action should call job management service
await mockDeleteAlertAction.object.run(null);
assert(commandServiceCalled);
mockJobManagementService.verify(s => s.deleteAlert(null, null), TypeMoq.Times.once());
});
@@ -277,11 +254,7 @@ suite('Job Management Actions', () => {
test('Edit Operator Action', async () => {
mockEditOperatorAction = TypeMoq.Mock.ofType(EditOperatorAction, TypeMoq.MockBehavior.Strict, EditOperatorAction.ID, EditOperatorAction.LABEL);
let commandServiceCalled: boolean = false;
mockEditOperatorAction.setup(s => s.run(TypeMoq.It.isAny())).returns(() => {
commandServiceCalled = true;
return Promise.resolve(commandServiceCalled);
});
mockEditOperatorAction.setup(s => s.run(TypeMoq.It.isAny()));
mockEditOperatorAction.setup(s => s.id).returns(() => EditOperatorAction.ID);
mockEditOperatorAction.setup(s => s.label).returns(() => EditOperatorAction.LABEL);
assert.equal(mockEditOperatorAction.object.id, EditOperatorAction.ID);
@@ -289,16 +262,13 @@ suite('Job Management Actions', () => {
// Edit Operator Action from Jobs View should open a dialog
await mockEditOperatorAction.object.run(null);
assert(commandServiceCalled);
mockEditOperatorAction.verify(s => s.run(TypeMoq.It.isAny()), TypeMoq.Times.once());
});
test('Delete Operator Action', async () => {
mockDeleteOperatorAction = TypeMoq.Mock.ofType(DeleteOperatorAction, TypeMoq.MockBehavior.Strict, DeleteOperatorAction.ID, DeleteOperatorAction.LABEL, null, null, mockJobManagementService);
let commandServiceCalled = false;
mockDeleteOperatorAction = TypeMoq.Mock.ofType(DeleteOperatorAction, TypeMoq.MockBehavior.Strict, null, null, mockJobManagementService);
mockDeleteOperatorAction.setup(s => s.run(TypeMoq.It.isAny())).returns(async () => {
commandServiceCalled = true;
await mockJobManagementService.object.deleteOperator(null, null).then((result) => result.success);
return commandServiceCalled;
await mockJobManagementService.object.deleteOperator(null, null);
});
mockDeleteOperatorAction.setup(s => s.id).returns(() => DeleteOperatorAction.ID);
mockDeleteOperatorAction.setup(s => s.label).returns(() => DeleteOperatorAction.LABEL);
@@ -307,7 +277,6 @@ suite('Job Management Actions', () => {
// Delete Operator Action should call job management service
await mockDeleteOperatorAction.object.run(null);
assert(commandServiceCalled);
mockJobManagementService.verify(s => s.deleteOperator(null, null), TypeMoq.Times.once());
});
@@ -327,11 +296,7 @@ suite('Job Management Actions', () => {
test('Edit Proxy Action', async () => {
mockEditProxyAction = TypeMoq.Mock.ofType(EditProxyAction, TypeMoq.MockBehavior.Strict, EditProxyAction.ID, EditProxyAction.LABEL);
let commandServiceCalled: boolean = false;
mockEditProxyAction.setup(s => s.run(TypeMoq.It.isAny())).returns(() => {
commandServiceCalled = true;
return Promise.resolve(commandServiceCalled);
});
mockEditProxyAction.setup(s => s.run(TypeMoq.It.isAny()));
mockEditProxyAction.setup(s => s.id).returns(() => EditProxyAction.ID);
mockEditProxyAction.setup(s => s.label).returns(() => EditProxyAction.LABEL);
assert.equal(mockEditProxyAction.object.id, EditProxyAction.ID);
@@ -339,16 +304,13 @@ suite('Job Management Actions', () => {
// Edit Proxy Action from Proxies View should open a dialog
await mockEditProxyAction.object.run(null);
assert(commandServiceCalled);
mockEditProxyAction.verify(s => s.run(TypeMoq.It.isAny()), TypeMoq.Times.once());
});
test('Delete Proxy Action', async () => {
mockDeleteProxyAction = TypeMoq.Mock.ofType(DeleteProxyAction, TypeMoq.MockBehavior.Strict, DeleteProxyAction.ID, DeleteProxyAction.LABEL, null, null, mockJobManagementService);
let commandServiceCalled = false;
mockDeleteProxyAction.setup(s => s.run(TypeMoq.It.isAny())).returns(async () => {
commandServiceCalled = true;
await mockJobManagementService.object.deleteProxy(null, null).then((result) => result.success);
return commandServiceCalled;
await mockJobManagementService.object.deleteProxy(null, null);
});
mockDeleteProxyAction.setup(s => s.id).returns(() => DeleteProxyAction.ID);
mockDeleteProxyAction.setup(s => s.label).returns(() => DeleteProxyAction.LABEL);
@@ -357,7 +319,6 @@ suite('Job Management Actions', () => {
// Delete Proxy Action should call job management service
await mockDeleteProxyAction.object.run(null);
assert(commandServiceCalled);
mockJobManagementService.verify(s => s.deleteProxy(null, null), TypeMoq.Times.once());
});
});