1+ /**
2+ * This program and the accompanying materials are made available under the terms of the
3+ * Eclipse Public License v2.0 which accompanies this distribution, and is available at
4+ * https://www.eclipse.org/legal/epl-v20.html
5+ *
6+ * SPDX-License-Identifier: EPL-2.0
7+ *
8+ * Copyright Contributors to the Zowe Project.
9+ *
10+ */
11+
12+ import { CICSRegionTree , CICSResourceContainerNode , CICSSessionTree , CICSTree } from "../../../src/trees" ;
13+ import { evaluateTreeNodes } from "../../../src/utils/treeUtils" ;
14+ import { ProgramMeta } from "../../../src/doc" ;
15+ import { IProfileLoaded } from "@zowe/imperative" ;
16+ import { ICMCIApiResponse } from "@zowe/cics-for-zowe-sdk" ;
17+ import PersistentStorage from "../../../src/utils/PersistentStorage" ;
18+ import { ResourceContainer } from "../../../src/resources" ;
19+ import { IProgram } from "@zowe/cics-for-zowe-explorer-api" ;
20+
21+ jest . mock ( "../../../src/utils/profileManagement" , ( ) => ( {
22+ ProfileManagement : { } ,
23+ } ) ) ;
24+ jest . spyOn ( PersistentStorage , "getNumberOfResourcesToFetch" ) . mockReturnValue ( 250 ) ;
25+ jest . spyOn ( PersistentStorage , "getDefaultResourceFilter" ) . mockReturnValue ( "Program=A*" ) ;
26+
27+ const CICSProfileMock = {
28+ host : "hostname" ,
29+ port : "123" ,
30+ user : "a" ,
31+ password : "b" ,
32+ rejectUnauthorized : false ,
33+ protocol : "http" ,
34+ } ;
35+ const profile : IProfileLoaded = { profile : CICSProfileMock , failNotFound : false , message : "" , type : "cics" , name : "MYPROF" } ;
36+
37+ const cicsTree = { _onDidChangeTreeData : { fire : ( ) => jest . fn ( ) } , refresh : ( ) => { } } as unknown as CICSTree ;
38+
39+ const sessionTree = new CICSSessionTree ( profile , cicsTree ) ;
40+ const regionTree = new CICSRegionTree ( "REG" , { } , sessionTree , undefined , sessionTree ) ;
41+ const parentNode = new CICSResourceContainerNode (
42+ "Programs" ,
43+ {
44+ parentNode : regionTree ,
45+ profile,
46+ regionName : "REG" ,
47+ cicsplexName : ""
48+ } ,
49+ undefined ,
50+ {
51+ meta : ProgramMeta ,
52+ resources : new ResourceContainer ( ProgramMeta ) ,
53+ }
54+ ) ;
55+ const prog : IProgram = {
56+ eyu_cicsname : "REG" ,
57+ library : "" ,
58+ librarydsn : "" ,
59+ newcopycnt : "1" ,
60+ program : "APROG" ,
61+ progtype : "" ,
62+ status : "ENABLED"
63+ } ;
64+
65+ describe ( "Tree Utils tests" , ( ) => {
66+
67+ let resourceNode : CICSResourceContainerNode < IProgram > ;
68+
69+ beforeEach ( ( ) => {
70+ resourceNode = new CICSResourceContainerNode (
71+ "APROG1" ,
72+ {
73+ parentNode,
74+ profile,
75+ regionName : "REG" ,
76+ cicsplexName : ""
77+ } ,
78+ {
79+ meta : ProgramMeta ,
80+ resource : { attributes : prog }
81+ } ,
82+ {
83+ meta : ProgramMeta ,
84+ resources : new ResourceContainer ( ProgramMeta ) ,
85+ }
86+ ) ;
87+
88+ jest . resetAllMocks ( ) ;
89+ } ) ;
90+
91+ it ( "should do nothing if no record is returned" , ( ) => {
92+
93+ const apiResp : ICMCIApiResponse = {
94+ response : {
95+ records : [ ] ,
96+ resultsummary : { api_response1 : "" , api_response2 : "" , displayed_recordcount : "0" , recordcount : "0" }
97+ }
98+ } ;
99+ const updateItemSpy = jest . spyOn ( CICSResourceContainerNode . prototype , "setContainedResource" ) ;
100+ evaluateTreeNodes ( resourceNode , cicsTree , apiResp , ProgramMeta ) ;
101+
102+ expect ( updateItemSpy ) . not . toHaveBeenCalled ( ) ;
103+ } ) ;
104+
105+ it ( "should update the record in the resource node" , ( ) => {
106+
107+ const updatedProgram = { ...prog , newcopycnt : 2 } ;
108+ const apiResp : ICMCIApiResponse = {
109+ response : {
110+ records : {
111+ cicsprogram : updatedProgram
112+ } ,
113+ resultsummary : { api_response1 : "" , api_response2 : "" , displayed_recordcount : "0" , recordcount : "0" }
114+ }
115+ } ;
116+ const updateItemSpy = jest . spyOn ( CICSResourceContainerNode . prototype , "setContainedResource" ) ;
117+ evaluateTreeNodes ( resourceNode , cicsTree , apiResp , ProgramMeta ) ;
118+
119+ expect ( updateItemSpy ) . toHaveBeenCalledTimes ( 1 ) ;
120+ expect ( updateItemSpy ) . toHaveBeenCalledWith ( { attributes : updatedProgram } ) ;
121+ } ) ;
122+
123+ } ) ;
0 commit comments