diff --git a/.env.example b/.env.example index 31a6eb736513e35d2f52eabc3c3dbc6c3fcdb6c4..ae1766776e592cce03e4e5d2884a4409ba5561f4 100644 --- a/.env.example +++ b/.env.example @@ -3,12 +3,12 @@ # Public App URL NEXT_PUBLIC_APP_URL="http://localhost:3000" -# Database for connecting to Prisma -DATABASE_URL="file:./dev.db" +# PostgreSQL Database for connecting to Prisma +DATABASE_URL="postgresql://janedoe:mypassword@localhost:5432/mydb?schema=sample" -# Database for connecting to Supabase for media -NEXT_PUBLIC_SUPABASE_URL="YOUR_SUPABASE_URL" -NEXT_PUBLIC_SUPABASE_ANON_KEY="YOUR_SUPABASE_ANON_KEY" +# Uploadthing Object Database for media storage +UPLOADTHING_SECRET="uploadthing_secret" +UPLOADTHING_APP_ID="uploadthing_app_id" # URLs TWITCH_AUTH_BASE_URL="https://id.twitch.tv/oauth2" @@ -16,12 +16,12 @@ IGDB_BASE_URL="https://api.igdb.com/v4" IGDB_IMG_BASE_URL="https://images.igdb.com/igdb/image/upload" # For Twitch Auth to fetch access token -TWITCH_CLIENT_ID="imdb_client_id" -TWITCH_CLIENT_SECRET="imdb_auth_id" +TWITCH_CLIENT_ID="twitch_client_id" +TWITCH_CLIENT_SECRET="twitch_client_secret" -# For NextAuth // use `openssl rand -base64 32` to generate a secret +# For NextAuth NEXTAUTH_URL="http://localhost:3000" -NEXTAUTH_SECRET="secret" +NEXTAUTH_SECRET="nextauth_secret" # For Github Auth GITHUB_CLIENT_ID="github_client_id" diff --git a/.gitignore b/.gitignore index 53ff3c9941de200c134e75edad8a26636c9c49da..1a46f3ae2670f8cddc55a9535d1dee45b50ed9b4 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,7 @@ # testing /coverage +.swc # next.js /.next/ diff --git a/__test__/api/favGamesListRoute.test.tsx b/__test__/api/favGamesListRoute.test.tsx deleted file mode 100644 index 7e4f1715aa12cdd7feb72ee2338091b547242b53..0000000000000000000000000000000000000000 --- a/__test__/api/favGamesListRoute.test.tsx +++ /dev/null @@ -1,57 +0,0 @@ -// import { getFavoriteGames, getGame, getGames } from "@/lib/igdb"; - -// // Mocken der Fetch-Funktion für die API-Aufrufe -// jest.mock('node-fetch'); - -// describe('Game Service', () => { -// test('fetches games from the server', async () => { -// // Mock-Daten der Spiele -// const mockGamesData = [ -// { -// id: 1, -// name: 'Game 1', -// cover: { -// image_id: 'cover_image_id_1', -// url: 'cover_image_url_1' -// }, -// // Weitere Eigenschaften der IGame-Schnittstelle -// }, -// { -// id: 2, -// name: 'Game 2', -// cover: { -// image_id: 'cover_image_id_2', -// url: 'cover_image_url_2' -// }, -// // Weitere Eigenschaften der IGame-Schnittstelle -// }, -// ]; - -// // Mock-Funktion für die Fetch-Funktion -// const mockFetch = jest.fn().mockResolvedValueOnce({ -// ok: true, -// json: async () => mockGamesData, -// }); - -// // Mocken der globalen fetch-Funktion -// // @ts-ignore -// global.fetch = mockFetch; - -// // Setzen der Umgebungsvariable IGDB_BASE_URL -// process.env.IGDB_BASE_URL = 'https://api.igdb.com/v4'; - -// // Aufruf der Funktion, die Spiele vom Server abruft -// const games = await getGames(); - -// // Überprüfen, ob die Fetch-Funktion mit den erwarteten Parametern aufgerufen wurde -// expect(mockFetch).toHaveBeenCalledWith('https://api.igdb.com/v4/games', { -// method: 'GET', -// // Weitere erwartete Optionen für den Fetch-Aufruf -// }); - -// // Überprüfen, ob die zurückgegebenen Spiele den erwarteten Daten entsprechen -// expect(games).toEqual(mockGamesData); -// }); - -// // Weitere Tests für getGame() und getFavoriteGames() hier... -// }); diff --git a/__test__/api/gamesRoute.test.tsx b/__test__/api/gamesRoute.test.tsx deleted file mode 100644 index 80aa671770b933e726ffe4e1c5062728b550265b..0000000000000000000000000000000000000000 --- a/__test__/api/gamesRoute.test.tsx +++ /dev/null @@ -1,57 +0,0 @@ -import { getFavoriteGames, getGame, getGames } from "@/lib/igdb"; - -// Mocken der Fetch-Funktion für die API-Aufrufe -jest.mock('node-fetch'); - -describe('Game Service', () => { - test('fetches games from the server', async () => { - // Mock-Daten der Spiele - const mockGamesData = [ - { - id: 1, - name: 'Game 1', - cover: { - image_id: 'cover_image_id_1', - url: 'cover_image_url_1' - }, - // Weitere Eigenschaften der IGame-Schnittstelle - }, - { - id: 2, - name: 'Game 2', - cover: { - image_id: 'cover_image_id_2', - url: 'cover_image_url_2' - }, - // Weitere Eigenschaften der IGame-Schnittstelle - }, - ]; - - // Mock-Funktion für die Fetch-Funktion - const mockFetch = jest.fn().mockResolvedValueOnce({ - ok: true, - json: async () => mockGamesData, - }); - - // Mocken der globalen fetch-Funktion - // @ts-ignore - global.fetch = mockFetch; - - // Setzen der Umgebungsvariable IGDB_BASE_URL - process.env.IGDB_BASE_URL = 'https://api.igdb.com/v4'; - - // Aufruf der Funktion, die Spiele vom Server abruft - const games = await getGames(); - - // Überprüfen, ob die Fetch-Funktion mit den erwarteten Parametern aufgerufen wurde - expect(mockFetch).toHaveBeenCalledWith('https://api.igdb.com/v4/games', { - method: 'GET', - // Weitere erwartete Optionen für den Fetch-Aufruf - }); - - // Überprüfen, ob die zurückgegebenen Spiele den erwarteten Daten entsprechen - expect(games).toEqual(mockGamesData); - }); - - // Weitere Tests für getGame() und getFavoriteGames() hier... -}); \ No newline at end of file diff --git a/__tests__/api/games.tsx b/__tests__/api/games.tsx new file mode 100644 index 0000000000000000000000000000000000000000..c05b3980a60c40932f20baad0fce26701c06c71d --- /dev/null +++ b/__tests__/api/games.tsx @@ -0,0 +1,49 @@ +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.tsx new file mode 100644 index 0000000000000000000000000000000000000000..2bdbf5e4f89949ca8e48a9e40df94267ab2e49d9 --- /dev/null +++ b/__tests__/api/gameslist.tsx @@ -0,0 +1,45 @@ +describe('games list 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 gameslist', async () => { + expect("test").toEqual("test"); + }); +}); \ No newline at end of file diff --git a/app/api/gamelists/route.ts b/app/api/gamelists/route.ts index fa9640edae83082c5d78b918a304dbb37eae900d..a107c731e62e375215366760fe024fa393471568 100644 --- a/app/api/gamelists/route.ts +++ b/app/api/gamelists/route.ts @@ -4,7 +4,6 @@ import { User } from "@prisma/client"; import { revalidatePath } from "next/cache"; import { NextRequest, NextResponse } from "next/server"; - export async function PUT(req: NextRequest) { const sessionUser = await getCurrentUser(); diff --git a/components/gweets/components/gweet-actions.tsx b/components/gweets/components/gweet-actions.tsx index 9011202799ca952df0d97d03f67c50ac86aff017..2fe4fd69c545e64432f29927b36095a328d4aa8d 100644 --- a/components/gweets/components/gweet-actions.tsx +++ b/components/gweets/components/gweet-actions.tsx @@ -10,7 +10,7 @@ export const GweetActions = ({ gweet: IGweet; }) => { return ( - <div className="space-x-12 w-60"> + <div className="space-x-12 w-64"> <CommentButton gweet={gweet} /> <RegweetButton gweet={gweet} /> <LikeButton gweet={gweet} /> diff --git a/components/gweets/components/gweet-options.tsx b/components/gweets/components/gweet-options.tsx index df18b1e70a017b2fcc5545cec9f2c1ae54d79877..2876d53f86bcca91d0765b7d2d1bc03c259a7685 100644 --- a/components/gweets/components/gweet-options.tsx +++ b/components/gweets/components/gweet-options.tsx @@ -36,7 +36,7 @@ export const GweetOptions = ({ gweet }: { gweet: IGweet }) => { } } - const url = getURL(`/status/${gweet?.id}`); + const url = getURL(`/${gweet?.author.username}/status/${gweet?.id}`); return ( <DropdownMenu open={dropdownOpen} onOpenChange={setDropdownOpen}> diff --git a/jest.config.js b/jest.config.js deleted file mode 100644 index e794dffd0abb8971f3bc1dc22e3d2a2e581d5a12..0000000000000000000000000000000000000000 --- a/jest.config.js +++ /dev/null @@ -1,19 +0,0 @@ -const nextJest = require('next/jest') - -const createJestConfig = nextJest({ - //Provide the path to your Next.js app to load next.config.js and .env in your test environment. - dir: '.', -}) - -// Add your custom config to be passed to Jest. -const customJestConfig = { - setupFilesAfterEnv: ['<rootDir>/jest.setup.js'], - moduleNameMapper: { - //Handle module aliases (this will be automatically configured for you soon) - '^@app/api/(.*)$': '<rootDir>/app/api/$1', - }, - testEnvironment: 'jest-environment-jsdom', -} - -// createJestConfig is exported this way to ensure that next/jest can load the Next.js config which is async. -module.exports = createJestConfig(customJestConfig) \ No newline at end of file diff --git a/jest.config.mjs b/jest.config.mjs new file mode 100644 index 0000000000000000000000000000000000000000..cd633c9ad7bf6fb7f1cb94145838a6ef058a73b3 --- /dev/null +++ b/jest.config.mjs @@ -0,0 +1,28 @@ +import nextJest from 'next/jest.js'; + +// Provide the path to your Next.js app to load next.config.js and .env files in your test environment +const createJestConfig = nextJest({ dir: './' }) + +// Custom client config to be passed to Jest. +const clientTestConfig = { + displayName: "client", + testPathIgnorePatterns: ["<rootDir>/node_modules/", "<rootDir>/__tests__/api/"], + setupFilesAfterEnv: ["<rootDir>/jest.setup.js"], + testEnvironment: "jest-environment-jsdom", +}; + +// Custom server config to be passed to Jest. +const serverTestConfig = { + displayName: "server", + testMatch: ["**/__tests__/api/**/*.[jt]s?(x)", "**/?(*.)+(spec|test).[jt]s?(x)"], + testEnvironment: "jest-environment-node", +}; + +// Add any custom config to be passed to Jest +/** @type {import('jest').Config} */ +const config = { + // Add more setup options before each test is run + projects: [await createJestConfig(clientTestConfig)(), await createJestConfig(serverTestConfig)()], +}; + +export default config; \ No newline at end of file diff --git a/jest.setup.js b/jest.setup.js index 666127af390a138ec802783a327366a743bb7188..306452c53e8f266c607181ec5d2720c5ebff224a 100644 --- a/jest.setup.js +++ b/jest.setup.js @@ -1 +1,6 @@ +// Optional: configure or set up a testing framework before each test. +// If you delete this file, remove `setupFilesAfterEnv` from `jest.config.js` + +// Used for __tests__/testing-library.js +// Learn more: https://github.com/testing-library/jest-dom import '@testing-library/jest-dom/extend-expect';