Skip to content

Commit ab1015f

Browse files
authored
test(server): add comment api smoke coverage (#3661)
1 parent 83ad72b commit ab1015f

1 file changed

Lines changed: 23 additions & 2 deletions

File tree

packages/server/__tests__/token.spec.js

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ const main = require('../index.js');
2222
// Use a custom model stub so no real database connection is needed
2323
const handler = main({
2424
customModel: (modelName) => {
25+
if (modelName === 'Comment') {
26+
return {
27+
select: async () => [],
28+
count: async () => 0,
29+
};
30+
}
31+
2532
if (modelName === 'Users') {
2633
return {
2734
select: async () => [],
@@ -62,15 +69,29 @@ const apiRequest = (method, path, body) => {
6269
return fetch(url, options).then((r) => r.json());
6370
};
6471

65-
describe('gET /api/token', () => {
72+
describe('GET /api/token', () => {
6673
it('should return empty user info when not authenticated', async () => {
6774
const body = await apiRequest('GET', '/api/token');
6875
expect(body.errno).toBe(0);
6976
expect(body.data).toStrictEqual({});
7077
});
7178
});
7279

73-
describe('pOST /api/token', () => {
80+
describe('GET /api/comment', () => {
81+
it('should return an empty comment list for a running server', async () => {
82+
const body = await apiRequest('GET', '/api/comment?path=/unit-test');
83+
84+
expect(body.errno).toBe(0);
85+
expect(body.data).toMatchObject({
86+
page: 1,
87+
pageSize: 10,
88+
count: 0,
89+
data: [],
90+
});
91+
});
92+
});
93+
94+
describe('POST /api/token', () => {
7495
it('should return a validation error when email is missing', async () => {
7596
const body = await apiRequest('POST', '/api/token', { password: 'password123' });
7697
expect(body.errno).toBe(1001);

0 commit comments

Comments
 (0)