-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbaseUtil.test.ts
More file actions
82 lines (69 loc) · 2.18 KB
/
baseUtil.test.ts
File metadata and controls
82 lines (69 loc) · 2.18 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
import { validateYamlInput } from "../../../src/util/baseUtil.ts"
import { RapLPBaseApiError } from "../../../src/util/RapLPBaseApiErrorHandling.ts";
describe('validateYamlInput', () => {
test('should return true for valid YAML string with all top-level keys', () => {
const validYaml = `
openapi: 3.0.3
info: some info
paths:
`;
const result = validateYamlInput(validYaml);
expect(result).toBe(true);
});
test('should throw error for missing top-level keys', () => {
const missingTopLevelKeysYaml = `
name: Jane Smith
age: 25
occupation: Designer
`;
try {
validateYamlInput(missingTopLevelKeysYaml);
} catch (error) {
if (error instanceof RapLPBaseApiError) {
expect(error.title).toBe("Missing required top-level keys");
expect(error.message).toContain("Missing required top-level keys: openapi, info, paths");
}
}
});
test('should throw error for invalid YAML string', () => {
// Invalid YAML: Missing colon after 'age'
const invalidYaml = `
name: Jane Smith
age 25
occupation: Designer
`;
try {
validateYamlInput(invalidYaml);
} catch (error) {
if (error instanceof RapLPBaseApiError) {
expect(error.title).toBe("Could not validate Yaml");
expect(error.message).toContain("YAML Syntax Error:");
}
}
});
test('should throw error for malformed YAML', () => {
// Completely malformed YAML
const malformedYaml = `Just
some
random: text: that is not YAML.`;
try {
validateYamlInput(malformedYaml);
} catch (error) {
if (error instanceof RapLPBaseApiError) {
expect(error.title).toBe("Could not validate Yaml");
expect(error.message).toContain("YAML Syntax Error:");
}
}
});
test('should throw error for empty string', () => {
const emptyYaml = "";
try {
validateYamlInput(emptyYaml);
} catch (error) {
if (error instanceof RapLPBaseApiError) {
expect(error.title).toBe("Could not validate Yaml");
expect(error.message).toContain("Parsed YAML is not a valid object");
}
}
});
});