@@ -11,6 +11,7 @@ import {
1111import {
1212 getRandomAddress ,
1313 getRequiredFieldMessage ,
14+ mockAppOrderbook ,
1415 mockWorkerpoolOrderbook ,
1516 resolveWithNoOrder ,
1617} from '../../../test-utils.js' ;
@@ -40,7 +41,7 @@ jest.unstable_mockModule(
4041jest . unstable_mockModule (
4142 '../../../../src/utils/processProtectedData.models.js' ,
4243 ( ) => ( {
43- findWorkerpoolOrders : jest . fn (
44+ filterWorkerpoolOrders : jest . fn (
4445 ( ) => mockWorkerpoolOrderbook . orders [ 0 ] . order
4546 ) ,
4647 checkUserVoucher : jest . fn ( ) ,
@@ -184,10 +185,10 @@ describe('processProtectedData', () => {
184185 } ) ;
185186 } ) ;
186187
187- describe ( 'When maxPrice is not a positive number' , ( ) => {
188+ describe ( 'When DatamaxPrice is not a positive number' , ( ) => {
188189 it ( 'should throw a yup ValidationError with the correct message' , async ( ) => {
189190 // --- GIVEN
190- const invalidMaxPrice = - 1 ;
191+ const invalidDataMaxPrice = - 1 ;
191192
192193 await expect (
193194 // --- WHEN
@@ -196,11 +197,55 @@ describe('processProtectedData', () => {
196197 iexec : { } ,
197198 protectedData : getRandomAddress ( ) ,
198199 app : getRandomAddress ( ) ,
199- maxPrice : invalidMaxPrice ,
200+ dataMaxPrice : invalidDataMaxPrice ,
200201 } )
201202 // --- THEN
202203 ) . rejects . toThrow (
203- new ValidationError ( 'maxPrice must be greater than or equal to 0' )
204+ new ValidationError ( 'dataMaxPrice must be greater than or equal to 0' )
205+ ) ;
206+ } ) ;
207+ } ) ;
208+
209+ describe ( 'When WorkerpoolmaxPrice is not a positive number' , ( ) => {
210+ it ( 'should throw a yup ValidationError with the correct message' , async ( ) => {
211+ // --- GIVEN
212+ const invalidWorkerpoolMaxPrice = - 1 ;
213+
214+ await expect (
215+ // --- WHEN
216+ processProtectedData ( {
217+ // @ts -expect-error No need for iexec here
218+ iexec : { } ,
219+ protectedData : getRandomAddress ( ) ,
220+ app : getRandomAddress ( ) ,
221+ workerpoolMaxPrice : invalidWorkerpoolMaxPrice ,
222+ } )
223+ // --- THEN
224+ ) . rejects . toThrow (
225+ new ValidationError (
226+ 'workerpoolMaxPrice must be greater than or equal to 0'
227+ )
228+ ) ;
229+ } ) ;
230+ } ) ;
231+
232+ describe ( 'When appMaxPrice is not a positive number' , ( ) => {
233+ it ( 'should throw a yup ValidationError with the correct message' , async ( ) => {
234+ // --- GIVEN
235+ const invalidAppMaxPrice = - 1 ;
236+
237+ await expect (
238+ // --- WHEN
239+ processProtectedData ( {
240+ // @ts -expect-error No need for iexec here
241+ iexec : { } ,
242+ protectedData : getRandomAddress ( ) ,
243+ app : getRandomAddress ( ) ,
244+ appMaxPrice : invalidAppMaxPrice ,
245+ } )
246+ // --- THEN
247+ ) . rejects . toThrow (
248+ new ValidationError ( 'appMaxPrice must be greater than or equal to 0' )
204249 ) ;
205250 } ) ;
206251 } ) ;
@@ -344,7 +389,9 @@ describe('processProtectedData', () => {
344389 fetchDatasetOrderbook : jest
345390 . fn < ( ) => Promise < { orders : [ ] ; count : number } > > ( )
346391 . mockResolvedValue ( resolveWithNoOrder ( ) ) ,
347- fetchAppOrderbook : jest . fn ( ) ,
392+ fetchAppOrderbook : jest
393+ . fn < ( ) => Promise < any > > ( )
394+ . mockResolvedValue ( mockAppOrderbook ) ,
348395 fetchWorkerpoolOrderbook : jest
349396 . fn < ( ) => Promise < any > > ( )
350397 . mockResolvedValue ( mockWorkerpoolOrderbook ) ,
@@ -363,7 +410,7 @@ describe('processProtectedData', () => {
363410 ) . rejects . toThrow (
364411 new WorkflowError ( {
365412 message : processProtectedDataErrorMessage ,
366- errorCause : Error ( 'No dataset orders found' ) ,
413+ errorCause : Error ( 'No Dataset order found for the desired price ' ) ,
367414 } )
368415 ) ;
369416 } ) ;
@@ -401,7 +448,7 @@ describe('processProtectedData', () => {
401448 ) . rejects . toThrow (
402449 new WorkflowError ( {
403450 message : processProtectedDataErrorMessage ,
404- errorCause : Error ( 'No app orders found' ) ,
451+ errorCause : Error ( 'No App order found for the desired price ' ) ,
405452 } )
406453 ) ;
407454 } ) ;
@@ -425,16 +472,17 @@ describe('processProtectedData', () => {
425472 } ) ;
426473
427474 // --- THEN
428- expect ( fetchWorkerpoolOrderbookMock ) . toHaveBeenCalledWith ( {
429- workerpool : 'any' , // <-- What we want to test
430- app : expect . any ( String ) ,
431- dataset : expect . any ( String ) ,
432- requester : expect . any ( String ) ,
433- category : 0 ,
434- minTag : SCONE_TAG ,
435- maxTag : SCONE_TAG ,
436- isRequesterStrict : expect . any ( Boolean ) ,
437- } ) ;
475+ expect ( fetchWorkerpoolOrderbookMock ) . toHaveBeenCalledWith (
476+ expect . objectContaining ( {
477+ workerpool : 'any' , // <-- the core of what you're testing
478+ dataset : expect . any ( String ) ,
479+ requester : expect . any ( String ) ,
480+ category : 0 ,
481+ minTag : SCONE_TAG ,
482+ maxTag : SCONE_TAG ,
483+ isRequesterStrict : expect . any ( Boolean ) ,
484+ } )
485+ ) ;
438486 } ) ;
439487 } ) ;
440488
@@ -511,24 +559,29 @@ describe('processProtectedData', () => {
511559 } ) ;
512560
513561 // --- THEN
514- expect ( fetchDatasetOrderbookMock ) . toHaveBeenCalledWith (
515- expect . any ( String ) ,
516- {
517- app : expect . any ( String ) ,
518- workerpool : expect . any ( String ) ,
519- requester : validWhitelistAddress . toLowerCase ( ) , // <-- whitelist address instead of user wallet address
520- }
562+ const calls = fetchDatasetOrderbookMock . mock . calls ;
563+
564+ expect ( calls ) . toEqual (
565+ expect . arrayContaining ( [
566+ [
567+ expect . any ( String ) ,
568+ expect . objectContaining ( {
569+ app : expect . any ( String ) ,
570+ requester : validWhitelistAddress . toLowerCase ( ) ,
571+ } ) ,
572+ ] ,
573+ ] )
521574 ) ;
522575 } ) ;
523576 } ) ;
524577
525578 describe ( 'When there is NO workerpool orders' , ( ) => {
526579 it ( 'should throw a WorkflowError with the correct message' , async ( ) => {
527- const { findWorkerpoolOrders } = await import (
580+ const { filterWorkerpoolOrders } = await import (
528581 '../../../../src/utils/processProtectedData.models.js'
529582 ) ;
530583
531- ( findWorkerpoolOrders as jest . Mock ) . mockReturnValue ( null ) ;
584+ ( filterWorkerpoolOrders as jest . Mock ) . mockReturnValue ( null ) ;
532585 // --- GIVEN
533586 const iexec = {
534587 wallet : {
@@ -557,7 +610,7 @@ describe('processProtectedData', () => {
557610 ) . rejects . toThrow (
558611 new WorkflowError ( {
559612 message : processProtectedDataErrorMessage ,
560- errorCause : Error ( 'No Workerpool order found. ' ) ,
613+ errorCause : Error ( 'No Workerpool order found for the desired price ' ) ,
561614 } )
562615 ) ;
563616 } ) ;
0 commit comments