@@ -36,40 +36,60 @@ describe('Apify Node', () => {
36
36
37
37
describe ( 'actors' , ( ) => {
38
38
describe ( 'run-actor' , ( ) => {
39
- it ( 'should run the run-actor workflow and wait for finish' , async ( ) => {
40
- const mockRunActor = fixtures . runActorResult ( ) ;
41
- const mockBuild = fixtures . getBuildResult ( ) ;
42
- const mockFinishedRun = fixtures . getSuccessRunResult ( ) ;
39
+ const mockRunActor = fixtures . runActorResult ( ) ;
40
+ const mockBuild = fixtures . getBuildResult ( ) ;
41
+ const mockFinishedRun = fixtures . getSuccessRunResult ( ) ;
42
+ const mockResultDataset = fixtures . getDatasetItems ( ) ;
43
43
44
- const scope = nock ( 'https://api.apify.com' )
45
- . get ( `/v2/acts/${ ACTOR_ID } ` )
46
- . reply ( 200 , fixtures . getActorResult ( ) )
47
- . get ( `/v2/acts/${ ACTOR_ID } /builds/default` )
48
- . reply ( 200 , mockBuild )
49
- . post ( `/v2/acts/${ ACTOR_ID } /runs` )
50
- . query ( { waitForFinish : 0 , build : mockBuild . data . buildNumber , memory : 1024 } )
51
- . reply ( 200 , mockRunActor )
52
- . get ( '/v2/actor-runs/Icz6E0IHX0c40yEi7' )
53
- . reply ( 200 , mockFinishedRun ) ;
44
+ const tests = [
45
+ {
46
+ name : 'Advanced Workflow' ,
47
+ workflowJsonName : 'run-actor-advanced.workflow.json' ,
48
+ nodeName : 'Crawl a Website (Advanced Settings)' ,
49
+ } ,
50
+ {
51
+ name : 'Standard Workflow' ,
52
+ workflowJsonName : 'run-actor-standard.workflow.json' ,
53
+ nodeName : 'Crawl a Website (Standard Settings)' ,
54
+ } ,
55
+ ] ;
54
56
55
- const runActorWorkflow = require ( './workflows/actors/run-actor-wait-for-finish.workflow.json' ) ;
56
- const { executionData } = await executeWorkflow ( {
57
- credentialsHelper,
58
- workflow : runActorWorkflow ,
59
- } ) ;
57
+ test . each ( tests ) (
58
+ '$name should run the WCC actor correctly' ,
59
+ async ( { workflowJsonName, nodeName } ) => {
60
+ const scope = nock ( 'https://api.apify.com' )
61
+ . get ( `/v2/acts/${ ACTOR_ID } /builds/default` )
62
+ . reply ( 200 , mockBuild )
63
+ . post ( `/v2/acts/${ ACTOR_ID } /runs` )
64
+ . query ( { waitForFinish : 0 } )
65
+ . reply ( 200 , mockRunActor )
66
+ . get ( '/v2/actor-runs/5rsC83CHinQwPlsSI' )
67
+ . reply ( 200 , mockFinishedRun )
68
+ . get ( '/v2/datasets/63kMAihbWVgBvEAZ2/items' )
69
+ . reply ( 200 , mockResultDataset ) ;
60
70
61
- const nodeResults = getRunTaskDataByNodeName ( executionData , 'Run actor' ) ;
62
- expect ( nodeResults . length ) . toBe ( 1 ) ;
63
- const [ nodeResult ] = nodeResults ;
64
- expect ( nodeResult . executionStatus ) . toBe ( 'success' ) ;
71
+ const workflow = require ( `./workflows/actors/${ workflowJsonName } ` ) ;
72
+ const { executionData } = await executeWorkflow ( {
73
+ credentialsHelper,
74
+ workflow,
75
+ } ) ;
65
76
66
- const data = getTaskData ( nodeResult ) ;
67
- // exptect polled terminal run as result
68
- expect ( data ) . not . toEqual ( mockRunActor . data ) ;
69
- expect ( data ) . toEqual ( mockFinishedRun . data ) ;
77
+ const nodeResults = getRunTaskDataByNodeName ( executionData , nodeName ) ;
78
+ expect ( nodeResults . length ) . toBe ( 1 ) ;
70
79
71
- expect ( scope . isDone ( ) ) . toBe ( true ) ;
72
- } ) ;
80
+ const [ nodeResult ] = nodeResults ;
81
+ expect ( nodeResult . executionStatus ) . toBe ( 'success' ) ;
82
+
83
+ const data = getTaskData ( nodeResult ) ;
84
+ expect ( typeof data ) . toBe ( 'object' ) ;
85
+
86
+ const first = data ?. [ '0' ] as { json : any } ;
87
+ expect ( first . json ) . toEqual ( mockResultDataset [ 0 ] ) ;
88
+
89
+ console . log ( `Pending mocks for ${ workflowJsonName } :` , scope . pendingMocks ( ) ) ;
90
+ expect ( scope . isDone ( ) ) . toBe ( true ) ;
91
+ } ,
92
+ ) ;
73
93
} ) ;
74
94
} ) ;
75
95
} ) ;
0 commit comments