Skip to content

Commit 7eb7f3f

Browse files
committed
add mocking to deploy tests
1 parent 1b1b8ca commit 7eb7f3f

File tree

3 files changed

+276
-106
lines changed

3 files changed

+276
-106
lines changed

__tests__/api/BundleDeploy/BundleDeployer.test.ts

Lines changed: 200 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -57,98 +57,141 @@ const DEFAULT_PARAMTERS: IHandlerParameters = {
5757
describe("BundleDeployer01", () => {
5858

5959
it("should complain with missing zOSMF profile for deploy", async () => {
60+
await runDeployTestWithError();
61+
});
62+
it("should complain with missing zOSMF profile for undeploy", async () => {
63+
await runUndeployTestWithError();
64+
});
65+
it("should complain if cicshlq not found", async () => {
6066

61-
let parms: IHandlerParameters;
62-
parms = DEFAULT_PARAMTERS;
63-
setCommonParmsForDeployTests(parms);
64-
parms.arguments.csdgroup = "12345678";
67+
jest.spyOn(ZosmfSession, "createBasicZosmfSession").mockImplementationOnce(() => ({}));
68+
await runDeployTestWithError();
69+
});
70+
it("should complain if cicshlq not found2", async () => {
6571

66-
// Create a Bundle
67-
const bd = new BundleDeployer(parms);
72+
jest.spyOn(ZosmfSession, "createBasicZosmfSession").mockImplementationOnce(() => ({}));
73+
jest.spyOn(List, "allMembers").mockImplementationOnce(() => ( { val1: "wibble"}));
74+
await runDeployTestWithError();
75+
});
76+
it("should complain if cpsmhlq not found", async () => {
6877

69-
let err: Error;
70-
try {
71-
const response = await bd.deployBundle();
72-
} catch (e) {
73-
err = e;
74-
}
75-
expect(err).toBeDefined();
76-
expect(err.message).toMatchSnapshot();
78+
jest.spyOn(ZosmfSession, "createBasicZosmfSession").mockImplementationOnce(() => ({}));
79+
jest.spyOn(List, "allMembers").mockImplementationOnce(() => ( { val1: "DFHDPLOY"}));
80+
await runDeployTestWithError();
7781
});
78-
it("should complain with missing zOSMF profile for undeploy", async () => {
82+
it("should complain if cpsmhlq not found2", async () => {
7983

80-
let parms: IHandlerParameters;
81-
parms = DEFAULT_PARAMTERS;
82-
setCommonParmsForDeployTests(parms);
83-
parms.arguments.csdgroup = "12345678";
84+
jest.spyOn(ZosmfSession, "createBasicZosmfSession").mockImplementationOnce(() => ({}));
85+
jest.spyOn(List, "allMembers").mockImplementationOnce(() => ( { val: "DFHDPLOY" }))
86+
.mockImplementationOnce(() => ( { val: "wibble" }));
87+
await runDeployTestWithError();
88+
});
89+
it("should handle failure during submitjobs processing", async () => {
8490

85-
// Create a Bundle
86-
const bd = new BundleDeployer(parms);
91+
const spy1 = jest.spyOn(ZosmfSession, "createBasicZosmfSession").mockImplementationOnce(() => ({}));
92+
const spy2 = jest.spyOn(List, "allMembers").mockImplementationOnce(() => ( { val: "DFHDPLOY" }))
93+
.mockImplementationOnce(() => ( { val: "EYU9ABSI" }));
94+
await runDeployTestWithError();
95+
});
96+
it("should complain of SYSTSPRT not found", async () => {
8797

88-
let err: Error;
89-
try {
90-
const response = await bd.undeployBundle();
91-
} catch (e) {
92-
err = e;
93-
}
94-
expect(err).toBeDefined();
95-
expect(err.message).toMatchSnapshot();
98+
const spy1 = jest.spyOn(ZosmfSession, "createBasicZosmfSession").mockImplementationOnce(() => ({}));
99+
const spy2 = jest.spyOn(List, "allMembers").mockImplementationOnce(() => ( { val: "DFHDPLOY" }))
100+
.mockImplementationOnce(() => ( { val: "EYU9ABSI" }));
101+
const spy3 = jest.spyOn(SubmitJobs, "submitJclString").mockImplementationOnce(() => [{}] );
102+
await runDeployTestWithError();
96103
});
97-
it("should generate deploy JCL for csdgroup", () => {
104+
it("should tolerate empty output from DFHDPLOY", async () => {
105+
106+
const spy1 = jest.spyOn(ZosmfSession, "createBasicZosmfSession").mockImplementationOnce(() => ({}));
107+
const spy2 = jest.spyOn(List, "allMembers").mockImplementationOnce(() => ( { val: "DFHDPLOY" }))
108+
.mockImplementationOnce(() => ( { val: "EYU9ABSI" }));
109+
const spy3 = jest.spyOn(SubmitJobs, "submitJclString").mockImplementationOnce(() => [{ddName: "SYSTSPRT", stepName: "DFHDPLOY"}] );
110+
await runDeployTestWithError();
111+
});
112+
it("should complain if status can't be determined", async () => {
113+
114+
const spy1 = jest.spyOn(ZosmfSession, "createBasicZosmfSession").mockImplementationOnce(() => ({}));
115+
const spy2 = jest.spyOn(List, "allMembers").mockImplementationOnce(() => ( { val: "DFHDPLOY" }))
116+
.mockImplementationOnce(() => ( { val: "EYU9ABSI" }));
117+
const spy3 = jest.spyOn(SubmitJobs, "submitJclString").mockImplementationOnce(() =>
118+
[{ddName: "SYSTSPRT", stepName: "DFHDPLOY", data: " "}] );
119+
await runDeployTestWithError();
120+
});
121+
it("should complain if DFHDPLOY ends with an error", async () => {
122+
123+
const spy1 = jest.spyOn(ZosmfSession, "createBasicZosmfSession").mockImplementationOnce(() => ({}));
124+
const spy2 = jest.spyOn(List, "allMembers").mockImplementationOnce(() => ( { val: "DFHDPLOY" }))
125+
.mockImplementationOnce(() => ( { val: "EYU9ABSI" }));
126+
const spy3 = jest.spyOn(SubmitJobs, "submitJclString").mockImplementationOnce(() =>
127+
[{ddName: "SYSTSPRT", stepName: "DFHDPLOY", data: "DFHRL2055I"}] );
128+
await runDeployTestWithError();
129+
});
130+
it("should complete with warnings ", async () => {
131+
132+
const spy1 = jest.spyOn(ZosmfSession, "createBasicZosmfSession").mockImplementationOnce(() => ({}));
133+
const spy2 = jest.spyOn(List, "allMembers").mockImplementationOnce(() => ( { val: "DFHDPLOY" }))
134+
.mockImplementationOnce(() => ( { val: "EYU9ABSI" }));
135+
const spy3 = jest.spyOn(SubmitJobs, "submitJclString").mockImplementationOnce(() =>
136+
[{ddName: "SYSTSPRT", stepName: "DFHDPLOY", data: "DFHRL2043I"}] );
137+
138+
await runDeployTest();
139+
});
140+
it("should deploy successfully", async () => {
141+
142+
const spy1 = jest.spyOn(ZosmfSession, "createBasicZosmfSession").mockImplementationOnce(() => ({}));
143+
const spy2 = jest.spyOn(List, "allMembers").mockImplementationOnce(() => ( { val: "DFHDPLOY" }))
144+
.mockImplementationOnce(() => ( { val: "EYU9ABSI" }));
145+
const spy3 = jest.spyOn(SubmitJobs, "submitJclString").mockImplementationOnce(() =>
146+
[{ddName: "SYSTSPRT", stepName: "DFHDPLOY", data: "DFHRL2012I"}] );
147+
148+
await runDeployTest();
149+
});
150+
it("should undeploy successfully", async () => {
151+
152+
const spy1 = jest.spyOn(ZosmfSession, "createBasicZosmfSession").mockImplementationOnce(() => ({}));
153+
const spy2 = jest.spyOn(List, "allMembers").mockImplementationOnce(() => ( { val: "DFHDPLOY" }))
154+
.mockImplementationOnce(() => ( { val: "EYU9ABSI" }));
155+
const spy3 = jest.spyOn(SubmitJobs, "submitJclString").mockImplementationOnce(() =>
156+
[{ddName: "SYSTSPRT", stepName: "DFHDPLOY", data: "DFHRL2037I"}] );
157+
158+
await runUndeployTest();
159+
});
160+
it("should generate deploy JCL for csdgroup", async () => {
98161

99162
let parms: IHandlerParameters;
100163
parms = DEFAULT_PARAMTERS;
101164
setCommonParmsForDeployTests(parms);
102165
parms.arguments.csdgroup = "12345678";
103-
104-
// Create a Bundle
105-
const bd = new BundleDeployer(parms);
106-
107-
// Check the output as JSON
108-
expect(bd.getDeployJCL()).toMatchSnapshot();
166+
await testDeployJCL(parms);
109167
});
110-
it("should generate deploy JCL for csdgroup with timeout", () => {
168+
it("should generate deploy JCL for csdgroup with timeout", async () => {
111169

112170
let parms: IHandlerParameters;
113171
parms = DEFAULT_PARAMTERS;
114172
setCommonParmsForDeployTests(parms);
115173
parms.arguments.csdgroup = "12345678";
116174
parms.arguments.timeout = 1500;
117-
118-
// Create a Bundle
119-
const bd = new BundleDeployer(parms);
120-
121-
// Check the output as JSON
122-
expect(bd.getDeployJCL()).toMatchSnapshot();
175+
await testDeployJCL(parms);
123176
});
124-
it("should generate deploy JCL for resgroup", () => {
177+
it("should generate deploy JCL for resgroup", async () => {
125178

126179
let parms: IHandlerParameters;
127180
parms = DEFAULT_PARAMTERS;
128181
setCommonParmsForDeployTests(parms);
129182
parms.arguments.resgroup = "12345678";
130-
131-
// Create a Bundle
132-
const bd = new BundleDeployer(parms);
133-
134-
// Check the output as JSON
135-
expect(bd.getDeployJCL()).toMatchSnapshot();
183+
await testDeployJCL(parms);
136184
});
137-
it("should generate deploy JCL for resgroup with timeout", () => {
185+
it("should generate deploy JCL for resgroup with timeout", async () => {
138186

139187
let parms: IHandlerParameters;
140188
parms = DEFAULT_PARAMTERS;
141189
setCommonParmsForDeployTests(parms);
142190
parms.arguments.resgroup = "12345678";
143191
parms.arguments.timeout = 1500;
144-
145-
// Create a Bundle
146-
const bd = new BundleDeployer(parms);
147-
148-
// Check the output as JSON
149-
expect(bd.getDeployJCL()).toMatchSnapshot();
192+
await testDeployJCL(parms);
150193
});
151-
it("should support long bundledir", () => {
194+
it("should support long bundledir", async () => {
152195

153196
let parms: IHandlerParameters;
154197
parms = DEFAULT_PARAMTERS;
@@ -159,70 +202,108 @@ describe("BundleDeployer01", () => {
159202
"12345678901234567890123456789012345678901234567890" +
160203
"12345678901234567890123456789012345678901234567890" +
161204
"1234567890123456789012345678901234567890123456789012345";
162-
163-
// Create a Bundle
164-
const bd = new BundleDeployer(parms);
165-
166-
// Check the output as JSON
167-
expect(bd.getDeployJCL()).toMatchSnapshot();
205+
await testDeployJCL(parms);
168206
});
169-
it("should generate undeploy JCL for csdgroup", () => {
207+
it("should generate undeploy JCL for csdgroup", async () => {
170208

171209
let parms: IHandlerParameters;
172210
parms = DEFAULT_PARAMTERS;
173211
setCommonParmsForDeployTests(parms);
174212
parms.arguments.csdgroup = "12345678";
175-
176-
// Create a Bundle
177-
const bd = new BundleDeployer(parms);
178-
179-
// Check the output as JSON
180-
expect(bd.getUndeployJCL()).toMatchSnapshot();
213+
await testUndeployJCL(parms);
181214
});
182-
it("should generate undeploy JCL for csdgroup with timeout", () => {
215+
it("should generate undeploy JCL for csdgroup with timeout", async () => {
183216

184217
let parms: IHandlerParameters;
185218
parms = DEFAULT_PARAMTERS;
186219
setCommonParmsForDeployTests(parms);
187220
parms.arguments.csdgroup = "12345678";
188221
parms.arguments.timeout = 1500;
189-
190-
// Create a Bundle
191-
const bd = new BundleDeployer(parms);
192-
193-
// Check the output as JSON
194-
expect(bd.getUndeployJCL()).toMatchSnapshot();
222+
await testUndeployJCL(parms);
195223
});
196-
it("should generate undeploy JCL for resgroup", () => {
224+
it("should generate undeploy JCL for resgroup", async () => {
197225

198226
let parms: IHandlerParameters;
199227
parms = DEFAULT_PARAMTERS;
200228
setCommonParmsForDeployTests(parms);
201229
parms.arguments.resgroup = "12345678";
202-
203-
// Create a Bundle
204-
const bd = new BundleDeployer(parms);
205-
206-
// Check the output as JSON
207-
expect(bd.getUndeployJCL()).toMatchSnapshot();
230+
await testUndeployJCL(parms);
208231
});
209-
it("should generate undeploy JCL for resgroup with timeout", () => {
232+
it("should generate undeploy JCL for resgroup with timeout", async () => {
210233

211234
let parms: IHandlerParameters;
212235
parms = DEFAULT_PARAMTERS;
213236
setCommonParmsForDeployTests(parms);
214237
parms.arguments.resgroup = "12345678";
215238
parms.arguments.timeout = 1500;
216-
217-
// Create a Bundle
218-
const bd = new BundleDeployer(parms);
219-
220-
// Check the output as JSON
221-
expect(bd.getUndeployJCL()).toMatchSnapshot();
239+
await testUndeployJCL(parms);
222240
});
223241
});
224242

243+
async function runDeployTestWithError() {
244+
let parms: IHandlerParameters;
245+
parms = DEFAULT_PARAMTERS;
246+
setCommonParmsForDeployTests(parms);
247+
parms.arguments.csdgroup = "12345678";
248+
249+
const bd = new BundleDeployer(parms);
250+
251+
let err: Error;
252+
try {
253+
const response = await bd.deployBundle();
254+
} catch (e) {
255+
err = e;
256+
}
257+
expect(err).toBeDefined();
258+
expect(err.message).toMatchSnapshot();
259+
}
260+
261+
async function runUndeployTestWithError() {
262+
let parms: IHandlerParameters;
263+
parms = DEFAULT_PARAMTERS;
264+
setCommonParmsForUndeployTests(parms);
265+
parms.arguments.csdgroup = "12345678";
266+
267+
const bd = new BundleDeployer(parms);
268+
269+
let err: Error;
270+
try {
271+
const response = await bd.undeployBundle();
272+
} catch (e) {
273+
err = e;
274+
}
275+
expect(err).toBeDefined();
276+
expect(err.message).toMatchSnapshot();
277+
}
278+
279+
async function runDeployTest() {
280+
let parms: IHandlerParameters;
281+
parms = DEFAULT_PARAMTERS;
282+
setCommonParmsForDeployTests(parms);
283+
parms.arguments.csdgroup = "12345678";
284+
285+
const bd = new BundleDeployer(parms);
286+
const response = await bd.deployBundle();
287+
expect(response).toMatchSnapshot();
288+
}
289+
290+
async function runUndeployTest() {
291+
let parms: IHandlerParameters;
292+
parms = DEFAULT_PARAMTERS;
293+
setCommonParmsForUndeployTests(parms);
294+
parms.arguments.csdgroup = "12345678";
295+
296+
const bd = new BundleDeployer(parms);
297+
const response = await bd.undeployBundle();
298+
expect(response).toMatchSnapshot();
299+
}
300+
225301
function setCommonParmsForDeployTests(parms: IHandlerParameters) {
302+
setCommonParmsForUndeployTests(parms);
303+
parms.arguments.bundledir = "1234567890";
304+
}
305+
306+
function setCommonParmsForUndeployTests(parms: IHandlerParameters) {
226307
parms.arguments.cicshlq = "12345678901234567890123456789012345";
227308
parms.arguments.cpsmhlq = "abcde12345abcde12345abcde12345abcde";
228309
parms.arguments.cicsplex = "12345678";
@@ -231,6 +312,32 @@ function setCommonParmsForDeployTests(parms: IHandlerParameters) {
231312
parms.arguments.resgroup = undefined;
232313
parms.arguments.timeout = undefined;
233314
parms.arguments.name = "12345678";
234-
parms.arguments.bundledir = "1234567890";
235315
}
236316

317+
async function testDeployJCL(parms: IHandlerParameters) {
318+
const spy1 = jest.spyOn(ZosmfSession, "createBasicZosmfSession").mockImplementationOnce(() => ({}));
319+
const spy2 = jest.spyOn(List, "allMembers").mockImplementationOnce(() => ( { val: "DFHDPLOY" }))
320+
.mockImplementationOnce(() => ( { val: "EYU9ABSI" }));
321+
const spy3 = jest.spyOn(SubmitJobs, "submitJclString").mockImplementationOnce(() =>
322+
[{ddName: "SYSTSPRT", stepName: "DFHDPLOY", data: "DFHRL2037I"}] );
323+
324+
const bd = new BundleDeployer(parms);
325+
const response = await bd.deployBundle();
326+
327+
// Check the generated JCL
328+
expect(spy3.mock.calls[spy3.mock.calls.length - 1][1]).toMatchSnapshot();
329+
}
330+
331+
async function testUndeployJCL(parms: IHandlerParameters) {
332+
const spy1 = jest.spyOn(ZosmfSession, "createBasicZosmfSession").mockImplementationOnce(() => ({}));
333+
const spy2 = jest.spyOn(List, "allMembers").mockImplementationOnce(() => ( { val: "DFHDPLOY" }))
334+
.mockImplementationOnce(() => ( { val: "EYU9ABSI" }));
335+
const spy3 = jest.spyOn(SubmitJobs, "submitJclString").mockImplementationOnce(() =>
336+
[{ddName: "SYSTSPRT", stepName: "DFHDPLOY", data: "DFHRL2037I"}] );
337+
338+
const bd = new BundleDeployer(parms);
339+
const response = await bd.undeployBundle();
340+
341+
// Check the generated JCL
342+
expect(spy3.mock.calls[spy3.mock.calls.length - 1][1]).toMatchSnapshot();
343+
}

0 commit comments

Comments
 (0)