-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathMapboxDocumentationResource.test.ts
More file actions
102 lines (82 loc) · 3.26 KB
/
MapboxDocumentationResource.test.ts
File metadata and controls
102 lines (82 loc) · 3.26 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
// Copyright (c) Mapbox, Inc.
// Licensed under the MIT License.
import { describe, expect, it } from 'vitest';
import { MapboxDocumentationResource } from '../../../src/resources/mapbox-documentation-resource/MapboxDocumentationResource.js';
import { setupHttpRequest } from '../../utils/httpPipelineUtils.js';
describe('MapboxDocumentationResource', () => {
it('should have correct metadata', () => {
const { httpRequest } = setupHttpRequest();
const resource = new MapboxDocumentationResource({ httpRequest });
expect(resource.name).toBe('Mapbox Documentation');
expect(resource.uri).toBe('resource://mapbox-documentation');
expect(resource.mimeType).toBe('text/markdown');
expect(resource.description).toContain(
'Latest official Mapbox documentation'
);
});
it('should successfully fetch documentation content with proper MIME type', async () => {
const mockContent = `# Mapbox Documentation
This is the Mapbox developer documentation for LLMs.
## Web SDKs
- Mapbox GL JS for interactive maps
- Mobile SDKs for iOS and Android
## APIs
- Geocoding API for address search
- Directions API for routing`;
const { httpRequest, mockHttpRequest } = setupHttpRequest({
ok: true,
status: 200,
text: () => Promise.resolve(mockContent)
});
const resource = new MapboxDocumentationResource({ httpRequest });
const uri = new URL('resource://mapbox-documentation');
const result = await resource.readCallback(uri, {} as any);
expect(mockHttpRequest).toHaveBeenCalledWith(
'https://docs.mapbox.com/llms.txt',
{
headers: {
Accept: 'text/markdown, text/plain;q=0.9, */*;q=0.8',
'User-Agent': 'TestServer/1.0.0 (default, no-tag, abcdef)'
}
}
);
expect(result.contents).toHaveLength(1);
expect(result.contents[0]).toMatchObject({
uri: 'resource://mapbox-documentation',
mimeType: 'text/markdown',
text: mockContent
});
});
it('should handle HTTP errors', async () => {
const { httpRequest } = setupHttpRequest({
ok: false,
status: 404,
statusText: 'Not Found'
});
const resource = new MapboxDocumentationResource({ httpRequest });
const uri = new URL('resource://mapbox-documentation');
await expect(resource.readCallback(uri, {} as any)).rejects.toThrow(
'Failed to fetch Mapbox documentation: Not Found'
);
});
it('should handle network errors', async () => {
const { httpRequest } = setupHttpRequest({
text: () => Promise.reject(new Error('Network error'))
});
const resource = new MapboxDocumentationResource({ httpRequest });
const uri = new URL('resource://mapbox-documentation');
await expect(resource.readCallback(uri, {} as any)).rejects.toThrow(
'Failed to fetch Mapbox documentation: Network error'
);
});
it('should handle unknown errors', async () => {
const { httpRequest } = setupHttpRequest({
text: () => Promise.reject('String error')
});
const resource = new MapboxDocumentationResource({ httpRequest });
const uri = new URL('resource://mapbox-documentation');
await expect(resource.readCallback(uri, {} as any)).rejects.toThrow(
'Failed to fetch Mapbox documentation: Unknown error occurred'
);
});
});