@@ -54,29 +54,21 @@ describe('ZFL Parser - Subscriptions', () => {
5454 describe ( 'Subscription system' , ( ) => {
5555 it ( 'should have correct name and zdl' , ( ) => {
5656 assert . equal ( jsonPath ( model , "$.flows.PaymentsFlow.systems.Subscription.name" ) , "Subscription" ) ;
57- assert . equal ( jsonPath ( model , "$.flows.PaymentsFlow.systems.Subscription.zdl" ) , "subscription/model.zdl" ) ;
57+ assert . equal ( jsonPath ( model , "$.flows.PaymentsFlow.systems.Subscription.options. zdl" ) , "subscription/model.zdl" ) ;
5858 } ) ;
5959
6060 it ( 'should have 1 service' , ( ) => {
6161 assert . equal ( mapSize ( jsonPath ( model , "$.flows.PaymentsFlow.systems.Subscription.services" ) ) , 1 ) ;
6262 } ) ;
6363
6464 it ( 'should have SubscriptionService with correct commands' , ( ) => {
65- assert . equal ( jsonPath ( model , "$.flows.PaymentsFlow.systems.Subscription.services.DefaultService .name" ) , "DefaultService " ) ;
66- const commands = jsonPath ( model , "$.flows.PaymentsFlow.systems.Subscription.services.DefaultService .commands" ) ;
65+ assert . equal ( jsonPath ( model , "$.flows.PaymentsFlow.systems.Subscription.services.SubscriptionService .name" ) , "SubscriptionService " ) ;
66+ const commands = jsonPath ( model , "$.flows.PaymentsFlow.systems.Subscription.services.SubscriptionService .commands" ) ;
6767 assert . equal ( arraySize ( commands ) , 3 ) ;
6868 assert . equal ( commands [ 0 ] , "renewSubscription" ) ;
6969 assert . equal ( commands [ 1 ] , "suspendSubscription" ) ;
7070 assert . equal ( commands [ 2 ] , "cancelRenewal" ) ;
7171 } ) ;
72-
73- it ( 'should have correct events' , ( ) => {
74- const events = jsonPath ( model , "$.flows.PaymentsFlow.systems.Subscription.events" ) ;
75- assert . equal ( arraySize ( events ) , 3 ) ;
76- assert . equal ( events [ 0 ] , "SubscriptionRenewed" ) ;
77- assert . equal ( events [ 1 ] , "SubscriptionSuspended" ) ;
78- assert . equal ( events [ 2 ] , "RenewalCancelled" ) ;
79- } ) ;
8072 } ) ;
8173
8274 describe ( 'Payments system' , ( ) => {
@@ -147,9 +139,9 @@ describe('ZFL Parser - Subscriptions', () => {
147139 } ) ;
148140
149141 describe ( 'when blocks' , ( ) => {
150- it ( 'should have 5 when blocks' , ( ) => {
142+ it ( 'should have 6 when blocks' , ( ) => {
151143 const whens = jsonPath ( model , "$.flows.PaymentsFlow.whens" ) ;
152- assert . equal ( arraySize ( whens ) , 5 ) ;
144+ assert . equal ( arraySize ( whens ) , 6 ) ;
153145 } ) ;
154146
155147 describe ( 'first when block' , ( ) => {
@@ -159,10 +151,8 @@ describe('ZFL Parser - Subscriptions', () => {
159151 assert . equal ( triggers [ 0 ] , "CustomerRequestsSubscriptionRenewal" ) ;
160152 } ) ;
161153
162- it ( 'should have correct commands' , ( ) => {
163- const commands = jsonPath ( model , "$.flows.PaymentsFlow.whens[0].commands" ) ;
164- assert . equal ( arraySize ( commands ) , 1 ) ;
165- assert . equal ( commands [ 0 ] , "renewSubscription" ) ;
154+ it ( 'should have correct command' , ( ) => {
155+ assert . equal ( jsonPath ( model , "$.flows.PaymentsFlow.whens[0].command" ) , "renewSubscription" ) ;
166156 } ) ;
167157
168158 it ( 'should have correct events' , ( ) => {
@@ -179,10 +169,8 @@ describe('ZFL Parser - Subscriptions', () => {
179169 assert . equal ( triggers [ 0 ] , "SubscriptionRenewed" ) ;
180170 } ) ;
181171
182- it ( 'should have correct commands' , ( ) => {
183- const commands = jsonPath ( model , "$.flows.PaymentsFlow.whens[1].commands" ) ;
184- assert . equal ( arraySize ( commands ) , 1 ) ;
185- assert . equal ( commands [ 0 ] , "chargePayment" ) ;
172+ it ( 'should have correct command' , ( ) => {
173+ assert . equal ( jsonPath ( model , "$.flows.PaymentsFlow.whens[1].command" ) , "chargePayment" ) ;
186174 } ) ;
187175
188176 it ( 'should have correct events' , ( ) => {
@@ -193,94 +181,82 @@ describe('ZFL Parser - Subscriptions', () => {
193181 } ) ;
194182 } ) ;
195183
196- describe ( 'third when block with if/else ' , ( ) => {
184+ describe ( 'third when block with if condition ' , ( ) => {
197185 it ( 'should have correct triggers' , ( ) => {
198186 const triggers = jsonPath ( model , "$.flows.PaymentsFlow.whens[2].triggers" ) ;
199187 assert . equal ( arraySize ( triggers ) , 1 ) ;
200188 assert . equal ( triggers [ 0 ] , "PaymentFailed" ) ;
201189 } ) ;
202190
203- it ( 'should have 1 if block' , ( ) => {
204- const ifs = jsonPath ( model , "$.flows.PaymentsFlow.whens[2].ifs" ) ;
205- assert . equal ( arraySize ( ifs ) , 1 ) ;
206- } ) ;
207-
208191 it ( 'should have correct if condition' , ( ) => {
209- assert . equal ( jsonPath ( model , "$.flows.PaymentsFlow.whens[2].ifs[0].condition " ) , "less than 3 attempts" ) ;
192+ assert . equal ( jsonPath ( model , "$.flows.PaymentsFlow.whens[2].options.if " ) , "less than 3 attempts" ) ;
210193 } ) ;
211194
212- it ( 'should have correct if commands' , ( ) => {
213- const commands = jsonPath ( model , "$.flows.PaymentsFlow.whens[2].ifs[0].commands" ) ;
214- assert . equal ( arraySize ( commands ) , 1 ) ;
215- assert . equal ( commands [ 0 ] , "retryPayment" ) ;
195+ it ( 'should have correct command' , ( ) => {
196+ assert . equal ( jsonPath ( model , "$.flows.PaymentsFlow.whens[2].command" ) , "retryPayment" ) ;
216197 } ) ;
217198
218- it ( 'should have correct if events' , ( ) => {
219- const events = jsonPath ( model , "$.flows.PaymentsFlow.whens[2].ifs[0]. events" ) ;
199+ it ( 'should have correct events' , ( ) => {
200+ const events = jsonPath ( model , "$.flows.PaymentsFlow.whens[2].events" ) ;
220201 assert . equal ( arraySize ( events ) , 1 ) ;
221202 assert . equal ( events [ 0 ] , "PaymentRetryScheduled" ) ;
222203 } ) ;
204+ } ) ;
223205
224- it ( 'should have else block' , ( ) => {
225- const elseBlock = jsonPath ( model , "$.flows.PaymentsFlow.whens[2].ifs[0].else" ) ;
226- assert . notEqual ( elseBlock , null ) ;
206+ describe ( 'fourth when block with if condition (else case)' , ( ) => {
207+ it ( 'should have correct triggers' , ( ) => {
208+ const triggers = jsonPath ( model , "$.flows.PaymentsFlow.whens[3].triggers" ) ;
209+ assert . equal ( arraySize ( triggers ) , 1 ) ;
210+ assert . equal ( triggers [ 0 ] , "PaymentFailed" ) ;
227211 } ) ;
228212
229- it ( 'should have correct else policies' , ( ) => {
230- const policies = jsonPath ( model , "$.flows.PaymentsFlow.whens[2].ifs[0].else.policies" ) ;
231- assert . equal ( arraySize ( policies ) , 1 ) ;
232- assert . equal ( policies [ 0 ] , "Suspend after 3 failed attempts" ) ;
213+ it ( 'should have correct if condition' , ( ) => {
214+ assert . equal ( jsonPath ( model , "$.flows.PaymentsFlow.whens[3].options.if" ) , "3 or more attempts" ) ;
233215 } ) ;
234216
235- it ( 'should have correct else commands' , ( ) => {
236- const commands = jsonPath ( model , "$.flows.PaymentsFlow.whens[2].ifs[0].else.commands" ) ;
237- assert . equal ( arraySize ( commands ) , 1 ) ;
238- assert . equal ( commands [ 0 ] , "suspendSubscription" ) ;
217+ it ( 'should have correct command' , ( ) => {
218+ assert . equal ( jsonPath ( model , "$.flows.PaymentsFlow.whens[3].command" ) , "suspendSubscription" ) ;
239219 } ) ;
240220
241- it ( 'should have correct else events' , ( ) => {
242- const events = jsonPath ( model , "$.flows.PaymentsFlow.whens[2].ifs[0].else .events" ) ;
221+ it ( 'should have correct events' , ( ) => {
222+ const events = jsonPath ( model , "$.flows.PaymentsFlow.whens[3] .events" ) ;
243223 assert . equal ( arraySize ( events ) , 1 ) ;
244224 assert . equal ( events [ 0 ] , "SubscriptionSuspended" ) ;
245225 } ) ;
246226 } ) ;
247227
248- describe ( 'fourth when block with AND trigger' , ( ) => {
228+ describe ( 'fifth when block with AND trigger' , ( ) => {
249229 it ( 'should have 2 triggers (AND condition)' , ( ) => {
250- const triggers = jsonPath ( model , "$.flows.PaymentsFlow.whens[3 ].triggers" ) ;
230+ const triggers = jsonPath ( model , "$.flows.PaymentsFlow.whens[4 ].triggers" ) ;
251231 assert . equal ( arraySize ( triggers ) , 2 ) ;
252232 assert . equal ( triggers [ 0 ] , "PaymentSucceeded" ) ;
253233 assert . equal ( triggers [ 1 ] , "BillingCycleEnded" ) ;
254234 } ) ;
255235
256- it ( 'should have correct commands' , ( ) => {
257- const commands = jsonPath ( model , "$.flows.PaymentsFlow.whens[3].commands" ) ;
258- assert . equal ( arraySize ( commands ) , 1 ) ;
259- assert . equal ( commands [ 0 ] , "recordPayment" ) ;
236+ it ( 'should have correct command' , ( ) => {
237+ assert . equal ( jsonPath ( model , "$.flows.PaymentsFlow.whens[4].command" ) , "recordPayment" ) ;
260238 } ) ;
261239
262240 it ( 'should have correct events' , ( ) => {
263- const events = jsonPath ( model , "$.flows.PaymentsFlow.whens[3 ].events" ) ;
241+ const events = jsonPath ( model , "$.flows.PaymentsFlow.whens[4 ].events" ) ;
264242 assert . equal ( arraySize ( events ) , 1 ) ;
265243 assert . equal ( events [ 0 ] , "PaymentRecorded" ) ;
266244 } ) ;
267245 } ) ;
268246
269- describe ( 'fifth when block' , ( ) => {
247+ describe ( 'sixth when block' , ( ) => {
270248 it ( 'should have correct triggers' , ( ) => {
271- const triggers = jsonPath ( model , "$.flows.PaymentsFlow.whens[4 ].triggers" ) ;
249+ const triggers = jsonPath ( model , "$.flows.PaymentsFlow.whens[5 ].triggers" ) ;
272250 assert . equal ( arraySize ( triggers ) , 1 ) ;
273251 assert . equal ( triggers [ 0 ] , "PaymentTimeout" ) ;
274252 } ) ;
275253
276- it ( 'should have correct commands' , ( ) => {
277- const commands = jsonPath ( model , "$.flows.PaymentsFlow.whens[4].commands" ) ;
278- assert . equal ( arraySize ( commands ) , 1 ) ;
279- assert . equal ( commands [ 0 ] , "cancelRenewal" ) ;
254+ it ( 'should have correct command' , ( ) => {
255+ assert . equal ( jsonPath ( model , "$.flows.PaymentsFlow.whens[5].command" ) , "cancelRenewal" ) ;
280256 } ) ;
281257
282258 it ( 'should have correct events' , ( ) => {
283- const events = jsonPath ( model , "$.flows.PaymentsFlow.whens[4 ].events" ) ;
259+ const events = jsonPath ( model , "$.flows.PaymentsFlow.whens[5 ].events" ) ;
284260 assert . equal ( arraySize ( events ) , 1 ) ;
285261 assert . equal ( events [ 0 ] , "RenewalCancelled" ) ;
286262 } ) ;
0 commit comments