|
| 1 | +/* |
| 2 | + * Copyright 2021-Present The Serverless Workflow Specification Authors |
| 3 | + * <p> |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * <p> |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * <p> |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + * |
| 16 | + */ |
| 17 | +import {ActionBuilder, EventsBuilder, OperationStateBuilder, WorkflowBuilder} from '../../src'; |
| 18 | +import * as fs from 'fs'; |
| 19 | +import {StartBuilder} from '../../src/model/start.builder'; |
| 20 | +import {EventStateBuilder} from '../../src/model/event-state.builder'; |
| 21 | +import {OnEventBuilder} from '../../src/model/on-event.builder'; |
| 22 | +import {FunctionRefBuilder} from '../../src/model/function-ref.builder'; |
| 23 | +import {FunctionsBuilder} from '../../src/model/functions.builder'; |
| 24 | + |
| 25 | + |
| 26 | +describe("booklending workflow example", () => { |
| 27 | + |
| 28 | + |
| 29 | + it('should generate Workflow object', function () { |
| 30 | + |
| 31 | + const workflow = new WorkflowBuilder() |
| 32 | + .withId("booklending") |
| 33 | + .withName("Book Lending Workflow") |
| 34 | + .withVersion("1.0") |
| 35 | + .withStart(new StartBuilder() |
| 36 | + .withName("Book Lending Request") |
| 37 | + .build()) |
| 38 | + .withStates([ |
| 39 | + new EventStateBuilder() |
| 40 | + .withName("Book Lending Request") |
| 41 | + .withOnEvents([ |
| 42 | + new OnEventBuilder() |
| 43 | + .withEventsRef(["Book Lending Request Event"]) |
| 44 | + .build(), |
| 45 | + ]) |
| 46 | + .withTransition("Get Book Status") |
| 47 | + .build(), |
| 48 | + new OperationStateBuilder() |
| 49 | + .withName("Get Book Status") |
| 50 | + .withActions([ |
| 51 | + new ActionBuilder().withFunctionRef( |
| 52 | + new FunctionRefBuilder() |
| 53 | + .withRefName("Get status for book") |
| 54 | + .withArguments({ |
| 55 | + "bookid": "${ .book.id }", |
| 56 | + }) |
| 57 | + .build(), |
| 58 | + ).build(), |
| 59 | + ]) |
| 60 | + .withTransition("Book Status Decision") |
| 61 | + .build(), |
| 62 | + ]) |
| 63 | + .withFunctions(new FunctionsBuilder() |
| 64 | + .withURIDefinition("file://books/lending/functions.json") |
| 65 | + .build()) |
| 66 | + .withEvents(new EventsBuilder() |
| 67 | + .withURIDefinition("file://books/lending/events.json") |
| 68 | + .build()) |
| 69 | + .build(); |
| 70 | + |
| 71 | + const expected = JSON.parse(fs.readFileSync("./spec/examples/booklending.json") |
| 72 | + .toLocaleString()) as any; |
| 73 | + expect(workflow).toEqual(expected); |
| 74 | + |
| 75 | + }); |
| 76 | + |
| 77 | + |
| 78 | +}); |
0 commit comments