@@ -53,6 +53,18 @@ const prog2: IProgram = {
5353 library : "MYLIB" ,
5454 librarydsn : "MYLIBDSN" ,
5555} ;
56+ const locFile1 : ILocalFile = {
57+ browse : "" ,
58+ dsname : "A.B.C" ,
59+ enablestatus : "ENABLED" ,
60+ eyu_cicsname : "MYREG" ,
61+ file : "AS" ,
62+ keylength : "" ,
63+ openstatus : "OPEN" ,
64+ read : "" ,
65+ recordsize : "" ,
66+ vsamtype : ""
67+ } ;
5668
5769const runGetCacheMock = jest . fn ( ) ;
5870
@@ -68,20 +80,22 @@ jest.mock("../../../src/utils/resourceUtils", () => ({
6880 runGetResource : runGetResourceMock ,
6981} ) ) ;
7082
71- import { ProgramMeta } from "../../../src/doc" ;
72- import { Resource } from "../../../src/resources" ;
83+ import { LocalFileMeta , ProgramMeta } from "../../../src/doc" ;
7384import { ResourceContainer } from "../../../src/resources/ResourceContainer" ;
7485import { CICSProfileMock } from "../../__utils__/globalMocks" ;
75- import { IProgram , IResource } from "@zowe/cics-for-zowe-explorer-api" ;
86+ import { ILocalFile , IProgram } from "@zowe/cics-for-zowe-explorer-api" ;
7687
7788const prof = { ...CICSProfileMock , host : "hostname" } ;
7889const profileMock = { failNotFound : false , message : "" , type : "cics" , name : "MYPROF" , profile : prof } ;
7990
8091describe ( "Resource Container" , ( ) => {
81- let container : ResourceContainer < IResource > ;
92+ let container : ResourceContainer ;
8293
8394 beforeEach ( ( ) => {
84- container = new ResourceContainer ( ProgramMeta ) ;
95+ container = new ResourceContainer ( [ ProgramMeta ] , {
96+ profileName : profileMock . name ,
97+ regionName : "MYREG"
98+ } ) ;
8599
86100 jest . clearAllMocks ( ) ;
87101
@@ -101,110 +115,94 @@ describe("Resource Container", () => {
101115 resultsummary : {
102116 api_response1 : "1024" ,
103117 cachetoken : "MYCACHETOKEN" ,
118+ recordcount : "2" ,
104119 } ,
105120 } ,
106121 } ) ;
107122 } ) ;
108123
109124 it ( "creates resource container" , ( ) => {
110125 expect ( container ) . toBeDefined ( ) ;
111- expect ( container . getMeta ( ) ) . toBe ( ProgramMeta ) ;
112126 } ) ;
113127
114128 it ( "should default values on instantiation" , ( ) => {
115- expect ( container . isFilterApplied ( ) ) . toBeFalsy ( ) ;
116- expect ( container . getResources ( ) ) . toEqual ( [ ] ) ;
117- expect ( container . getResource ( ) ) . toBeUndefined ( ) ;
118- expect ( container . getFetchedAll ( ) ) . toBeFalsy ( ) ;
129+ expect ( container . isCriteriaApplied ( ) ) . toBeFalsy ( ) ;
130+ expect ( container . hasMore ( ) ) . toBeFalsy ( ) ;
119131 } ) ;
120132
121133 it ( "should set criteria" , async ( ) => {
122- // @ts -ignore - private property
123- expect ( container . criteria ) . toEqual ( await ProgramMeta . getDefaultCriteria ( ) ) ;
134+ expect ( container . getCriteria ( ProgramMeta ) ) . toEqual ( ProgramMeta . getDefaultCriteria ( ) ) ;
124135 container . setCriteria ( [ "a" , "b" ] ) ;
125- // @ts -ignore - private property
126- expect ( container . criteria ) . toEqual ( "PROGRAM=a OR PROGRAM=b" ) ;
136+ expect ( container . getCriteria ( ProgramMeta ) ) . toEqual ( "PROGRAM=a OR PROGRAM=b" ) ;
127137 } ) ;
128138
129- it ( "should set numtoFetch" , async ( ) => {
130- // @ts -ignore - private property
131- expect ( container . numberToFetch ) . toEqual ( 250 ) ;
132- container . setNumberToFetch ( 12 ) ;
133- // @ts -ignore - private property
134- expect ( container . numberToFetch ) . toEqual ( 12 ) ;
135- await container . resetNumberToFetch ( ) ;
136- // @ts -ignore - private property
137- expect ( container . numberToFetch ) . toEqual ( 250 ) ;
139+ it ( "should get region name" , ( ) => {
140+ expect ( container . getRegionName ( ) ) . toEqual ( "MYREG" ) ;
138141 } ) ;
139-
140- it ( "should load resources with no plexname and no cache token" , async ( ) => {
141- // @ts -ignore - private property
142- expect ( container . cacheToken ) . toBeNull ( ) ;
143-
144- const [ resources , moreToFetch ] = await container . loadResources ( profileMock , "MYREG" , undefined ) ;
145- expect ( moreToFetch ) . toBeFalsy ( ) ;
146- expect ( resources ) . toEqual ( [ new Resource < IProgram > ( prog1 ) , new Resource < IProgram > ( prog2 ) ] ) ;
147-
148- expect ( runGetResourceMock ) . toHaveBeenCalledWith ( {
149- profileName : "MYPROF" ,
150- resourceName : "CICSProgram" ,
151- cicsPlex : undefined ,
152- regionName : "MYREG" ,
153- params : {
154- criteria : await ProgramMeta . getDefaultCriteria ( ) ,
155- queryParams : {
156- summonly : true ,
157- nodiscard : true ,
158- overrideWarningCount : true ,
159- } ,
160- } ,
142+ it ( "should get profile name" , ( ) => {
143+ expect ( container . getProfileName ( ) ) . toEqual ( "MYPROF" ) ;
144+ } ) ;
145+ it ( "should get plex name when not set" , ( ) => {
146+ expect ( container . getPlexName ( ) ) . toBeUndefined ( ) ;
147+ } ) ;
148+ it ( "should get plex name when set" , ( ) => {
149+ container = new ResourceContainer ( [ ProgramMeta ] , {
150+ profileName : profileMock . name ,
151+ cicsplexName : "MYPLEX" ,
152+ regionName : "MYREG"
161153 } ) ;
162- expect ( runGetCacheMock ) . toHaveBeenCalledTimes ( 2 ) ;
154+ expect ( container . getPlexName ( ) ) . toEqual ( "MYPLEX" ) ;
163155 } ) ;
164156
165- it ( "should load resources with cache token" , async ( ) => {
166- // @ts -ignore - private property
167- container . cacheToken = "NEWTOKEN" ;
168-
169- const [ resources , moreToFetch ] = await container . loadResources ( profileMock , "MYREG" , undefined ) ;
170- expect ( moreToFetch ) . toBeFalsy ( ) ;
171- expect ( resources ) . toEqual ( [ new Resource < IProgram > ( prog1 ) , new Resource < IProgram > ( prog2 ) ] ) ;
157+ it ( "should ensure summaries" , async ( ) => {
158+ container = new ResourceContainer ( [ ProgramMeta , LocalFileMeta ] , {
159+ profileName : profileMock . name ,
160+ cicsplexName : "MYPLEX" ,
161+ regionName : "MYREG"
162+ } ) ;
172163
173- expect ( runGetResourceMock ) . toHaveBeenCalledTimes ( 0 ) ;
174- expect ( runGetCacheMock ) . toHaveBeenCalledTimes ( 2 ) ;
175- } ) ;
164+ expect ( container . isCriteriaApplied ( ) ) . toBeFalsy ( ) ;
176165
177- it ( "should load resources and get NODATA" , async ( ) => {
178- runGetResourceMock . mockResolvedValue ( {
166+ runGetCacheMock . mockResolvedValueOnce ( {
179167 response : {
180168 resultsummary : {
181- api_response1 : "1027" ,
169+ recordcount : "2" ,
170+ } ,
171+ records : {
172+ cicsprogram : [ prog1 , prog2 ] ,
173+ } ,
174+ } ,
175+ } ) . mockResolvedValueOnce ( {
176+ response : {
177+ resultsummary : {
178+ recordcount : "1" ,
179+ } ,
180+ records : {
181+ cicsprogram : [ locFile1 ] ,
182182 } ,
183183 } ,
184184 } ) ;
185185
186- const [ resources , moreToFetch ] = await container . loadResources ( profileMock , "MYREG" , undefined ) ;
187- expect ( moreToFetch ) . toBeFalsy ( ) ;
188- expect ( resources ) . toEqual ( [ ] ) ;
189- // @ts -ignore - private property
190- expect ( container . cacheToken ) . toBeNull ( ) ;
191- // @ts -ignore - private property
192- expect ( container . fetchedAll ) . toBeTruthy ( ) ;
193-
194- expect ( runGetResourceMock ) . toHaveBeenCalledWith ( {
195- profileName : "MYPROF" ,
196- resourceName : "CICSProgram" ,
197- cicsPlex : undefined ,
198- regionName : "MYREG" ,
199- params : {
200- criteria : await ProgramMeta . getDefaultCriteria ( ) ,
201- queryParams : {
202- summonly : true ,
203- nodiscard : true ,
204- overrideWarningCount : true ,
186+ runGetResourceMock . mockResolvedValueOnce ( {
187+ response : {
188+ resultsummary : {
189+ api_response1 : "1024" ,
190+ cachetoken : "MYCACHETOKEN" ,
191+ recordcount : "2" ,
192+ } ,
193+ } ,
194+ } ) . mockResolvedValueOnce ( {
195+ response : {
196+ resultsummary : {
197+ api_response1 : "1024" ,
198+ cachetoken : "MYCACHETOKEN2" ,
199+ recordcount : "1" ,
205200 } ,
206201 } ,
207202 } ) ;
208- expect ( runGetCacheMock ) . toHaveBeenCalledTimes ( 0 ) ;
203+
204+ const res = await container . fetchNextPage ( ) ;
205+
206+ expect ( res ) . toHaveLength ( 3 ) ;
209207 } ) ;
210208} ) ;
0 commit comments