Skip to content

Commit 8e0c791

Browse files
committed
test(search): add missing branch tests for Search
1 parent 9f3b295 commit 8e0c791

File tree

1 file changed

+44
-23
lines changed

1 file changed

+44
-23
lines changed

src/search/search.test.ts

Lines changed: 44 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,34 +9,55 @@ const fullEndpoint = `${baseUrl}${endpoint}`;
99

1010
const hyper = new Hyper('hyper_1234');
1111

12+
const expectedResult = [
13+
{
14+
metadata: {
15+
name: 'Quarterly Sales Report Q1 2023',
16+
source: 'https://enterprise.gethyper.ai/reports/q1-sales-2023',
17+
type: 'web',
18+
},
19+
page_content:
20+
'Quarterly Sales Report Q1 2023\nExecutive Summary\nThe first quarter saw a 17% increase in sales across all sectors. The enterprise software division exceeded its targets with a significant contribution to the overall growth...',
21+
type: 'Document',
22+
},
23+
{
24+
metadata: {
25+
name: 'Market Analysis: Q1 Consumer Trends',
26+
source: 'https://enterprise.gethyper.ai/analyses/q1-market-trends',
27+
type: 'web',
28+
},
29+
page_content:
30+
'Market Analysis: Q1 Consumer Trends\nAbstract\nThis paper provides an in-depth analysis of consumer trends in the first quarter of 2023, highlighting the shifts in customer behavior...',
31+
type: 'Document',
32+
},
33+
];
34+
1235
describe('Hypercode Search API methods', () => {
1336
afterEach(() => fetchMock.resetMocks());
1437

1538
describe('execute method', () => {
16-
it('should return the correct search results for a query with contextId', async () => {
17-
const expectedResult = [
18-
{
19-
metadata: {
20-
name: 'Quarterly Sales Report Q1 2023',
21-
source: 'https://enterprise.gethyper.ai/reports/q1-sales-2023',
22-
type: 'web',
23-
},
24-
page_content:
25-
'Quarterly Sales Report Q1 2023\nExecutive Summary\nThe first quarter saw a 17% increase in sales across all sectors. The enterprise software division exceeded its targets with a significant contribution to the overall growth...',
26-
type: 'Document',
27-
},
28-
{
29-
metadata: {
30-
name: 'Market Analysis: Q1 Consumer Trends',
31-
source: 'https://enterprise.gethyper.ai/analyses/q1-market-trends',
32-
type: 'web',
33-
},
34-
page_content:
35-
'Market Analysis: Q1 Consumer Trends\nAbstract\nThis paper provides an in-depth analysis of consumer trends in the first quarter of 2023, highlighting the shifts in customer behavior...',
36-
type: 'Document',
37-
},
38-
];
39+
it('should return the correct search results for a query', async () => {
40+
fetchMock.mockOnce(JSON.stringify(expectedResult), {
41+
status: 200,
42+
});
43+
44+
const result = await hyper.search.execute('quarterly sales report');
3945

46+
expect(result.data).toEqual(expectedResult);
47+
expect(fetchMock).toHaveBeenLastCalledWith(
48+
fullEndpoint, // endpoint
49+
// body and headers
50+
expect.objectContaining({
51+
body: expect.stringContaining(
52+
JSON.stringify({
53+
query: 'quarterly sales report',
54+
}),
55+
),
56+
}),
57+
);
58+
});
59+
60+
it('should return the correct search results for a query with contextId', async () => {
4061
const contextId = '123e4567-e89b-12d3-a456-426614174000';
4162

4263
fetchMock.mockOnce(JSON.stringify(expectedResult), {

0 commit comments

Comments
 (0)