-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathgenerate-method-id.test.ts
More file actions
90 lines (79 loc) · 2.76 KB
/
generate-method-id.test.ts
File metadata and controls
90 lines (79 loc) · 2.76 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
import { generateMethodParamId, generateMethodResultId } from "./generate-method-id";
import { MethodObject } from "./types";
describe("methodParamId", () => {
describe("default paramStructure: either", () => {
it("returns an id for params:", () => {
const method = {
name: "foo",
params: [{ name: "bar", schema: {} }],
result: { name: "baz", schema: {} },
};
const result = generateMethodParamId(method, method.params[0]);
expect(result).toBe("foo/bar/0");
});
});
describe("paramStructure: by-position", () => {
it("returns an id for params:", () => {
const method = {
name: "foo",
paramStructure: "by-position",
params: [{ name: "bar", schema: {} }],
result: { name: "baz", schema: {} },
} as MethodObject;
const result = generateMethodParamId(method, { name: "bar", schema: {} });
expect(result).toBe("foo/0");
});
it("throws when the content descriptor is not found in the params", () => {
const method = {
name: "foo",
params: [{ name: "u will never get dis", schema: {} }],
result: { name: "baz", schema: {} },
} as MethodObject;
expect(() => generateMethodParamId(method, { name: "123", schema: {} })).toThrow(
"Content Descriptor not found in method."
);
});
});
describe("paramStructure: by-name", () => {
it("returns an id for params:", () => {
const method = {
name: "foo",
paramStructure: "by-name",
params: [{ name: "bar", schema: {} }],
result: { name: "baz", schema: {} },
} as MethodObject;
const result = generateMethodParamId(method, { name: "bar", schema: {} });
expect(result).toBe("foo/bar");
});
it("throws when the content descriptor is not found in the params", () => {
const method = {
name: "foo",
paramStructure: "by-name",
params: [{ name: "bar", schema: {} }],
result: { name: "baz", schema: {} },
} as MethodObject;
expect(() => generateMethodParamId(method, { name: "123", schema: {} })).toThrow();
});
});
});
describe("methodResultId", () => {
it("returns an id for result", () => {
const method = {
name: "foo",
params: [{ name: "bar", schema: {} }],
result: { name: "baz", schema: {} },
};
const result = generateMethodResultId(method, method.result);
expect(result).toBe("foo/result");
});
it("throws when the result doesnt match the methods result", () => {
const method = {
name: "foo",
params: [],
result: { name: "baz", schema: {} },
};
expect(() => generateMethodResultId(method, { name: "peepee", schema: {} })).toThrow(
"Content Descriptor not found in method."
);
});
});