|
| 1 | +import "reflect-metadata"; |
1 | 2 | import { describe, expect, it } from "vitest"; |
| 3 | +import { Parameter } from "../src/decorators/function.dec"; |
| 4 | +import { EventSetting } from "../src/decorators/event.dec"; |
2 | 5 |
|
3 | | -describe("index", () => { |
4 | | - // mock test |
5 | | - it("should pass", () => { |
6 | | - // compare true to true |
7 | | - expect(true).toBe(true); |
| 6 | +describe("Parameter decorator", () => { |
| 7 | + it("preserves source order across multiple decorators", () => { |
| 8 | + @Parameter({ runtimeName: "first" }) |
| 9 | + @Parameter({ runtimeName: "second" }) |
| 10 | + @Parameter({ runtimeName: "third" }) |
| 11 | + class Foo {} |
| 12 | + |
| 13 | + const parameters = Reflect.getMetadata("hercules:function_parameters", Foo); |
| 14 | + expect(parameters.map((p: { runtimeName: string }) => p.runtimeName)).toEqual([ |
| 15 | + "first", |
| 16 | + "second", |
| 17 | + "third", |
| 18 | + ]); |
| 19 | + }); |
| 20 | + |
| 21 | + it("works for a single parameter", () => { |
| 22 | + @Parameter({ runtimeName: "only" }) |
| 23 | + class Bar {} |
| 24 | + |
| 25 | + const parameters = Reflect.getMetadata("hercules:function_parameters", Bar); |
| 26 | + expect(parameters.map((p: { runtimeName: string }) => p.runtimeName)).toEqual(["only"]); |
| 27 | + }); |
| 28 | +}); |
| 29 | + |
| 30 | +describe("EventSetting decorator", () => { |
| 31 | + it("preserves source order across multiple decorators", () => { |
| 32 | + @EventSetting({ identifier: "first" }) |
| 33 | + @EventSetting({ identifier: "second" }) |
| 34 | + @EventSetting({ identifier: "third" }) |
| 35 | + class Event {} |
| 36 | + |
| 37 | + const settings = Reflect.getMetadata("hercules:flow_settings", Event); |
| 38 | + expect(settings.map((s: { identifier: string }) => s.identifier)).toEqual([ |
| 39 | + "first", |
| 40 | + "second", |
| 41 | + "third", |
| 42 | + ]); |
8 | 43 | }); |
9 | | -}); |
| 44 | +}); |
0 commit comments