Add tests for updated getUserComments func

This commit is contained in:
esvyridov
2021-12-23 17:44:45 -06:00
committed by Umputun
parent cd391a8b0e
commit 0bf5a91091
2 changed files with 32 additions and 1 deletions
+31
View File
@@ -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,
});
});
});
+1 -1
View File
@@ -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> =>