Skip to content

Commit 229bb0e

Browse files
Merge pull request #73 from pcoop/branch1
Add Jobid to error messages
2 parents 2c56a50 + 526203f commit 229bb0e

File tree

5 files changed

+123
-97
lines changed

5 files changed

+123
-97
lines changed

__tests__/api/BundleDeploy/BundleDeployer.test.ts

Lines changed: 72 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*/
1111

1212
import { BundleDeployer } from "../../../src/api/BundleDeploy/BundleDeployer";
13-
import { IHandlerParameters } from "@zowe/imperative";
13+
import { IHandlerParameters, TaskStage } from "@zowe/imperative";
1414
import * as DeployBundleDefinition from "../../../src/cli/deploy/bundle/DeployBundle.definition";
1515
import * as fse from "fs-extra";
1616
import { ZosmfSession, SubmitJobs, List } from "@zowe/cli";
@@ -54,144 +54,154 @@ const DEFAULT_PARAMTERS: IHandlerParameters = {
5454
fullDefinition: DeployBundleDefinition.DeployBundleDefinition,
5555
};
5656

57+
58+
let createSpy = jest.spyOn(ZosmfSession, "createBasicZosmfSession").mockImplementation(() => ({}));
59+
let listSpy = jest.spyOn(List, "allMembers").mockImplementation(() => ({}));
60+
let submitSpy = jest.spyOn(SubmitJobs, "submitJclString").mockImplementation(() => ({}));
61+
62+
5763
describe("BundleDeployer01", () => {
5864

65+
beforeEach(() => {
66+
createSpy = jest.spyOn(ZosmfSession, "createBasicZosmfSession").mockImplementation(() => ({}));
67+
listSpy = jest.spyOn(List, "allMembers").mockImplementation(() => ( { val: "DFHDPLOY EYU9ABSI" }));
68+
submitSpy = jest.spyOn(SubmitJobs, "submitJclString").mockImplementation(() => ({}));
69+
});
5970
afterEach(() => {
6071
jest.restoreAllMocks();
6172
});
6273
it("should complain with missing zOSMF profile for deploy", async () => {
63-
const createSpy = jest.spyOn(ZosmfSession, "createBasicZosmfSession").mockImplementationOnce(() => { throw new Error( "Injected Create error" ); });
74+
createSpy.mockImplementationOnce(() => { throw new Error( "Injected Create error" ); });
6475
await runDeployTestWithError();
6576

6677
expect(createSpy).toHaveBeenCalledTimes(1);
6778
});
6879
it("should complain with missing zOSMF profile for undeploy", async () => {
69-
const createSpy = jest.spyOn(ZosmfSession, "createBasicZosmfSession").mockImplementationOnce(() => { throw new Error( "Injected Create error" ); });
80+
createSpy.mockImplementationOnce(() => { throw new Error( "Injected Create error" ); });
7081
await runUndeployTestWithError();
7182

7283
expect(createSpy).toHaveBeenCalledTimes(1);
7384
});
7485
it("should complain if cicshlq not found", async () => {
75-
76-
const createSpy = jest.spyOn(ZosmfSession, "createBasicZosmfSession").mockImplementationOnce(() => ({}));
77-
const listSpy = jest.spyOn(List, "allMembers").mockImplementationOnce(() => { throw new Error( "Injected CICSHLQ error" ); });
86+
listSpy.mockImplementationOnce(() => { throw new Error( "Injected CICSHLQ error" ); });
7887
await runDeployTestWithError();
7988

8089
expect(createSpy).toHaveBeenCalledTimes(1);
8190
expect(listSpy).toHaveBeenCalledTimes(1);
8291
});
8392
it("should complain if cicshlq not found2", async () => {
84-
85-
const createSpy = jest.spyOn(ZosmfSession, "createBasicZosmfSession").mockImplementationOnce(() => ({}));
86-
const listSpy = jest.spyOn(List, "allMembers").mockImplementationOnce(() => ( { val1: "wibble"}));
93+
listSpy.mockImplementationOnce(() => ( { val1: "wibble"}));
8794
await runDeployTestWithError();
8895

8996
expect(createSpy).toHaveBeenCalledTimes(1);
9097
expect(listSpy).toHaveBeenCalledTimes(1);
9198
});
9299
it("should complain if cpsmhlq not found", async () => {
93-
94-
const createSpy = jest.spyOn(ZosmfSession, "createBasicZosmfSession").mockImplementationOnce(() => ({}));
95-
const listSpy = jest.spyOn(List, "allMembers").mockImplementationOnce(() => ( { val1: "DFHDPLOY"}))
96-
.mockImplementationOnce(() => { throw new Error( "Injected CPSMHLQ error" ); });
100+
listSpy = jest.spyOn(List, "allMembers").mockImplementationOnce(() => ( { val1: "DFHDPLOY"}))
101+
.mockImplementationOnce(() => { throw new Error( "Injected CPSMHLQ error" ); });
97102
await runDeployTestWithError();
98103

99104
expect(createSpy).toHaveBeenCalledTimes(1);
100105
expect(listSpy).toHaveBeenCalledTimes(2);
101106
});
102107
it("should complain if cpsmhlq not found2", async () => {
103-
104-
const createSpy = jest.spyOn(ZosmfSession, "createBasicZosmfSession").mockImplementationOnce(() => ({}));
105-
const listSpy = jest.spyOn(List, "allMembers").mockImplementationOnce(() => ( { val: "DFHDPLOY" }))
106-
.mockImplementationOnce(() => ( { val: "wibble" }));
108+
listSpy = jest.spyOn(List, "allMembers").mockImplementationOnce(() => ( { val: "DFHDPLOY" }))
109+
.mockImplementationOnce(() => ( { val: "wibble" }));
107110
await runDeployTestWithError();
108111

109112
expect(createSpy).toHaveBeenCalledTimes(1);
110113
expect(listSpy).toHaveBeenCalledTimes(2);
111114
});
112115
it("should handle failure during submitjobs processing", async () => {
116+
submitSpy = jest.spyOn(SubmitJobs, "submitJclString").mockImplementationOnce(() => { throw new Error( "Injected Submit error" ); });
117+
await runDeployTestWithError();
113118

114-
const createSpy = jest.spyOn(ZosmfSession, "createBasicZosmfSession").mockImplementationOnce(() => ({}));
115-
const listSpy = jest.spyOn(List, "allMembers").mockImplementationOnce(() => ( { val: "DFHDPLOY" }))
116-
.mockImplementationOnce(() => ( { val: "EYU9ABSI" }));
117-
const submitSpy = jest.spyOn(SubmitJobs, "submitJclString").mockImplementationOnce(() => { throw new Error( "Injected Submit error" ); });
119+
expect(createSpy).toHaveBeenCalledTimes(1);
120+
expect(listSpy).toHaveBeenCalledTimes(2);
121+
expect(submitSpy).toHaveBeenCalledTimes(1);
122+
});
123+
it("should update the progress bar", async () => {
124+
submitSpy = jest.spyOn(SubmitJobs, "submitJclString").mockImplementationOnce((session: any, jcl: string, parms: any) => {
125+
parms.task.statusMessage = "Waiting for JOB12345 to enter OUTPUT";
126+
parms.task.stageName = TaskStage.IN_PROGRESS;
127+
const expectedMsg = "Waiting for JOB12345 to enter OUTPUT (Processing DFHDPLOY DEPLOY action)";
128+
// wait 1.5 seconds
129+
return new Promise((resolve, reject) => {
130+
setTimeout(() => {
131+
// Now check that the status message has been updated by the progress bar processing
132+
if (parms.task.statusMessage !== expectedMsg) {
133+
throw new Error("Failed to find the expected message. Got: '" + parms.task.statusMessage + "' expected " +
134+
expectedMsg);
135+
}
136+
resolve();
137+
}, 1500);
138+
});
139+
});
118140
await runDeployTestWithError();
119141

120142
expect(createSpy).toHaveBeenCalledTimes(1);
121143
expect(listSpy).toHaveBeenCalledTimes(2);
122144
expect(submitSpy).toHaveBeenCalledTimes(1);
123145
});
124-
it("should complain if SYSTSPRT not found", async () => {
146+
it("should include the JOBID in an error", async () => {
147+
submitSpy = jest.spyOn(SubmitJobs, "submitJclString").mockImplementationOnce((session: any, jcl: string, parms: any) => {
148+
parms.task.statusMessage = "Waiting for JOB12345 to enter OUTPUT";
149+
parms.task.stageName = TaskStage.IN_PROGRESS;
150+
// wait 1.5 seconds
151+
return new Promise((resolve, reject) => {
152+
setTimeout(() => {
153+
reject(new Error("Injected submit error"));
154+
}, 1500);
155+
});
156+
});
157+
await runDeployTestWithError();
125158

126-
const createSpy = jest.spyOn(ZosmfSession, "createBasicZosmfSession").mockImplementationOnce(() => ({}));
127-
const listSpy = jest.spyOn(List, "allMembers").mockImplementationOnce(() => ( { val: "DFHDPLOY" }))
128-
.mockImplementationOnce(() => ( { val: "EYU9ABSI" }));
129-
const submitSpy = jest.spyOn(SubmitJobs, "submitJclString").mockImplementationOnce(() => [{}] );
159+
expect(createSpy).toHaveBeenCalledTimes(1);
160+
expect(listSpy).toHaveBeenCalledTimes(2);
161+
expect(submitSpy).toHaveBeenCalledTimes(1);
162+
});
163+
it("should complain if SYSTSPRT not found", async () => {
164+
submitSpy.mockImplementationOnce(() => [{}] );
130165
await runDeployTestWithError();
131166

132167
expect(createSpy).toHaveBeenCalledTimes(1);
133168
expect(listSpy).toHaveBeenCalledTimes(2);
134169
expect(submitSpy).toHaveBeenCalledTimes(1);
135170
});
136171
it("should failover to JESMSGLG if SYSTSPRT not found", async () => {
137-
138-
const createSpy = jest.spyOn(ZosmfSession, "createBasicZosmfSession").mockImplementationOnce(() => ({}));
139-
const listSpy = jest.spyOn(List, "allMembers").mockImplementationOnce(() => ( { val: "DFHDPLOY" }))
140-
.mockImplementationOnce(() => ( { val: "EYU9ABSI" }));
141-
const submitSpy = jest.spyOn(SubmitJobs, "submitJclString").mockImplementationOnce(() =>
142-
[{ddName: "JESMSGLG", stepName: "DFHDPLOY"}] );
172+
submitSpy.mockImplementationOnce(() => [{ddName: "JESMSGLG", stepName: "DFHDPLOY"}] );
143173
await runDeployTestWithError();
144174

145175
expect(createSpy).toHaveBeenCalledTimes(1);
146176
expect(listSpy).toHaveBeenCalledTimes(2);
147177
expect(submitSpy).toHaveBeenCalledTimes(1);
148178
});
149179
it("should tolerate empty output from DFHDPLOY", async () => {
150-
151-
const createSpy = jest.spyOn(ZosmfSession, "createBasicZosmfSession").mockImplementationOnce(() => ({}));
152-
const listSpy = jest.spyOn(List, "allMembers").mockImplementationOnce(() => ( { val: "DFHDPLOY" }))
153-
.mockImplementationOnce(() => ( { val: "EYU9ABSI" }));
154-
const submitSpy = jest.spyOn(SubmitJobs, "submitJclString").mockImplementationOnce(() =>
155-
[{ddName: "SYSTSPRT", stepName: "DFHDPLOY"}] );
180+
submitSpy.mockImplementationOnce(() => [{ddName: "SYSTSPRT", stepName: "DFHDPLOY"}] );
156181
await runDeployTestWithError();
157182

158183
expect(createSpy).toHaveBeenCalledTimes(1);
159184
expect(listSpy).toHaveBeenCalledTimes(2);
160185
expect(submitSpy).toHaveBeenCalledTimes(1);
161186
});
162187
it("should complain if status can't be determined", async () => {
163-
164-
const createSpy = jest.spyOn(ZosmfSession, "createBasicZosmfSession").mockImplementationOnce(() => ({}));
165-
const listSpy = jest.spyOn(List, "allMembers").mockImplementationOnce(() => ( { val: "DFHDPLOY" }))
166-
.mockImplementationOnce(() => ( { val: "EYU9ABSI" }));
167-
const submitSpy = jest.spyOn(SubmitJobs, "submitJclString").mockImplementationOnce(() =>
168-
[{ddName: "SYSTSPRT", stepName: "DFHDPLOY", data: " "}] );
188+
submitSpy.mockImplementationOnce(() => [{ddName: "SYSTSPRT", stepName: "DFHDPLOY", data: " "}] );
169189
await runDeployTestWithError();
170190

171191
expect(createSpy).toHaveBeenCalledTimes(1);
172192
expect(listSpy).toHaveBeenCalledTimes(2);
173193
expect(submitSpy).toHaveBeenCalledTimes(1);
174194
});
175195
it("should complain if DFHDPLOY ends with an error", async () => {
176-
177-
const createSpy = jest.spyOn(ZosmfSession, "createBasicZosmfSession").mockImplementationOnce(() => ({}));
178-
const listSpy = jest.spyOn(List, "allMembers").mockImplementationOnce(() => ( { val: "DFHDPLOY" }))
179-
.mockImplementationOnce(() => ( { val: "EYU9ABSI" }));
180-
const submitSpy = jest.spyOn(SubmitJobs, "submitJclString").mockImplementationOnce(() =>
181-
[{ddName: "SYSTSPRT", stepName: "DFHDPLOY", data: "DFHRL2055I"}] );
196+
submitSpy.mockImplementationOnce(() => [{ddName: "SYSTSPRT", stepName: "DFHDPLOY", data: "DFHRL2055I"}] );
182197
await runDeployTestWithError();
183198

184199
expect(createSpy).toHaveBeenCalledTimes(1);
185200
expect(listSpy).toHaveBeenCalledTimes(2);
186201
expect(submitSpy).toHaveBeenCalledTimes(1);
187202
});
188203
it("should complete with warnings ", async () => {
189-
190-
const createSpy = jest.spyOn(ZosmfSession, "createBasicZosmfSession").mockImplementationOnce(() => ({}));
191-
const listSpy = jest.spyOn(List, "allMembers").mockImplementationOnce(() => ( { val: "DFHDPLOY" }))
192-
.mockImplementationOnce(() => ( { val: "EYU9ABSI" }));
193-
const submitSpy = jest.spyOn(SubmitJobs, "submitJclString").mockImplementationOnce(() =>
194-
[{ddName: "SYSTSPRT", stepName: "DFHDPLOY", data: "DFHRL2043I"}] );
204+
submitSpy.mockImplementationOnce(() => [{ddName: "SYSTSPRT", stepName: "DFHDPLOY", data: "DFHRL2043I"}] );
195205

196206
await runDeployTest();
197207

@@ -200,12 +210,7 @@ describe("BundleDeployer01", () => {
200210
expect(submitSpy).toHaveBeenCalledTimes(1);
201211
});
202212
it("should deploy successfully", async () => {
203-
204-
const createSpy = jest.spyOn(ZosmfSession, "createBasicZosmfSession").mockImplementationOnce(() => ({}));
205-
const listSpy = jest.spyOn(List, "allMembers").mockImplementationOnce(() => ( { val: "DFHDPLOY" }))
206-
.mockImplementationOnce(() => ( { val: "EYU9ABSI" }));
207-
const submitSpy = jest.spyOn(SubmitJobs, "submitJclString").mockImplementationOnce(() =>
208-
[{ddName: "SYSTSPRT", stepName: "DFHDPLOY", data: "DFHRL2012I"}] );
213+
submitSpy.mockImplementationOnce(() => [{ddName: "SYSTSPRT", stepName: "DFHDPLOY", data: "DFHRL2012I"}] );
209214

210215
await runDeployTest();
211216

@@ -214,12 +219,7 @@ describe("BundleDeployer01", () => {
214219
expect(submitSpy).toHaveBeenCalledTimes(1);
215220
});
216221
it("should undeploy successfully", async () => {
217-
218-
const createSpy = jest.spyOn(ZosmfSession, "createBasicZosmfSession").mockImplementationOnce(() => ({}));
219-
const listSpy = jest.spyOn(List, "allMembers").mockImplementationOnce(() => ( { val: "DFHDPLOY" }))
220-
.mockImplementationOnce(() => ( { val: "EYU9ABSI" }));
221-
const submitSpy = jest.spyOn(SubmitJobs, "submitJclString").mockImplementationOnce(() =>
222-
[{ddName: "SYSTSPRT", stepName: "DFHDPLOY", data: "DFHRL2037I"}] );
222+
submitSpy.mockImplementationOnce(() => [{ddName: "SYSTSPRT", stepName: "DFHDPLOY", data: "DFHRL2037I"}] );
223223

224224
await runUndeployTest();
225225

@@ -579,29 +579,21 @@ function setCommonParmsForUndeployTests(parms: IHandlerParameters) {
579579
}
580580

581581
async function testDeployJCL(parms: IHandlerParameters) {
582-
const spy1 = jest.spyOn(ZosmfSession, "createBasicZosmfSession").mockImplementationOnce(() => ({}));
583-
const spy2 = jest.spyOn(List, "allMembers").mockImplementationOnce(() => ( { val: "DFHDPLOY" }))
584-
.mockImplementationOnce(() => ( { val: "EYU9ABSI" }));
585-
const spy3 = jest.spyOn(SubmitJobs, "submitJclString").mockImplementationOnce(() =>
586-
[{ddName: "SYSTSPRT", stepName: "DFHDPLOY", data: "DFHRL2012I"}] );
582+
submitSpy.mockImplementationOnce(() => [{ddName: "SYSTSPRT", stepName: "DFHDPLOY", data: "DFHRL2012I"}] );
587583

588584
const bd = new BundleDeployer(parms);
589585
const response = await bd.deployBundle();
590586

591587
// Check the generated JCL
592-
expect(spy3.mock.calls[spy3.mock.calls.length - 1][1]).toMatchSnapshot();
588+
expect(submitSpy.mock.calls[submitSpy.mock.calls.length - 1][1]).toMatchSnapshot();
593589
}
594590

595591
async function testUndeployJCL(parms: IHandlerParameters) {
596-
const spy1 = jest.spyOn(ZosmfSession, "createBasicZosmfSession").mockImplementationOnce(() => ({}));
597-
const spy2 = jest.spyOn(List, "allMembers").mockImplementationOnce(() => ( { val: "DFHDPLOY" }))
598-
.mockImplementationOnce(() => ( { val: "EYU9ABSI" }));
599-
const spy3 = jest.spyOn(SubmitJobs, "submitJclString").mockImplementationOnce(() =>
600-
[{ddName: "SYSTSPRT", stepName: "DFHDPLOY", data: "DFHRL2037I"}] );
592+
submitSpy.mockImplementationOnce(() => [{ddName: "SYSTSPRT", stepName: "DFHDPLOY", data: "DFHRL2037I"}] );
601593

602594
const bd = new BundleDeployer(parms);
603595
const response = await bd.undeployBundle();
604596

605597
// Check the generated JCL
606-
expect(spy3.mock.calls[spy3.mock.calls.length - 1][1]).toMatchSnapshot();
598+
expect(submitSpy.mock.calls[submitSpy.mock.calls.length - 1][1]).toMatchSnapshot();
607599
}

0 commit comments

Comments
 (0)