Add tests for updated getUserComments func
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
import { getUserComments } from './api';
|
||||
import { apiFetcher } from './fetcher';
|
||||
|
||||
describe('getUserComments', () => {
|
||||
it('should call apiFetcher.get with /comments endpoint and default skip and limit query params', () => {
|
||||
const apiFetcherSpy = jest.spyOn(apiFetcher, 'get');
|
||||
const userId = '1';
|
||||
|
||||
getUserComments(userId);
|
||||
expect(apiFetcherSpy).toHaveBeenCalledWith('/comments', {
|
||||
user: userId,
|
||||
skip: 0,
|
||||
limit: 10,
|
||||
});
|
||||
});
|
||||
|
||||
it('should call apiFetcher.get with /comments endpoint and provided query params', () => {
|
||||
const apiFetcherSpy = jest.spyOn(apiFetcher, 'get');
|
||||
const userId = '1';
|
||||
const config = {
|
||||
skip: 10,
|
||||
limit: 20,
|
||||
};
|
||||
|
||||
getUserComments(userId, config);
|
||||
expect(apiFetcherSpy).toHaveBeenCalledWith('/comments', {
|
||||
user: userId,
|
||||
...config,
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -13,7 +13,7 @@ export const getComment = (id: Comment['id']): Promise<Comment> => apiFetcher.ge
|
||||
|
||||
export const getUserComments = (
|
||||
userId: User['id'],
|
||||
config: { skip?: number; limit?: number } = { skip: 0, limit: 10 }
|
||||
config: { limit: number; skip?: number } = { limit: 10, skip: 0 }
|
||||
): Promise<{ comments: Comment[]; count: number }> => apiFetcher.get('/comments', { user: userId, ...config });
|
||||
|
||||
export const putCommentVote = ({ id, value }: { id: Comment['id']; value: number }): Promise<void> =>
|
||||
|
||||
Reference in New Issue
Block a user