forked from patternfly/patternfly-mcp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresource.patternFlyComponentsIndex.test.ts
More file actions
80 lines (71 loc) · 2.32 KB
/
Copy pathresource.patternFlyComponentsIndex.test.ts
File metadata and controls
80 lines (71 loc) · 2.32 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
import { McpError } from '@modelcontextprotocol/sdk/types.js';
import {
patternFlyComponentsIndexResource,
listResources,
resourceCallback
} from '../resource.patternFlyComponentsIndex';
import { isPlainObject } from '../server.helpers';
describe('patternFlyComponentsIndexResource', () => {
it('should have a consistent return structure', () => {
const resource = patternFlyComponentsIndexResource();
expect({
name: resource[0],
uri: resource[1],
config: isPlainObject(resource[2]),
handler: resource[3]
}).toMatchSnapshot('structure');
});
});
describe('listResources', () => {
it('should return a list of resources', async () => {
const resources = await listResources();
expect(resources.resources).toBeDefined();
const everyResourceSameProperties = resources.resources.every((obj: any) =>
Boolean(obj.uri) &&
/^patternfly:\/\/components\//.test(obj.uri) &&
Boolean(obj.name) &&
Boolean(obj.mimeType) &&
Boolean(obj.description));
expect(everyResourceSameProperties).toBe(true);
});
});
describe('resourceCallback', () => {
it.each([
{
description: 'default',
variables: {},
expected: '# PatternFly Components Index for "v6"'
},
{
description: 'explicit valid version',
variables: {
version: 'v6'
},
expected: '# PatternFly Components Index for "v6"'
},
{
description: 'category',
variables: {
category: 'accessibility'
},
expected: 'category=accessibility'
}
])('should return context content, $description', async ({ variables, expected }) => {
const result = await resourceCallback(undefined 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(expected);
});
it.each([
{
description: 'available version',
variables: {
version: 'v5'
},
error: 'Invalid PatternFly version'
}
])('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);
});
});