Skip to content
Snippets Groups Projects
Commit e89055fd authored by Yusuf Akgül's avatar Yusuf Akgül :hatching_chick:
Browse files

Merge branch 'testing' into 'main'

Testing

See merge request !34
parents c966816a 9fe220f7
No related branches found
No related tags found
1 merge request!34Testing
Pipeline #38858 passed
...@@ -3,12 +3,12 @@ ...@@ -3,12 +3,12 @@
# Public App URL # Public App URL
NEXT_PUBLIC_APP_URL="http://localhost:3000" NEXT_PUBLIC_APP_URL="http://localhost:3000"
# Database for connecting to Prisma # PostgreSQL Database for connecting to Prisma
DATABASE_URL="file:./dev.db" DATABASE_URL="postgresql://janedoe:mypassword@localhost:5432/mydb?schema=sample"
# Database for connecting to Supabase for media # Uploadthing Object Database for media storage
NEXT_PUBLIC_SUPABASE_URL="YOUR_SUPABASE_URL" UPLOADTHING_SECRET="uploadthing_secret"
NEXT_PUBLIC_SUPABASE_ANON_KEY="YOUR_SUPABASE_ANON_KEY" UPLOADTHING_APP_ID="uploadthing_app_id"
# URLs # URLs
TWITCH_AUTH_BASE_URL="https://id.twitch.tv/oauth2" TWITCH_AUTH_BASE_URL="https://id.twitch.tv/oauth2"
...@@ -16,12 +16,12 @@ IGDB_BASE_URL="https://api.igdb.com/v4" ...@@ -16,12 +16,12 @@ IGDB_BASE_URL="https://api.igdb.com/v4"
IGDB_IMG_BASE_URL="https://images.igdb.com/igdb/image/upload" IGDB_IMG_BASE_URL="https://images.igdb.com/igdb/image/upload"
# For Twitch Auth to fetch access token # For Twitch Auth to fetch access token
TWITCH_CLIENT_ID="imdb_client_id" TWITCH_CLIENT_ID="twitch_client_id"
TWITCH_CLIENT_SECRET="imdb_auth_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_URL="http://localhost:3000"
NEXTAUTH_SECRET="secret" NEXTAUTH_SECRET="nextauth_secret"
# For Github Auth # For Github Auth
GITHUB_CLIENT_ID="github_client_id" GITHUB_CLIENT_ID="github_client_id"
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
# testing # testing
/coverage /coverage
.swc
# next.js # next.js
/.next/ /.next/
......
// 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...
// });
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
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
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
...@@ -4,7 +4,6 @@ import { User } from "@prisma/client"; ...@@ -4,7 +4,6 @@ import { User } from "@prisma/client";
import { revalidatePath } from "next/cache"; import { revalidatePath } from "next/cache";
import { NextRequest, NextResponse } from "next/server"; import { NextRequest, NextResponse } from "next/server";
export async function PUT(req: NextRequest) { export async function PUT(req: NextRequest) {
const sessionUser = await getCurrentUser(); const sessionUser = await getCurrentUser();
......
...@@ -10,7 +10,7 @@ export const GweetActions = ({ ...@@ -10,7 +10,7 @@ export const GweetActions = ({
gweet: IGweet; gweet: IGweet;
}) => { }) => {
return ( return (
<div className="space-x-12 w-60"> <div className="space-x-12 w-64">
<CommentButton gweet={gweet} /> <CommentButton gweet={gweet} />
<RegweetButton gweet={gweet} /> <RegweetButton gweet={gweet} />
<LikeButton gweet={gweet} /> <LikeButton gweet={gweet} />
......
...@@ -36,7 +36,7 @@ export const GweetOptions = ({ gweet }: { gweet: IGweet }) => { ...@@ -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 ( return (
<DropdownMenu open={dropdownOpen} onOpenChange={setDropdownOpen}> <DropdownMenu open={dropdownOpen} onOpenChange={setDropdownOpen}>
......
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
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
// 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'; import '@testing-library/jest-dom/extend-expect';
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment