@@ -11,6 +11,7 @@ import {
1111import {
1212 getRandomAddress ,
1313 getRequiredFieldMessage ,
14+ mockWorkerpoolOrderbook ,
1415 resolveWithNoOrder ,
1516} from '../../../test-utils.js' ;
1617import { resolveWithOneAppOrder } from '../../../utils/appOrders.js' ;
@@ -36,6 +37,16 @@ jest.unstable_mockModule(
3637 } )
3738) ;
3839
40+ jest . unstable_mockModule (
41+ '../../../../src/utils/processProtectedData.models.js' ,
42+ ( ) => ( {
43+ filterWorkerpoolOrders : jest . fn (
44+ ( ) => mockWorkerpoolOrderbook . orders [ 0 ] . order
45+ ) ,
46+ checkUserVoucher : jest . fn ( ) ,
47+ } )
48+ ) ;
49+
3950describe ( 'processProtectedData' , ( ) => {
4051 let testedModule : any ;
4152 let processProtectedData : ProcessProtectedData ;
@@ -330,9 +341,13 @@ describe('processProtectedData', () => {
330341 . mockResolvedValue ( getRandomAddress ( ) ) ,
331342 } ,
332343 orderbook : {
333- fetchDatasetOrderbook : resolveWithNoOrder ( ) ,
344+ fetchDatasetOrderbook : jest
345+ . fn < ( ) => Promise < { orders : [ ] ; count : number } > > ( )
346+ . mockResolvedValue ( resolveWithNoOrder ( ) ) ,
334347 fetchAppOrderbook : jest . fn ( ) ,
335- fetchWorkerpoolOrderbook : jest . fn ( ) ,
348+ fetchWorkerpoolOrderbook : jest
349+ . fn < ( ) => Promise < any > > ( )
350+ . mockResolvedValue ( mockWorkerpoolOrderbook ) ,
336351 } ,
337352 } ;
338353
@@ -365,8 +380,12 @@ describe('processProtectedData', () => {
365380 } ,
366381 orderbook : {
367382 fetchDatasetOrderbook : resolveWithOneDatasetOrder ( ) , // <-- 1 dataset order
368- fetchAppOrderbook : resolveWithNoOrder ( ) , // <-- NO app order
369- fetchWorkerpoolOrderbook : jest . fn ( ) ,
383+ fetchAppOrderbook : jest
384+ . fn < ( ) => Promise < { orders : [ ] ; count : 0 } > > ( )
385+ . mockResolvedValue ( resolveWithNoOrder ( ) ) , // <-- NO app order
386+ fetchWorkerpoolOrderbook : jest
387+ . fn < ( ) => Promise < any > > ( )
388+ . mockResolvedValue ( mockWorkerpoolOrderbook ) ,
370389 } ,
371390 } ;
372391
@@ -388,40 +407,6 @@ describe('processProtectedData', () => {
388407 } ) ;
389408 } ) ;
390409
391- describe ( 'When there is NO workerpool orders' , ( ) => {
392- it ( 'should throw a WorkflowError with the correct message' , async ( ) => {
393- // --- GIVEN
394- const iexec = {
395- wallet : {
396- getAddress : jest
397- . fn < ( ) => Promise < Address > > ( )
398- . mockResolvedValue ( getRandomAddress ( ) ) ,
399- } ,
400- orderbook : {
401- fetchDatasetOrderbook : resolveWithOneDatasetOrder ( ) , // <-- 1 dataset order
402- fetchAppOrderbook : resolveWithOneAppOrder ( ) , // <-- 1 app order
403- fetchWorkerpoolOrderbook : resolveWithNoOrder ( ) , // <-- NO workerpool order
404- } ,
405- } ;
406-
407- await expect (
408- // --- WHEN
409- processProtectedData ( {
410- // @ts -expect-error Minimal iexec implementation with only what's necessary for this test
411- iexec,
412- protectedData : getRandomAddress ( ) ,
413- app : getRandomAddress ( ) ,
414- } )
415- // --- THEN
416- ) . rejects . toThrow (
417- new WorkflowError ( {
418- message : processProtectedDataErrorMessage ,
419- errorCause : Error ( 'No workerpool orders found' ) ,
420- } )
421- ) ;
422- } ) ;
423- } ) ;
424-
425410 describe ( 'When workerpool is explicitly set to the Zero address' , ( ) => {
426411 it ( "should call fetchWorkerpoolOrderbook with workerpool parameter equals to 'any'" , async ( ) => {
427412 // --- GIVEN
@@ -536,4 +521,45 @@ describe('processProtectedData', () => {
536521 ) ;
537522 } ) ;
538523 } ) ;
524+
525+ describe ( 'When there is NO workerpool orders' , ( ) => {
526+ it ( 'should throw a WorkflowError with the correct message' , async ( ) => {
527+ const { filterWorkerpoolOrders } = await import (
528+ '../../../../src/utils/processProtectedData.models.js'
529+ ) ;
530+
531+ ( filterWorkerpoolOrders as jest . Mock ) . mockReturnValue ( null ) ;
532+ // --- GIVEN
533+ const iexec = {
534+ wallet : {
535+ getAddress : jest
536+ . fn < ( ) => Promise < Address > > ( )
537+ . mockResolvedValue ( getRandomAddress ( ) ) ,
538+ } ,
539+ orderbook : {
540+ fetchDatasetOrderbook : resolveWithOneDatasetOrder ( ) , // <-- 1 dataset order
541+ fetchAppOrderbook : resolveWithOneAppOrder ( ) , // <-- 1 app order
542+ fetchWorkerpoolOrderbook : jest
543+ . fn < ( ) => Promise < { orders : [ ] ; count : 0 } > > ( )
544+ . mockResolvedValue ( resolveWithNoOrder ( ) ) , // <-- NO workerpool order
545+ } ,
546+ } ;
547+
548+ await expect (
549+ // --- WHEN
550+ processProtectedData ( {
551+ // @ts -expect-error Minimal iexec implementation with only what's necessary for this test
552+ iexec,
553+ protectedData : getRandomAddress ( ) ,
554+ app : getRandomAddress ( ) ,
555+ } )
556+ // --- THEN
557+ ) . rejects . toThrow (
558+ new WorkflowError ( {
559+ message : processProtectedDataErrorMessage ,
560+ errorCause : Error ( 'No Workerpool order found.' ) ,
561+ } )
562+ ) ;
563+ } ) ;
564+ } ) ;
539565} ) ;
0 commit comments