Skip to content

Commit d283d99

Browse files
committed
feat: adding test scenario for correct order of parameters and settings
1 parent 2bab8a1 commit d283d99

1 file changed

Lines changed: 41 additions & 6 deletions

File tree

ts/test/index.test.ts

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,44 @@
1+
import "reflect-metadata";
12
import { describe, expect, it } from "vitest";
3+
import { Parameter } from "../src/decorators/function.dec";
4+
import { EventSetting } from "../src/decorators/event.dec";
25

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+
]);
843
});
9-
});
44+
});

0 commit comments

Comments
 (0)