|
| 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 {WorkflowBuilder} from "../../src"; |
| 18 | +import * as fs from "fs"; |
| 19 | +import { |
| 20 | + ActionBuilder, EndBuilder, |
| 21 | + EventBuilder, |
| 22 | + EventsBuilder, |
| 23 | + ForEachStateBuilder, |
| 24 | + FunctionDefBuilder, |
| 25 | + FunctionRefBuilder, |
| 26 | + ProduceEventDefBuilder, |
| 27 | +} from '../../src'; |
| 28 | + |
| 29 | + |
| 30 | +describe("sendcloudevent workflow example", () => { |
| 31 | + |
| 32 | + |
| 33 | + it('should generate Workflow object', function () { |
| 34 | + |
| 35 | + const workflow = new WorkflowBuilder() |
| 36 | + .withId("sendcloudeventonprovision") |
| 37 | + .withVersion("1.0") |
| 38 | + .withName("Send CloudEvent on provision completion") |
| 39 | + .withStart("ProvisionOrdersState") |
| 40 | + .withEvents( |
| 41 | + new EventsBuilder() |
| 42 | + .withEvents([ |
| 43 | + new EventBuilder() |
| 44 | + .withName("provisioningCompleteEvent") |
| 45 | + .withType("provisionCompleteType") |
| 46 | + .withKind("produced") |
| 47 | + .build(), |
| 48 | + |
| 49 | + ]).build(), |
| 50 | + ) |
| 51 | + .withFunctions([ |
| 52 | + new FunctionDefBuilder() |
| 53 | + .withName("provisionOrderFunction") |
| 54 | + .withOperation("http://myapis.org/provisioning.json#doProvision") |
| 55 | + .build(), |
| 56 | + ]) |
| 57 | + .withStates([ |
| 58 | + new ForEachStateBuilder() |
| 59 | + .withName("ProvisionOrdersState") |
| 60 | + .withInputCollection("${ .orders }") |
| 61 | + .withIterationParam("singleorder") |
| 62 | + .withOutputCollection("${ .provisionedOrders }") |
| 63 | + .withActions([ |
| 64 | + new ActionBuilder() |
| 65 | + .withFunctionRef( |
| 66 | + new FunctionRefBuilder() |
| 67 | + .withRefName("provisionOrderFunction") |
| 68 | + .withArguments({ |
| 69 | + "order": "${ .singleorder }", |
| 70 | + }) |
| 71 | + .build(), |
| 72 | + ) |
| 73 | + .build(), |
| 74 | + ]) |
| 75 | + .withEnd( |
| 76 | + new EndBuilder() |
| 77 | + .withProduceEvents([ |
| 78 | + new ProduceEventDefBuilder() |
| 79 | + .withEventRef("provisioningCompleteEvent") |
| 80 | + .withData("${ .provisionedOrders }") |
| 81 | + .build(), |
| 82 | + ]) |
| 83 | + .build(), |
| 84 | + ) |
| 85 | + .build(), |
| 86 | + ]) |
| 87 | + .build(); |
| 88 | + |
| 89 | + |
| 90 | + |
| 91 | + |
| 92 | + const expected = JSON.parse(fs.readFileSync("./spec/examples/sendcloudevent.json") |
| 93 | + .toLocaleString()) as any; |
| 94 | + expect(workflow).toEqual(expected); |
| 95 | + |
| 96 | + }); |
| 97 | + |
| 98 | + |
| 99 | +}); |
0 commit comments