@@ -91,6 +91,7 @@ describe('fetchMyContacts', () => {
9191 requester : userAddress ,
9292 isAppStrict : true ,
9393 isRequesterStrict : false ,
94+ bulkOnly : false ,
9495 pageSize : 1000 ,
9596 }
9697 ) ;
@@ -102,6 +103,7 @@ describe('fetchMyContacts', () => {
102103 requester : userAddress ,
103104 isAppStrict : true ,
104105 isRequesterStrict : false ,
106+ bulkOnly : false ,
105107 pageSize : 1000 ,
106108 }
107109 ) ;
@@ -157,6 +159,7 @@ describe('fetchMyContacts', () => {
157159 requester : userAddress ,
158160 isAppStrict : true ,
159161 isRequesterStrict : true ,
162+ bulkOnly : false ,
160163 pageSize : 1000 ,
161164 }
162165 ) ;
@@ -168,6 +171,7 @@ describe('fetchMyContacts', () => {
168171 requester : userAddress ,
169172 isAppStrict : true ,
170173 isRequesterStrict : true ,
174+ bulkOnly : false ,
171175 pageSize : 1000 ,
172176 }
173177 ) ;
@@ -232,4 +236,209 @@ describe('fetchMyContacts', () => {
232236 expect ( result [ 0 ] ) . toHaveProperty ( 'grantedAccess' ) ;
233237 expect ( result [ 0 ] . grantedAccess ) . toEqual ( MOCK_ORDER . order ) ;
234238 } ) ;
239+
240+ it ( 'should pass bulkOnly parameter to fetchDatasetOrderbook when set to true' , async ( ) => {
241+ // --- GIVEN
242+ const { getValidContact } = ( await import (
243+ '../../src/utils/subgraphQuery.js'
244+ ) ) as unknown as { getValidContact : jest . Mock < ( ) => Promise < any [ ] > > } ;
245+ getValidContact . mockResolvedValue ( [ ] ) ;
246+
247+ const mockFetchDatasetOrderbook : any = jest . fn ( ) . mockImplementation ( ( ) => {
248+ return Promise . resolve ( {
249+ ok : true ,
250+ count : 1 ,
251+ nextPage : 1 ,
252+ orders : [ MOCK_ORDER ] ,
253+ } ) ;
254+ } ) ;
255+
256+ const iexec = {
257+ wallet : {
258+ getAddress : jest
259+ . fn < ( ) => Promise < Address > > ( )
260+ . mockResolvedValue ( getRandomAddress ( ) ) ,
261+ } ,
262+ ens : {
263+ resolveName : jest
264+ . fn < ( ) => Promise < Address > > ( )
265+ . mockResolvedValue ( getRandomAddress ( ) ) ,
266+ } ,
267+ orderbook : {
268+ fetchDatasetOrderbook : mockFetchDatasetOrderbook ,
269+ } ,
270+ } ;
271+
272+ await fetchMyContacts ( {
273+ // @ts -expect-error Minimal iexec implementation with only what's necessary for this test
274+ iexec : iexec ,
275+ // @ts -expect-error No need for graphQLClient here
276+ graphQLClient : { } ,
277+ dappAddressOrENS : defaultConfig . dappAddress ,
278+ dappWhitelistAddress : defaultConfig . whitelistSmartContract ,
279+ bulkOnly : true ,
280+ } ) ;
281+ const userAddress = ( await iexec . wallet . getAddress ( ) ) . toLowerCase ( ) ;
282+ expect ( iexec . orderbook . fetchDatasetOrderbook ) . toHaveBeenNthCalledWith (
283+ 1 ,
284+ {
285+ dataset : 'any' ,
286+ app : defaultConfig . dappAddress . toLowerCase ( ) ,
287+ requester : userAddress ,
288+ isAppStrict : true ,
289+ isRequesterStrict : false ,
290+ bulkOnly : true ,
291+ pageSize : 1000 ,
292+ }
293+ ) ;
294+ expect ( iexec . orderbook . fetchDatasetOrderbook ) . toHaveBeenNthCalledWith (
295+ 2 ,
296+ {
297+ dataset : 'any' ,
298+ app : defaultConfig . whitelistSmartContract . toLowerCase ( ) ,
299+ requester : userAddress ,
300+ isAppStrict : true ,
301+ isRequesterStrict : false ,
302+ bulkOnly : true ,
303+ pageSize : 1000 ,
304+ }
305+ ) ;
306+ } ) ;
307+
308+ it ( 'should not pass bulkOnly parameter when set to false (default)' , async ( ) => {
309+ // --- GIVEN
310+ const { getValidContact } = ( await import (
311+ '../../src/utils/subgraphQuery.js'
312+ ) ) as unknown as { getValidContact : jest . Mock < ( ) => Promise < any [ ] > > } ;
313+ getValidContact . mockResolvedValue ( [ ] ) ;
314+
315+ const mockFetchDatasetOrderbook : any = jest . fn ( ) . mockImplementation ( ( ) => {
316+ return Promise . resolve ( {
317+ ok : true ,
318+ count : 1 ,
319+ nextPage : 1 ,
320+ orders : [ MOCK_ORDER ] ,
321+ } ) ;
322+ } ) ;
323+
324+ const iexec = {
325+ wallet : {
326+ getAddress : jest
327+ . fn < ( ) => Promise < Address > > ( )
328+ . mockResolvedValue ( getRandomAddress ( ) ) ,
329+ } ,
330+ ens : {
331+ resolveName : jest
332+ . fn < ( ) => Promise < Address > > ( )
333+ . mockResolvedValue ( getRandomAddress ( ) ) ,
334+ } ,
335+ orderbook : {
336+ fetchDatasetOrderbook : mockFetchDatasetOrderbook ,
337+ } ,
338+ } ;
339+
340+ await fetchMyContacts ( {
341+ // @ts -expect-error Minimal iexec implementation with only what's necessary for this test
342+ iexec : iexec ,
343+ // @ts -expect-error No need for graphQLClient here
344+ graphQLClient : { } ,
345+ dappAddressOrENS : defaultConfig . dappAddress ,
346+ dappWhitelistAddress : defaultConfig . whitelistSmartContract ,
347+ bulkOnly : false ,
348+ } ) ;
349+ const userAddress = ( await iexec . wallet . getAddress ( ) ) . toLowerCase ( ) ;
350+ expect ( iexec . orderbook . fetchDatasetOrderbook ) . toHaveBeenNthCalledWith (
351+ 1 ,
352+ {
353+ dataset : 'any' ,
354+ app : defaultConfig . dappAddress . toLowerCase ( ) ,
355+ requester : userAddress ,
356+ isAppStrict : true ,
357+ isRequesterStrict : false ,
358+ bulkOnly : false ,
359+ pageSize : 1000 ,
360+ }
361+ ) ;
362+ expect ( iexec . orderbook . fetchDatasetOrderbook ) . toHaveBeenNthCalledWith (
363+ 2 ,
364+ {
365+ dataset : 'any' ,
366+ app : defaultConfig . whitelistSmartContract . toLowerCase ( ) ,
367+ requester : userAddress ,
368+ isAppStrict : true ,
369+ isRequesterStrict : false ,
370+ bulkOnly : false ,
371+ pageSize : 1000 ,
372+ }
373+ ) ;
374+ } ) ;
375+
376+ it ( 'should work with both isUserStrict and bulkOnly parameters' , async ( ) => {
377+ // --- GIVEN
378+ const { getValidContact } = ( await import (
379+ '../../src/utils/subgraphQuery.js'
380+ ) ) as unknown as { getValidContact : jest . Mock < ( ) => Promise < any [ ] > > } ;
381+ getValidContact . mockResolvedValue ( [ ] ) ;
382+
383+ const mockFetchDatasetOrderbook : any = jest . fn ( ) . mockImplementation ( ( ) => {
384+ return Promise . resolve ( {
385+ ok : true ,
386+ count : 1 ,
387+ nextPage : 1 ,
388+ orders : [ MOCK_ORDER ] ,
389+ } ) ;
390+ } ) ;
391+
392+ const iexec = {
393+ wallet : {
394+ getAddress : jest
395+ . fn < ( ) => Promise < Address > > ( )
396+ . mockResolvedValue ( getRandomAddress ( ) ) ,
397+ } ,
398+ ens : {
399+ resolveName : jest
400+ . fn < ( ) => Promise < Address > > ( )
401+ . mockResolvedValue ( getRandomAddress ( ) ) ,
402+ } ,
403+ orderbook : {
404+ fetchDatasetOrderbook : mockFetchDatasetOrderbook ,
405+ } ,
406+ } ;
407+
408+ await fetchMyContacts ( {
409+ // @ts -expect-error Minimal iexec implementation with only what's necessary for this test
410+ iexec : iexec ,
411+ // @ts -expect-error No need for graphQLClient here
412+ graphQLClient : { } ,
413+ dappAddressOrENS : defaultConfig . dappAddress ,
414+ dappWhitelistAddress : defaultConfig . whitelistSmartContract ,
415+ isUserStrict : true ,
416+ bulkOnly : true ,
417+ } ) ;
418+ const userAddress = ( await iexec . wallet . getAddress ( ) ) . toLowerCase ( ) ;
419+ expect ( iexec . orderbook . fetchDatasetOrderbook ) . toHaveBeenNthCalledWith (
420+ 1 ,
421+ {
422+ dataset : 'any' ,
423+ app : defaultConfig . dappAddress . toLowerCase ( ) ,
424+ requester : userAddress ,
425+ isAppStrict : true ,
426+ isRequesterStrict : true ,
427+ bulkOnly : true ,
428+ pageSize : 1000 ,
429+ }
430+ ) ;
431+ expect ( iexec . orderbook . fetchDatasetOrderbook ) . toHaveBeenNthCalledWith (
432+ 2 ,
433+ {
434+ dataset : 'any' ,
435+ app : defaultConfig . whitelistSmartContract . toLowerCase ( ) ,
436+ requester : userAddress ,
437+ isAppStrict : true ,
438+ isRequesterStrict : true ,
439+ bulkOnly : true ,
440+ pageSize : 1000 ,
441+ }
442+ ) ;
443+ } ) ;
235444} ) ;
0 commit comments