1414 * limitations under the License.
1515 *
1616 */
17- import { ActionBuilder , EventsBuilder , OperationStateBuilder , WorkflowBuilder } from '../../src' ;
17+ import {
18+ ActionBuilder ,
19+ DatabasedSwitchBuilder ,
20+ EventsBuilder ,
21+ OperationStateBuilder ,
22+ TransitionDataConditionBuilder ,
23+ WorkflowBuilder ,
24+ } from '../../src' ;
1825import * as fs from 'fs' ;
1926import { StartBuilder } from '../../src/model/start.builder' ;
2027import { EventStateBuilder } from '../../src/model/event-state.builder' ;
2128import { OnEventBuilder } from '../../src/model/on-event.builder' ;
2229import { FunctionRefBuilder } from '../../src/model/function-ref.builder' ;
2330import { FunctionsBuilder } from '../../src/model/functions.builder' ;
31+ import { EventBasedSwitchBuilder } from '../../src/model/event-based-switch.builder' ;
32+ import { TransitionEventConditionBuilder } from '../../src/model/transition-event-condition.builder' ;
33+ import { DelayStateBuilder } from '../../src/model/delay-state.builder' ;
2434
2535
2636describe ( "booklending workflow example" , ( ) => {
@@ -59,6 +69,96 @@ describe("booklending workflow example", () => {
5969 ] )
6070 . withTransition ( "Book Status Decision" )
6171 . build ( ) ,
72+ new DatabasedSwitchBuilder ( )
73+ . withName ( "Book Status Decision" )
74+ . withDataConditions ( [
75+ new TransitionDataConditionBuilder ( )
76+ . withName ( "Book is on loan" )
77+ . withCondition ( "${ .book.status == \"onloan\" }" )
78+ . withTransition ( "Report Status To Lender" )
79+ . build ( ) ,
80+ new TransitionDataConditionBuilder ( )
81+ . withName ( "Check is available" )
82+ . withCondition ( "${ .book.status == \"available\" }" )
83+ . withTransition ( "Check Out Book" )
84+ . build ( ) ,
85+ ] )
86+ . build ( ) ,
87+ new OperationStateBuilder ( )
88+ . withName ( "Report Status To Lender" )
89+ . withActions ( [
90+ new ActionBuilder ( )
91+ . withFunctionRef ( new FunctionRefBuilder ( )
92+ . withRefName ( "Send status to lender" )
93+ . withArguments ( {
94+ "bookid" : "${ .book.id }" ,
95+ "message" : "Book ${ .book.title } is already on loan" ,
96+ } )
97+ . build ( ) )
98+ . build ( ) ,
99+ ] )
100+ . withTransition ( "Wait for Lender response" )
101+ . build ( ) ,
102+ new EventBasedSwitchBuilder ( )
103+ . withName ( "Wait for Lender response" )
104+ . withEventConditions ( [
105+ new TransitionEventConditionBuilder ( )
106+ . withName ( "Hold Book" )
107+ . withEventRef ( "Hold Book Event" )
108+ . withTransition ( "Request Hold" )
109+ . build ( ) ,
110+ new TransitionEventConditionBuilder ( )
111+ . withName ( "Decline Book Hold" )
112+ . withEventRef ( "Decline Hold Event" )
113+ . withTransition ( "Cancel Request" )
114+ . build ( ) ,
115+ ] )
116+ . build ( ) ,
117+ new OperationStateBuilder ( )
118+ . withName ( "Request Hold" )
119+ . withActions ( [
120+ new ActionBuilder ( ) . withFunctionRef (
121+ new FunctionRefBuilder ( )
122+ . withRefName ( "Request hold for lender" )
123+ . withArguments ( {
124+ "bookid" : "${ .book.id }" ,
125+ "lender" : "${ .lender }" ,
126+ } ) . build ( ) ) . build ( ) ,
127+ ] )
128+ . withTransition ( "Wait two weeks" )
129+ . build ( ) ,
130+ new DelayStateBuilder ( )
131+ . withName ( "Wait two weeks" )
132+ . withTimeDelay ( "PT2W" )
133+ . withTransition ( "Get Book Status" )
134+ . build ( ) ,
135+ new OperationStateBuilder ( )
136+ . withName ( "Check Out Book" )
137+ . withActions ( [
138+ new ActionBuilder ( )
139+ . withFunctionRef (
140+ new FunctionRefBuilder ( )
141+ . withRefName ( "Check out book with id" )
142+ . withArguments ( {
143+ "bookid" : "${ .book.id }"
144+ } )
145+ . build ( ) )
146+ . build ( ) ,
147+ new ActionBuilder ( )
148+ . withFunctionRef (
149+ new FunctionRefBuilder ( )
150+ . withRefName ( "Notify Lender for checkout" )
151+ . withArguments ( {
152+ "bookid" : "${ .book.id }" ,
153+ "lender" : "${ .lender }"
154+ } )
155+ . build ( ) )
156+ . build ( )
157+
158+ ] )
159+ . withEnd ( true )
160+ . build ( )
161+
62162 ] )
63163 . withFunctions ( new FunctionsBuilder ( )
64164 . withURIDefinition ( "file://books/lending/functions.json" )
@@ -68,6 +168,7 @@ describe("booklending workflow example", () => {
68168 . build ( ) )
69169 . build ( ) ;
70170
171+
71172 const expected = JSON . parse ( fs . readFileSync ( "./spec/examples/booklending.json" )
72173 . toLocaleString ( ) ) as any ;
73174 expect ( workflow ) . toEqual ( expected ) ;
0 commit comments