@@ -2,6 +2,7 @@ const Clarifai = require('./../src');
22const { errorHandler} = require ( './helpers' ) ;
33const { sampleImages} = require ( './test-data' ) ;
44const generalModelVersionId = 'aa9ca48295b37401f8af92ad1af0d91d' ;
5+ const Workflows = require ( './../src/Workflows' ) ;
56
67let app ;
78let testWorkflowId ;
@@ -14,9 +15,30 @@ describe('Workflow', () => {
1415 } ) ;
1516 } ) ;
1617
18+ it ( 'Gets all workflows' , done => {
19+ app . workflows . list ( {
20+ page : 1 ,
21+ perPage : 5
22+ } )
23+ . then ( workflows => {
24+ expect ( workflows ) . toBeDefined ( ) ;
25+ expect ( workflows instanceof Workflows ) . toBe ( true ) ;
26+
27+ for ( let i = 0 ; i < workflows . length ; i ++ ) {
28+ let workflow = workflows [ i ] ;
29+ expect ( workflow . id ) . toBeDefined ( ) ;
30+ expect ( workflow . appId ) . toBeDefined ( ) ;
31+ expect ( workflow . createdAt ) . toBeDefined ( ) ;
32+ }
33+
34+ done ( ) ;
35+ } )
36+ . catch ( errorHandler . bind ( done ) ) ;
37+ } ) ;
38+
1739 it ( 'Call given workflow id with one input' , done => {
1840 testWorkflowId = 'big-bang' + Date . now ( ) ;
19- app . workflow . create ( testWorkflowId , {
41+ app . workflows . create ( testWorkflowId , {
2042 modelId : Clarifai . GENERAL_MODEL ,
2143 modelVersionId : generalModelVersionId
2244 } )
@@ -36,22 +58,32 @@ describe('Workflow', () => {
3658 expect ( output . created_at ) . toBeDefined ( ) ;
3759 expect ( output . model ) . toBeDefined ( ) ;
3860 expect ( output . model . model_version ) . toBeDefined ( ) ;
61+ } )
62+ . then ( ( ) => {
63+ app . workflows . delete ( testWorkflowId ) ;
3964 done ( ) ;
4065 } )
4166 . catch ( errorHandler . bind ( done ) ) ;
4267 } ) ;
4368
4469 it ( 'Call given workflow id with multiple inputs with specified types' , done => {
45- app . workflow . predict ( testWorkflowId , [
46- {
47- url : sampleImages [ 0 ] ,
48- allowDuplicateUrl : true
49- } ,
50- {
51- url : sampleImages [ 1 ] ,
52- allowDuplicateUrl : true
53- }
54- ] )
70+ testWorkflowId = 'big-bang' + Date . now ( ) ;
71+ app . workflows . create ( testWorkflowId , {
72+ modelId : Clarifai . GENERAL_MODEL ,
73+ modelVersionId : generalModelVersionId
74+ } )
75+ . then ( ( ) => {
76+ return app . workflow . predict ( testWorkflowId , [
77+ {
78+ url : sampleImages [ 0 ] ,
79+ allowDuplicateUrl : true
80+ } ,
81+ {
82+ url : sampleImages [ 1 ] ,
83+ allowDuplicateUrl : true
84+ }
85+ ] ) ;
86+ } )
5587 . then ( response => {
5688 expect ( response . workflow ) . toBeDefined ( ) ;
5789 const results = response . results ;
@@ -66,16 +98,25 @@ describe('Workflow', () => {
6698 expect ( output . created_at ) . toBeDefined ( ) ;
6799 expect ( output . model ) . toBeDefined ( ) ;
68100 expect ( output . model . model_version ) . toBeDefined ( ) ;
101+ } )
102+ . then ( ( ) => {
103+ app . workflows . delete ( testWorkflowId ) ;
69104 done ( ) ;
70105 } )
71106 . catch ( errorHandler . bind ( done ) ) ;
72107 } ) ;
73108
74109 it ( 'Call given workflow id with multiple inputs without specified types' , done => {
75- app . workflow . predict ( testWorkflowId , [
76- sampleImages [ 2 ] ,
77- sampleImages [ 3 ]
78- ] )
110+ testWorkflowId = 'big-bang' + Date . now ( ) ;
111+ app . workflows . create ( testWorkflowId , {
112+ modelId : Clarifai . GENERAL_MODEL ,
113+ modelVersionId : generalModelVersionId
114+ } )
115+ . then ( ( ) => {
116+ return app . workflow . predict ( testWorkflowId , [
117+ sampleImages [ 2 ] , sampleImages [ 3 ]
118+ ] ) ;
119+ } )
79120 . then ( response => {
80121 expect ( response . workflow ) . toBeDefined ( ) ;
81122 const results = response . results ;
@@ -92,7 +133,8 @@ describe('Workflow', () => {
92133 expect ( output . model . model_version ) . toBeDefined ( ) ;
93134 return app . workflow . delete ( testWorkflowId ) ;
94135 } )
95- . then ( response => {
136+ . then ( ( ) => {
137+ app . workflows . delete ( testWorkflowId ) ;
96138 done ( ) ;
97139 } )
98140 . catch ( errorHandler . bind ( done ) ) ;
0 commit comments