Skip to content

Commit c99929f

Browse files
committed
fix: review update
1 parent 408643f commit c99929f

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

src/__tests__/server.resourceMeta.test.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,24 @@ describe('setMetadataOptions', () => {
8080

8181
expect(content).toContain('# Test Config Metadata');
8282
});
83+
84+
it('should fall back to empty values when a complete callback throws', async () => {
85+
const throwingComplete = jest.fn().mockRejectedValue(new Error('network error'));
86+
const options = setMetadataOptions({
87+
name: 'test',
88+
baseUri: 'test://uri',
89+
searchParams: [],
90+
config: { title: 'Test Config' } as any,
91+
metaConfig: {},
92+
complete: { version: throwingComplete },
93+
registerAllSearchCombinations: undefined
94+
});
95+
96+
const content = await options.metaHandler('v6');
97+
98+
expect(content).toContain('# Test Config Metadata');
99+
expect(throwingComplete).toHaveBeenCalledTimes(1);
100+
});
83101
});
84102

85103
describe('getUriBreakdown', () => {
@@ -97,6 +115,13 @@ describe('getUriBreakdown', () => {
97115
configUri: undefined,
98116
complete: { version: jest.fn() },
99117
expected: { isMetaTemplate: true, metaUri: 'test://uri/meta{?version}' }
118+
},
119+
{
120+
description: 'configUri provided overrides derived meta URI',
121+
uriOrTemplate: 'test://uri{?version}',
122+
configUri: 'test://custom/meta{?version}',
123+
complete: undefined,
124+
expected: { isMetaTemplate: true, metaUri: 'test://custom/meta{?version}' }
100125
}
101126
])('should breakdown URI, $description', ({ uriOrTemplate, configUri, complete, expected }) => {
102127
const result = getUriBreakdown({ uriOrTemplate, configUri, complete } as any);
@@ -168,4 +193,27 @@ describe('setMetaResources', () => {
168193
expect(JSON.stringify(response[1])).toContain(expected);
169194
expect(response).toMatchSnapshot();
170195
});
196+
197+
it('should append meta content to original resource read result', async () => {
198+
const originalContent = {
199+
contents: [{ uri: 'test://uri', mimeType: 'text/markdown', text: 'original' }]
200+
};
201+
const callback = jest.fn().mockResolvedValue(originalContent);
202+
const resource = () => [
203+
'test-resource',
204+
'test://uri',
205+
{ title: 'Test', description: 'Test' },
206+
callback,
207+
{ metaConfig: {} }
208+
];
209+
210+
const [, enhancedResource]: any = setMetaResources([resource] as any);
211+
const [, , , enhancedCallback] = enhancedResource();
212+
const result = await enhancedCallback(new URL('test://uri'), {});
213+
214+
expect(callback).toHaveBeenCalledTimes(1);
215+
expect(result.contents).toHaveLength(2);
216+
expect(result.contents[0].text).toBe('original');
217+
expect(result.contents[1].text).toContain('Test Metadata');
218+
});
171219
});

0 commit comments

Comments
 (0)