Skip to content

Commit 9a0be8d

Browse files
committed
test: add unit tests for GET /onboarding/follow-suggestions endpoint
1 parent 4b4b984 commit 9a0be8d

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { describe, it, expect, vi, beforeEach } from 'vitest';
2+
import { createMockH3Event } from '~~/test/mocks/h3-event';
3+
import { useH3TestUtils } from '~~/test/mocks/h3-test-utils';
4+
import followSuggestionsHandler from '~~/server/api/onboarding/follow-suggestions.get';
5+
6+
useH3TestUtils();
7+
8+
const mockServerApiFetch = vi.fn();
9+
vi.stubGlobal('serverApiFetch', () => mockServerApiFetch);
10+
11+
describe('GET /onboarding/follow-suggestions', () => {
12+
beforeEach(() => {
13+
vi.clearAllMocks();
14+
});
15+
it('returns user follow suggestions', async () => {
16+
const mockResponse = {
17+
success: true,
18+
data: [
19+
{
20+
username: 'janedoe',
21+
displayName: 'Jane Doe',
22+
},
23+
],
24+
};
25+
mockServerApiFetch.mockResolvedValueOnce(mockResponse);
26+
27+
const event = createMockH3Event({
28+
method: 'GET',
29+
query: {
30+
cursor: 'abc123',
31+
limit: '10',
32+
},
33+
});
34+
35+
const response = await followSuggestionsHandler(event);
36+
37+
expect(mockServerApiFetch).toHaveBeenCalledWith('/onboarding/follow-suggestions', {
38+
method: 'GET',
39+
query: { cursor: 'abc123', limit: '10' },
40+
});
41+
expect(response).toMatchObject(mockResponse);
42+
});
43+
});

0 commit comments

Comments
 (0)