@@ -25,14 +25,15 @@ const pluginOptions = {
2525 serviceId : 'id' ,
2626 endpoint : 'point' ,
2727 format : 'list' ,
28+ readAll : false ,
2829 version : 'v1' ,
2930} ;
3031
3132describe ( 'sourceNodes' , ( ) => {
3233 test ( 'sourceNodes with list, success response' , async ( ) => {
3334 mockResponse = {
3435 statusCode : 200 ,
35- body : { contents : [ { id : '1' } , { id : '2' } ] } ,
36+ body : { contents : [ { id : '1' } , { id : '2' } ] , totalCount : 2 } ,
3637 } ;
3738 await sourceNodes ( { actions, createNodeId, reporter } , pluginOptions ) ;
3839 expect ( actions . createNode . mock . calls . length ) . toBe ( 2 ) ;
@@ -75,4 +76,151 @@ describe('sourceNodes', () => {
7576 expect ( createNodeId ) . not . toBeCalled ( ) ;
7677 expect ( reporter . panic . mock . calls . length ) . toBe ( 1 ) ;
7778 } ) ;
79+
80+ test ( 'sourceNodes with list and readAll, success response' , async ( ) => {
81+ const options = {
82+ apiKey : 'key' ,
83+ serviceId : 'id' ,
84+ endpoint : 'point' ,
85+ format : 'list' ,
86+ readAll : true ,
87+ version : 'v1' ,
88+ } ;
89+ mockResponse = {
90+ statusCode : 200 ,
91+ body : { contents : [ { id : '1' } , { id : '2' } ] , totalCount : 2 } ,
92+ } ;
93+ await sourceNodes ( { actions, createNodeId, reporter } , options ) ;
94+ expect ( actions . createNode . mock . calls . length ) . toBe ( 2 ) ;
95+ expect ( createNodeId . mock . calls . length ) . toBe ( 2 ) ;
96+ expect ( reporter . panic ) . not . toBeCalled ( ) ;
97+ } ) ;
98+
99+ test ( 'sourceNodes with list and readAll, success response' , async ( ) => {
100+ const options = {
101+ apiKey : 'key' ,
102+ serviceId : 'id' ,
103+ endpoint : 'point' ,
104+ format : 'list' ,
105+ readAll : true ,
106+ version : 'v1' ,
107+ query : {
108+ limit : 3 ,
109+ } ,
110+ } ;
111+ mockResponse = {
112+ statusCode : 200 ,
113+ body : {
114+ contents : [ { id : '1' } , { id : '2' } , { id : '3' } ] ,
115+ totalCount : 12 ,
116+ } ,
117+ } ;
118+ await sourceNodes ( { actions, createNodeId, reporter } , options ) ;
119+ expect ( actions . createNode . mock . calls . length ) . toBe ( 12 ) ;
120+ expect ( createNodeId . mock . calls . length ) . toBe ( 12 ) ;
121+ expect ( reporter . panic ) . not . toBeCalled ( ) ;
122+ } ) ;
123+ test ( 'sourceNodes with list, error response' , async ( ) => {
124+ const options = {
125+ apiKey : 'key' ,
126+ serviceId : 'id' ,
127+ endpoint : 'point' ,
128+ format : 'list' ,
129+ readAll : true ,
130+ version : 'v1' ,
131+ } ;
132+ mockResponse = {
133+ statusCode : 400 ,
134+ body : { message : 'error' } ,
135+ } ;
136+ await sourceNodes ( { actions, createNodeId, reporter } , options ) ;
137+ expect ( actions . createNode ) . not . toBeCalled ( ) ;
138+ expect ( createNodeId ) . not . toBeCalled ( ) ;
139+ expect ( reporter . panic . mock . calls . length ) . toBe ( 1 ) ;
140+ } ) ;
141+
142+ test ( 'sourceNodes with list, error response' , async ( ) => {
143+ const options = {
144+ apiKey : 'key' ,
145+ serviceId : 'id' ,
146+ endpoint : 'point' ,
147+ format : 'list' ,
148+ readAll : true ,
149+ version : 'v1' ,
150+ } ;
151+ mockResponse = {
152+ statusCode : 200 ,
153+ body : { content : { id : '1' } , totalCount : 1 } ,
154+ } ;
155+ await sourceNodes ( { actions, createNodeId, reporter } , options ) ;
156+ expect ( actions . createNode ) . not . toBeCalled ( ) ;
157+ expect ( createNodeId ) . not . toBeCalled ( ) ;
158+ expect ( reporter . panic . mock . calls . length ) . toBe ( 1 ) ;
159+ } ) ;
160+ test ( 'sourceNodes with list and readAll, success response' , async ( ) => {
161+ const options = {
162+ apiKey : 'key' ,
163+ serviceId : 'id' ,
164+ endpoint : 'point' ,
165+ format : 'list' ,
166+ readAll : true ,
167+ version : 'v1' ,
168+ query : {
169+ limit : 0 ,
170+ } ,
171+ } ;
172+ mockResponse = {
173+ statusCode : 200 ,
174+ body : {
175+ contents : [ { id : '1' } , { id : '2' } , { id : '3' } ] ,
176+ totalCount : 3 ,
177+ } ,
178+ } ;
179+ await sourceNodes ( { actions, createNodeId, reporter } , options ) ;
180+ expect ( actions . createNode . mock . calls . length ) . toBe ( 3 ) ;
181+ expect ( createNodeId . mock . calls . length ) . toBe ( 3 ) ;
182+ expect ( reporter . panic ) . not . toBeCalled ( ) ;
183+ } ) ;
184+ test ( 'sourceNodes with list and readAll, success response' , async ( ) => {
185+ const options = {
186+ apiKey : 'key' ,
187+ serviceId : 'id' ,
188+ endpoint : 'point' ,
189+ format : 'list' ,
190+ readAll : true ,
191+ version : 'v1' ,
192+ query : {
193+ limit : 20 ,
194+ } ,
195+ } ;
196+ mockResponse = {
197+ statusCode : 200 ,
198+ body : { contents : [ { id : '1' } , { id : '2' } , { id : '3' } ] } ,
199+ } ;
200+ await sourceNodes ( { actions, createNodeId, reporter } , options ) ;
201+ expect ( actions . createNode . mock . calls . length ) . toBe ( 3 ) ;
202+ expect ( createNodeId . mock . calls . length ) . toBe ( 3 ) ;
203+ expect ( reporter . panic ) . not . toBeCalled ( ) ;
204+ } ) ;
205+ test ( 'sourceNodes with list and readAll, success response' , async ( ) => {
206+ const options = {
207+ apiKey : 'key' ,
208+ serviceId : 'id' ,
209+ endpoint : 'point' ,
210+ format : 'list' ,
211+ readAll : true ,
212+ version : 'v1' ,
213+ query : {
214+ limit : 1 ,
215+ } ,
216+ } ;
217+ mockResponse = {
218+ statusCode : 200 ,
219+ body : { contents : [ { id : '1' } ] , totalCount : 3 } ,
220+ } ;
221+ await sourceNodes ( { actions, createNodeId, reporter } , options ) ;
222+ expect ( actions . createNode . mock . calls . length ) . toBe ( 3 ) ;
223+ expect ( createNodeId . mock . calls . length ) . toBe ( 3 ) ;
224+ expect ( reporter . panic ) . not . toBeCalled ( ) ;
225+ } ) ;
78226} ) ;
0 commit comments