forked from patternfly/patternfly-mcp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresource.patternFlySchemasTemplate.test.ts
More file actions
156 lines (146 loc) · 3.69 KB
/
Copy pathresource.patternFlySchemasTemplate.test.ts
File metadata and controls
156 lines (146 loc) · 3.69 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
import { McpError } from '@modelcontextprotocol/sdk/types.js';
import {
patternFlySchemasTemplateResource,
uriNameComplete,
resourceCallback
} from '../resource.patternFlySchemasTemplate';
import { isPlainObject } from '../server.helpers';
describe('patternFlySchemasTemplateResource', () => {
beforeEach(() => {
jest.clearAllMocks();
});
it('should have a consistent return structure', () => {
const resource = patternFlySchemasTemplateResource();
expect({
name: resource[0],
uri: resource[1],
config: isPlainObject(resource[2]),
handler: resource[3]
}).toMatchSnapshot('structure');
});
});
describe('uriNameComplete', () => {
it.each([
{
description: 'with empty string',
value: '',
expected: 5
},
{
description: 'with lowercased name',
value: 'button',
expected: 1
},
{
description: 'with uppercased name',
value: 'BUTTON',
expected: 1
},
{
description: 'with mixed case name',
value: 'bUTTON',
expected: 1
},
{
description: 'with empty space and name',
value: ' BUTTON ',
expected: 1
}
])('should attempt to return PatternFly component names, $description', async ({ value, expected }) => {
const result = await uriNameComplete(value);
expect(result.length).toBeGreaterThanOrEqual(expected);
});
});
describe('resourceCallback', () => {
beforeEach(() => {
jest.clearAllMocks();
});
it.each([
{ description: 'no version', variables: { name: 'Button' } },
{
description: 'default',
variables: {
name: 'Button',
version: 'v6'
}
},
{
description: 'with lowercased name',
variables: {
name: 'button',
version: 'v6'
}
},
{
description: 'with hashed button name',
variables: {
name: 'ffcfb1b9b852a17ccb5b2adc12e3edd4a4ee41cb',
version: 'v6'
}
}
])('should attempt to return resource content, $description', async ({ variables }) => {
const mockContent = '$schema';
const result = await resourceCallback(
{ href: `patternfly://schemas/v6/${variables.name}` } as any,
variables
);
expect(result.contents).toBeDefined();
expect(Object.keys(result.contents[0] as any)).toEqual(['uri', 'mimeType', 'text']);
expect(result.contents[0]?.text).toContain(mockContent);
});
it.each([
{
description: 'with missing or undefined name',
error: 'must be a string',
variables: {}
},
{
description: 'with null name',
error: 'must be a string',
variables: {
name: null
}
},
{
description: 'with empty name',
error: 'must be a string',
variables: {
name: ''
}
},
{
description: 'with non-string name',
error: 'must be a string',
variables: {
name: 123
}
},
{
description: 'non-existent name',
error: 'No component JSON schemas found',
variables: {
name: 'loremIpsum',
version: 'v6'
}
},
{
description: 'found but no schema',
error: 'No component JSON schemas found',
variables: {
name: 'table',
version: 'v6'
}
},
{
description: 'wrong version',
error: 'Invalid PatternFly version',
variables: {
name: 'button',
version: 'v5'
}
}
])('should handle variable errors, $description', async ({ error, variables }) => {
await expect(resourceCallback(undefined as any, variables as any)).rejects.toThrow(McpError);
await expect(resourceCallback(undefined as any, variables as any)).rejects.toThrow(error);
});
});