@@ -30,18 +30,18 @@ const DEFAULT_PARAMTERS: IHandlerParameters = {
30
30
response : {
31
31
data : {
32
32
setMessage : jest . fn ( ( setMsgArgs ) => {
33
- expect ( " " + setMsgArgs ) . toMatchSnapshot ( ) ;
33
+ throw new Error ( "Unexpected use of setMessage in Mock: " + setMsgArgs . toString ( ) ) ;
34
34
} ) ,
35
35
setObj : jest . fn ( ( setObjArgs ) => {
36
- expect ( setObjArgs ) . toMatchSnapshot ( ) ;
36
+ throw new Error ( "Unexpected use of setObj in Mock: " + setObjArgs . toString ( ) ) ;
37
37
} )
38
38
} ,
39
39
console : {
40
40
log : jest . fn ( ( logs ) => {
41
- expect ( "" + logs ) . toMatchSnapshot ( ) ;
41
+ consoleText += logs . toString ( ) ;
42
42
} ) ,
43
43
error : jest . fn ( ( errors ) => {
44
- expect ( " " + errors ) . toMatchSnapshot ( ) ;
44
+ throw new Error ( "Unexpected use of error log in Mock: " + errors . toString ( ) ) ;
45
45
} ) ,
46
46
errorHeader : jest . fn ( ( ) => undefined )
47
47
} ,
@@ -53,6 +53,7 @@ const DEFAULT_PARAMTERS: IHandlerParameters = {
53
53
definition : PushBundleDefinition . PushBundleDefinition ,
54
54
fullDefinition : PushBundleDefinition . PushBundleDefinition ,
55
55
} ;
56
+ let consoleText = "" ;
56
57
57
58
// Initialise xml2json before mocking anything
58
59
const parser = require ( "xml2json" ) ;
@@ -87,6 +88,7 @@ describe("BundlePusher01", () => {
87
88
}
88
89
} ) ;
89
90
uploadSpy = jest . spyOn ( Upload , "dirToUSSDirRecursive" ) . mockImplementation ( ( ) => ( { } ) ) ;
91
+ consoleText = "" ;
90
92
} ) ;
91
93
afterEach ( ( ) => {
92
94
jest . restoreAllMocks ( ) ;
@@ -323,6 +325,51 @@ describe("BundlePusher01", () => {
323
325
expect ( readSpy ) . toHaveBeenCalledTimes ( 1 ) ;
324
326
expect ( uploadSpy ) . toHaveBeenCalledTimes ( 1 ) ;
325
327
} ) ;
328
+ it ( "should handle custom bundle id" , async ( ) => {
329
+ uploadSpy . mockImplementationOnce ( ( ) => { throw new Error ( "Injected upload error" ) ; } ) ;
330
+ readSpy = jest . spyOn ( fs , "readFileSync" ) . mockImplementation ( ( data : string ) => {
331
+ if ( data . indexOf ( "cics.xml" ) > - 1 ) {
332
+ return "<manifest xmlns=\"http://www.ibm.com/xmlns/prod/cics/bundle\" id=\"InjectedBundleId\" ></manifest>" ;
333
+ }
334
+ } ) ;
335
+
336
+ await runPushTestWithError ( "__tests__/__resources__/ExampleBundle01" , false ,
337
+ "A problem occurred uploading the bundle to the remote directory '/u/ThisDoesNotExist/InjectedBundleId_1.0.0'. Problem is: Injected upload error" ) ;
338
+
339
+ expect ( zosMFSpy ) . toHaveBeenCalledTimes ( 1 ) ;
340
+ expect ( sshSpy ) . toHaveBeenCalledTimes ( 1 ) ;
341
+ expect ( listSpy ) . toHaveBeenCalledTimes ( 1 ) ;
342
+ expect ( createSpy ) . toHaveBeenCalledTimes ( 1 ) ;
343
+ expect ( shellSpy ) . toHaveBeenCalledTimes ( 0 ) ;
344
+ expect ( membersSpy ) . toHaveBeenCalledTimes ( 0 ) ;
345
+ expect ( submitSpy ) . toHaveBeenCalledTimes ( 0 ) ;
346
+ expect ( existsSpy ) . toHaveBeenCalledTimes ( 1 ) ;
347
+ expect ( readSpy ) . toHaveBeenCalledTimes ( 1 ) ;
348
+ expect ( uploadSpy ) . toHaveBeenCalledTimes ( 1 ) ;
349
+ } ) ;
350
+ it ( "should handle custom bundle id and version" , async ( ) => {
351
+ uploadSpy . mockImplementationOnce ( ( ) => { throw new Error ( "Injected upload error" ) ; } ) ;
352
+ readSpy = jest . spyOn ( fs , "readFileSync" ) . mockImplementation ( ( data : string ) => {
353
+ if ( data . indexOf ( "cics.xml" ) > - 1 ) {
354
+ return "<manifest xmlns=\"http://www.ibm.com/xmlns/prod/cics/bundle\" id=\"InjectedBundleId\" " +
355
+ " bundleMajorVer=\"33\" bundleMinorVer=\"22\" bundleMicroVer=\"11\"></manifest>" ;
356
+ }
357
+ } ) ;
358
+
359
+ await runPushTestWithError ( "__tests__/__resources__/ExampleBundle01" , false ,
360
+ "A problem occurred uploading the bundle to the remote directory '/u/ThisDoesNotExist/InjectedBundleId_33.22.11'. Problem is: Injected upload error" ) ;
361
+
362
+ expect ( zosMFSpy ) . toHaveBeenCalledTimes ( 1 ) ;
363
+ expect ( sshSpy ) . toHaveBeenCalledTimes ( 1 ) ;
364
+ expect ( listSpy ) . toHaveBeenCalledTimes ( 1 ) ;
365
+ expect ( createSpy ) . toHaveBeenCalledTimes ( 1 ) ;
366
+ expect ( shellSpy ) . toHaveBeenCalledTimes ( 0 ) ;
367
+ expect ( membersSpy ) . toHaveBeenCalledTimes ( 0 ) ;
368
+ expect ( submitSpy ) . toHaveBeenCalledTimes ( 0 ) ;
369
+ expect ( existsSpy ) . toHaveBeenCalledTimes ( 1 ) ;
370
+ expect ( readSpy ) . toHaveBeenCalledTimes ( 1 ) ;
371
+ expect ( uploadSpy ) . toHaveBeenCalledTimes ( 1 ) ;
372
+ } ) ;
326
373
it ( "should handle error with remote npm install" , async ( ) => {
327
374
shellSpy . mockImplementation ( ( session : any , cmd : string ) => {
328
375
if ( cmd . indexOf ( "npm install" ) > - 1 ) {
@@ -355,6 +402,40 @@ describe("BundlePusher01", () => {
355
402
expect ( readSpy ) . toHaveBeenCalledTimes ( 1 ) ;
356
403
expect ( uploadSpy ) . toHaveBeenCalledTimes ( 1 ) ;
357
404
} ) ;
405
+ it ( "should handle failure of remote npm install" , async ( ) => {
406
+ shellSpy . mockImplementation ( ( session : any , cmd : string , dir : string , stdoutHandler : ( data : string ) => void ) => {
407
+ if ( cmd . indexOf ( "npm install" ) > - 1 ) {
408
+ stdoutHandler ( "Injected stdout error message" ) ;
409
+ }
410
+ else {
411
+ return true ;
412
+ }
413
+ } ) ;
414
+ existsSpy . mockImplementation ( ( data : string ) => {
415
+ if ( data . indexOf ( ".zosattributes" ) > - 1 ) {
416
+ return false ;
417
+ }
418
+ if ( data . indexOf ( "package.json" ) > - 1 ) {
419
+ return true ;
420
+ }
421
+ } ) ;
422
+
423
+ await runPushTestWithError ( "__tests__/__resources__/ExampleBundle01" , false ,
424
+ "A problem occurred attempting to run 'npm install' in remote directory '/u/ThisDoesNotExist/12345678'. " +
425
+ "Problem is: The output from the remote command implied that an error occurred." ) ;
426
+
427
+ expect ( consoleText ) . toContain ( "Injected stdout error message" ) ;
428
+ expect ( zosMFSpy ) . toHaveBeenCalledTimes ( 1 ) ;
429
+ expect ( sshSpy ) . toHaveBeenCalledTimes ( 1 ) ;
430
+ expect ( createSpy ) . toHaveBeenCalledTimes ( 1 ) ;
431
+ expect ( listSpy ) . toHaveBeenCalledTimes ( 1 ) ;
432
+ expect ( shellSpy ) . toHaveBeenCalledTimes ( 1 ) ;
433
+ expect ( membersSpy ) . toHaveBeenCalledTimes ( 0 ) ;
434
+ expect ( submitSpy ) . toHaveBeenCalledTimes ( 0 ) ;
435
+ expect ( existsSpy ) . toHaveBeenCalledTimes ( 2 ) ;
436
+ expect ( readSpy ) . toHaveBeenCalledTimes ( 1 ) ;
437
+ expect ( uploadSpy ) . toHaveBeenCalledTimes ( 1 ) ;
438
+ } ) ;
358
439
it ( "should handle error with remote bundle deploy" , async ( ) => {
359
440
submitSpy . mockImplementationOnce ( ( ) => { throw new Error ( "Injected deploy error" ) ; } ) ;
360
441
@@ -388,6 +469,41 @@ describe("BundlePusher01", () => {
388
469
expect ( readSpy ) . toHaveBeenCalledTimes ( 1 ) ;
389
470
expect ( uploadSpy ) . toHaveBeenCalledTimes ( 1 ) ;
390
471
} ) ;
472
+ it ( "should run to completion with verbose output" , async ( ) => {
473
+ const parms = getCommonParmsForPushTests ( ) ;
474
+ parms . arguments . verbose = true ;
475
+ shellSpy . mockImplementation ( ( session : any , cmd : string , dir : string , stdoutHandler : ( data : string ) => void ) => {
476
+ stdoutHandler ( "Injected stdout shell message" ) ;
477
+ } ) ;
478
+ existsSpy . mockImplementation ( ( data : string ) => {
479
+ if ( data . indexOf ( ".zosattributes" ) > - 1 ) {
480
+ return false ;
481
+ }
482
+ if ( data . indexOf ( "package.json" ) > - 1 ) {
483
+ return true ;
484
+ }
485
+ } ) ;
486
+
487
+ await runPushTest ( "__tests__/__resources__/ExampleBundle01" , false , "PUSH operation completed." , parms ) ;
488
+
489
+ expect ( consoleText ) . toContain ( "Making remote bundle directory" ) ;
490
+ expect ( consoleText ) . toContain ( "Accessing contents of remote bundle directory" ) ;
491
+ expect ( consoleText ) . toContain ( "Uploading the bundle to the remote bundle directory" ) ;
492
+ expect ( consoleText ) . toContain ( "Running npm install for the remote bundle" ) ;
493
+ expect ( consoleText ) . toContain ( "Injected stdout shell message" ) ;
494
+ expect ( consoleText ) . toContain ( "Deploying the bundle to CICS" ) ;
495
+ expect ( consoleText ) . toContain ( "Deployed existing bundle to CICS" ) ;
496
+ expect ( zosMFSpy ) . toHaveBeenCalledTimes ( 1 ) ;
497
+ expect ( sshSpy ) . toHaveBeenCalledTimes ( 1 ) ;
498
+ expect ( listSpy ) . toHaveBeenCalledTimes ( 1 ) ;
499
+ expect ( createSpy ) . toHaveBeenCalledTimes ( 1 ) ;
500
+ expect ( shellSpy ) . toHaveBeenCalledTimes ( 1 ) ;
501
+ expect ( membersSpy ) . toHaveBeenCalledTimes ( 2 ) ;
502
+ expect ( submitSpy ) . toHaveBeenCalledTimes ( 1 ) ;
503
+ expect ( existsSpy ) . toHaveBeenCalledTimes ( 2 ) ;
504
+ expect ( readSpy ) . toHaveBeenCalledTimes ( 1 ) ;
505
+ expect ( uploadSpy ) . toHaveBeenCalledTimes ( 1 ) ;
506
+ } ) ;
391
507
} ) ;
392
508
393
509
async function runPushTestWithError ( localBundleDir : string , overwrite : boolean , errorText : string , parmsIn ?: IHandlerParameters ) {
@@ -411,8 +527,14 @@ async function runPushTestWithError(localBundleDir: string, overwrite: boolean,
411
527
expect ( err . message ) . toContain ( errorText ) ;
412
528
}
413
529
414
- async function runPushTest ( localBundleDir : string , overwrite : boolean , expectedResponse : string ) {
415
- const parms = getCommonParmsForPushTests ( ) ;
530
+ async function runPushTest ( localBundleDir : string , overwrite : boolean , expectedResponse : string , parmsIn ?: IHandlerParameters ) {
531
+ let parms : IHandlerParameters ;
532
+ if ( parmsIn === undefined ) {
533
+ parms = getCommonParmsForPushTests ( ) ;
534
+ }
535
+ else {
536
+ parms = parmsIn ;
537
+ }
416
538
parms . arguments . overwrite = overwrite ;
417
539
418
540
let err : Error ;
0 commit comments