-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.test.ts
More file actions
94 lines (80 loc) · 3.67 KB
/
Copy pathindex.test.ts
File metadata and controls
94 lines (80 loc) · 3.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import "reflect-metadata";
import { describe, expect, it } from "vitest";
import { Parameter } from "../src/decorators/function.dec";
import { EventSetting } from "../src/decorators/event.dec";
import { Identifier } from "../src/decorators/meta.dec";
import { eventMap } from "../src/map/event.map";
import { runtimeEventMap } from "../src/map/runtime_event.map";
import { Rest } from "../src/definitions/draco_rest/runtime_flow_types/rest";
describe("Parameter decorator", () => {
it("preserves source order across multiple decorators", () => {
@Parameter({ runtimeName: "first" })
@Parameter({ runtimeName: "second" })
@Parameter({ runtimeName: "third" })
class Foo {}
const parameters = Reflect.getMetadata("hercules:function_parameters", Foo);
expect(parameters.map((p: { runtimeName: string }) => p.runtimeName)).toEqual([
"first",
"second",
"third",
]);
});
it("works for a single parameter", () => {
@Parameter({ runtimeName: "only" })
class Bar {}
const parameters = Reflect.getMetadata("hercules:function_parameters", Bar);
expect(parameters.map((p: { runtimeName: string }) => p.runtimeName)).toEqual(["only"]);
});
});
describe("eventMap", () => {
const restSettingOrder = [
"httpSchema",
"httpURL",
"httpMethod",
"httpAuth",
"httpAuthValue",
"input_schema",
];
it("keeps the runtime event's setting order regardless of override order", () => {
@Identifier("ScrambledOverrides")
@EventSetting({ identifier: "input_schema", hidden: true, defaultValue: {} })
@EventSetting({ identifier: "httpAuthValue", hidden: true })
@EventSetting({ identifier: "httpSchema", hidden: true, defaultValue: "application/json" })
@EventSetting({ identifier: "httpMethod", hidden: true, defaultValue: "POST" })
class ScrambledOverrides extends Rest {}
const def = eventMap(ScrambledOverrides);
expect(def.settings?.map(s => s.identifier)).toEqual(restSettingOrder);
});
it("merges override properties into the runtime event's setting", () => {
@Identifier("MethodOverride")
@EventSetting({ identifier: "httpMethod", hidden: true, defaultValue: "POST" })
class MethodOverride extends Rest {}
const httpMethod = eventMap(MethodOverride).settings?.find(s => s.identifier === "httpMethod");
expect(httpMethod?.hidden).toBe(true);
expect(httpMethod?.defaultValue).toBe("POST");
expect(httpMethod?.name).toEqual([{ code: "en-US", content: "Method" }]);
});
it("does not pollute the runtime event's settings via subclass overrides", () => {
@Identifier("PollutionCheck")
@EventSetting({ identifier: "httpMethod", hidden: true, defaultValue: "POST" })
class PollutionCheck extends Rest {}
eventMap(PollutionCheck);
const restSettings = runtimeEventMap(Rest).settings ?? [];
expect(restSettings.map(s => s.identifier)).toEqual(restSettingOrder);
expect(restSettings.find(s => s.identifier === "httpMethod")?.hidden).toBeUndefined();
});
});
describe("EventSetting decorator", () => {
it("preserves source order across multiple decorators", () => {
@EventSetting({ identifier: "first" })
@EventSetting({ identifier: "second" })
@EventSetting({ identifier: "third" })
class Event {}
const settings = Reflect.getMetadata("hercules:flow_settings", Event);
expect(settings.map((s: { identifier: string }) => s.identifier)).toEqual([
"first",
"second",
"third",
]);
});
});