10
10
*/
11
11
12
12
import { BundleDeployer } from "../../../src/api/BundleDeploy/BundleDeployer" ;
13
- import { IHandlerParameters } from "@zowe/imperative" ;
13
+ import { IHandlerParameters , TaskStage } from "@zowe/imperative" ;
14
14
import * as DeployBundleDefinition from "../../../src/cli/deploy/bundle/DeployBundle.definition" ;
15
15
import * as fse from "fs-extra" ;
16
16
import { ZosmfSession , SubmitJobs , List } from "@zowe/cli" ;
@@ -54,144 +54,154 @@ const DEFAULT_PARAMTERS: IHandlerParameters = {
54
54
fullDefinition : DeployBundleDefinition . DeployBundleDefinition ,
55
55
} ;
56
56
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
+
57
63
describe ( "BundleDeployer01" , ( ) => {
58
64
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
+ } ) ;
59
70
afterEach ( ( ) => {
60
71
jest . restoreAllMocks ( ) ;
61
72
} ) ;
62
73
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" ) ; } ) ;
64
75
await runDeployTestWithError ( ) ;
65
76
66
77
expect ( createSpy ) . toHaveBeenCalledTimes ( 1 ) ;
67
78
} ) ;
68
79
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" ) ; } ) ;
70
81
await runUndeployTestWithError ( ) ;
71
82
72
83
expect ( createSpy ) . toHaveBeenCalledTimes ( 1 ) ;
73
84
} ) ;
74
85
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" ) ; } ) ;
78
87
await runDeployTestWithError ( ) ;
79
88
80
89
expect ( createSpy ) . toHaveBeenCalledTimes ( 1 ) ;
81
90
expect ( listSpy ) . toHaveBeenCalledTimes ( 1 ) ;
82
91
} ) ;
83
92
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" } ) ) ;
87
94
await runDeployTestWithError ( ) ;
88
95
89
96
expect ( createSpy ) . toHaveBeenCalledTimes ( 1 ) ;
90
97
expect ( listSpy ) . toHaveBeenCalledTimes ( 1 ) ;
91
98
} ) ;
92
99
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" ) ; } ) ;
97
102
await runDeployTestWithError ( ) ;
98
103
99
104
expect ( createSpy ) . toHaveBeenCalledTimes ( 1 ) ;
100
105
expect ( listSpy ) . toHaveBeenCalledTimes ( 2 ) ;
101
106
} ) ;
102
107
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" } ) ) ;
107
110
await runDeployTestWithError ( ) ;
108
111
109
112
expect ( createSpy ) . toHaveBeenCalledTimes ( 1 ) ;
110
113
expect ( listSpy ) . toHaveBeenCalledTimes ( 2 ) ;
111
114
} ) ;
112
115
it ( "should handle failure during submitjobs processing" , async ( ) => {
116
+ submitSpy = jest . spyOn ( SubmitJobs , "submitJclString" ) . mockImplementationOnce ( ( ) => { throw new Error ( "Injected Submit error" ) ; } ) ;
117
+ await runDeployTestWithError ( ) ;
113
118
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
+ } ) ;
118
140
await runDeployTestWithError ( ) ;
119
141
120
142
expect ( createSpy ) . toHaveBeenCalledTimes ( 1 ) ;
121
143
expect ( listSpy ) . toHaveBeenCalledTimes ( 2 ) ;
122
144
expect ( submitSpy ) . toHaveBeenCalledTimes ( 1 ) ;
123
145
} ) ;
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 ( ) ;
125
158
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 ( ( ) => [ { } ] ) ;
130
165
await runDeployTestWithError ( ) ;
131
166
132
167
expect ( createSpy ) . toHaveBeenCalledTimes ( 1 ) ;
133
168
expect ( listSpy ) . toHaveBeenCalledTimes ( 2 ) ;
134
169
expect ( submitSpy ) . toHaveBeenCalledTimes ( 1 ) ;
135
170
} ) ;
136
171
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" } ] ) ;
143
173
await runDeployTestWithError ( ) ;
144
174
145
175
expect ( createSpy ) . toHaveBeenCalledTimes ( 1 ) ;
146
176
expect ( listSpy ) . toHaveBeenCalledTimes ( 2 ) ;
147
177
expect ( submitSpy ) . toHaveBeenCalledTimes ( 1 ) ;
148
178
} ) ;
149
179
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" } ] ) ;
156
181
await runDeployTestWithError ( ) ;
157
182
158
183
expect ( createSpy ) . toHaveBeenCalledTimes ( 1 ) ;
159
184
expect ( listSpy ) . toHaveBeenCalledTimes ( 2 ) ;
160
185
expect ( submitSpy ) . toHaveBeenCalledTimes ( 1 ) ;
161
186
} ) ;
162
187
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 : " " } ] ) ;
169
189
await runDeployTestWithError ( ) ;
170
190
171
191
expect ( createSpy ) . toHaveBeenCalledTimes ( 1 ) ;
172
192
expect ( listSpy ) . toHaveBeenCalledTimes ( 2 ) ;
173
193
expect ( submitSpy ) . toHaveBeenCalledTimes ( 1 ) ;
174
194
} ) ;
175
195
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" } ] ) ;
182
197
await runDeployTestWithError ( ) ;
183
198
184
199
expect ( createSpy ) . toHaveBeenCalledTimes ( 1 ) ;
185
200
expect ( listSpy ) . toHaveBeenCalledTimes ( 2 ) ;
186
201
expect ( submitSpy ) . toHaveBeenCalledTimes ( 1 ) ;
187
202
} ) ;
188
203
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" } ] ) ;
195
205
196
206
await runDeployTest ( ) ;
197
207
@@ -200,12 +210,7 @@ describe("BundleDeployer01", () => {
200
210
expect ( submitSpy ) . toHaveBeenCalledTimes ( 1 ) ;
201
211
} ) ;
202
212
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" } ] ) ;
209
214
210
215
await runDeployTest ( ) ;
211
216
@@ -214,12 +219,7 @@ describe("BundleDeployer01", () => {
214
219
expect ( submitSpy ) . toHaveBeenCalledTimes ( 1 ) ;
215
220
} ) ;
216
221
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" } ] ) ;
223
223
224
224
await runUndeployTest ( ) ;
225
225
@@ -579,29 +579,21 @@ function setCommonParmsForUndeployTests(parms: IHandlerParameters) {
579
579
}
580
580
581
581
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" } ] ) ;
587
583
588
584
const bd = new BundleDeployer ( parms ) ;
589
585
const response = await bd . deployBundle ( ) ;
590
586
591
587
// 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 ( ) ;
593
589
}
594
590
595
591
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" } ] ) ;
601
593
602
594
const bd = new BundleDeployer ( parms ) ;
603
595
const response = await bd . undeployBundle ( ) ;
604
596
605
597
// 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 ( ) ;
607
599
}
0 commit comments