diff --git a/__tests__/api/games.test.ts b/__tests__/api/games.test.ts new file mode 100644 index 0000000000000000000000000000000000000000..cddd2ec1bed07ebb514c85c4d80283c3d7cd1bea --- /dev/null +++ b/__tests__/api/games.test.ts @@ -0,0 +1,48 @@ +import { getGames } from "@/lib/igdb"; + +describe('games api', () => { + const mockGamesData = [ + { + id: 1, + name: 'Game 1', + cover: { + image_id: 'cover_image_id_1', + url: 'cover_image_url_1' + }, + }, + { + id: 2, + name: 'Game 2', + cover: { + image_id: 'cover_image_id_2', + url: 'cover_image_url_2' + }, + }, + ]; + + const mockAuthData = [ + { + access_token: "1", + expires_in: 420, + token_type: 'bearer', + } + ]; + + beforeAll(() => { + global.fetch = jest.fn() + .mockResolvedValueOnce({ + ok: true, + json: () => Promise.resolve(mockAuthData), + }) + .mockResolvedValueOnce({ + ok: true, + json: () => Promise.resolve(mockGamesData), + }); + }); + + test('get games', async () => { + const games = await getGames(); + + expect(games).toEqual(mockGamesData); + }); +}); diff --git a/__tests__/api/games.tsx b/__tests__/api/games.tsx deleted file mode 100644 index c05b3980a60c40932f20baad0fce26701c06c71d..0000000000000000000000000000000000000000 --- a/__tests__/api/games.tsx +++ /dev/null @@ -1,49 +0,0 @@ -import { getGames } from "@/lib/igdb"; - -describe('games api', () => { - - const mockGamesData = [ - { - id: 1, - name: 'Game 1', - cover: { - image_id: 'cover_image_id_1', - url: 'cover_image_url_1' - }, - }, - { - id: 2, - name: 'Game 2', - cover: { - image_id: 'cover_image_id_2', - url: 'cover_image_url_2' - }, - }, - ]; - - const mockAuthData = [ - { - access_token: "1", - expires_in: 420, - token_type: 'bearer', - } - ] - - beforeAll(async () => { - global.fetch = jest.fn() - .mockResolvedValueOnce(() => Promise.resolve({ - ok: true, - json: () => Promise.resolve(mockAuthData), - })) - .mockResolvedValueOnce(() => Promise.resolve({ - ok: true, - json: () => Promise.resolve(mockGamesData), - })) - }); - - test('get games', async () => { - const games = await getGames(); - - expect(games).toEqual("Game 1"); - }); -}); \ No newline at end of file diff --git a/__tests__/api/gameslist.tsx b/__tests__/api/gameslist.test.ts similarity index 100% rename from __tests__/api/gameslist.tsx rename to __tests__/api/gameslist.test.ts diff --git a/jest.config.mjs b/jest.config.mjs index cd633c9ad7bf6fb7f1cb94145838a6ef058a73b3..7079cf9e9cbc60a00b78c174d0027a0baabf3246 100644 --- a/jest.config.mjs +++ b/jest.config.mjs @@ -23,6 +23,11 @@ const serverTestConfig = { const config = { // Add more setup options before each test is run projects: [await createJestConfig(clientTestConfig)(), await createJestConfig(serverTestConfig)()], + collectCoverageFrom: [ + '**/app/api/**', + '!**/node_modules/**', + '!**/vendor/**', + ] }; export default config; \ No newline at end of file