Skip to content

Commit e69aabb

Browse files
test file : cover unsupported follow platform error (#93)
1 parent ffba46b commit e69aabb

1 file changed

Lines changed: 57 additions & 0 deletions

File tree

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import Fastify from 'fastify';
2+
import { describe, expect, it, vi } from 'vitest';
3+
4+
import { followRoutes } from '../routes/follow.js';
5+
6+
vi.mock('../utils/encryption.js', () => ({
7+
decrypt: vi.fn(() => 'fake-access-token'),
8+
}));
9+
10+
describe('POST /api/follow/:platform/:targetUsername', () => {
11+
it('returns 400 when API follow is not supported for the platform', async () => {
12+
const app = Fastify({ logger: false });
13+
14+
const findUnique = vi.fn().mockResolvedValue({
15+
id: 'token-1',
16+
userId: 'user-1',
17+
platform: 'unknown',
18+
accessToken: 'encrypted-token',
19+
});
20+
21+
app.decorate('prisma', {
22+
oAuthToken: {
23+
findUnique,
24+
},
25+
followLog: {
26+
create: vi.fn(),
27+
},
28+
}as any);
29+
30+
app.decorate('authenticate', async (request: any) => {
31+
request.user = { id: 'user-1' };
32+
});
33+
34+
await app.register(followRoutes, { prefix: '/api/follow' });
35+
await app.ready();
36+
37+
const response = await app.inject({
38+
method: 'POST',
39+
url: '/api/follow/unknown/targetUser',
40+
});
41+
42+
const body = response.json();
43+
44+
expect(response.statusCode).toBe(400);
45+
expect(body.error).toContain('API follow not supported');
46+
expect(findUnique).toHaveBeenCalledWith({
47+
where: {
48+
userId_platform: {
49+
userId: 'user-1',
50+
platform: 'unknown',
51+
},
52+
},
53+
});
54+
55+
await app.close();
56+
});
57+
});

0 commit comments

Comments
 (0)