|
| 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 {ScheduleBuilder} from '../src/model/schedule.builder'; |
| 18 | +import {CronDef} from '../src'; |
| 19 | + |
| 20 | + |
| 21 | +describe("ScheduleBuilder", () => { |
| 22 | + |
| 23 | + it("should throws an error if mandatory fields are not set ", () => { |
| 24 | + |
| 25 | + expect(() => new ScheduleBuilder().build()).toThrowError(); |
| 26 | + |
| 27 | + expect(() => new ScheduleBuilder() |
| 28 | + .withInterval("").build()) |
| 29 | + .toThrowError(); |
| 30 | + }); |
| 31 | + |
| 32 | + |
| 33 | + it("should create a valid object when interval is set", () => { |
| 34 | + expect(new ScheduleBuilder() |
| 35 | + .withInterval("PT2S").build()) |
| 36 | + .toEqual("PT2S"); |
| 37 | + }); |
| 38 | + |
| 39 | + |
| 40 | + it("should create a valid object when interval and cron are set", () => { |
| 41 | + |
| 42 | + expect(new ScheduleBuilder() |
| 43 | + .withInterval("PT2S") |
| 44 | + .withCron(validCronDef()) |
| 45 | + .build()) |
| 46 | + .toEqual({ |
| 47 | + interval: "PT2S", |
| 48 | + cron: validCronDef(), |
| 49 | + timezone: "UTC", |
| 50 | + }); |
| 51 | + }); |
| 52 | + |
| 53 | + |
| 54 | + it("should allow set timezone", () => { |
| 55 | + |
| 56 | + expect(new ScheduleBuilder() |
| 57 | + .withInterval("PT2S") |
| 58 | + .withCron(validCronDef()) |
| 59 | + .withTimezone("CET") |
| 60 | + .build()) |
| 61 | + .toEqual({ |
| 62 | + interval: "PT2S", |
| 63 | + cron: validCronDef(), |
| 64 | + timezone: "CET", |
| 65 | + }); |
| 66 | + }); |
| 67 | +}); |
| 68 | + |
| 69 | + |
| 70 | +function validCronDef(): CronDef { |
| 71 | + return "0 * * ? * *"; |
| 72 | +} |
| 73 | + |
| 74 | + |
0 commit comments