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

Merge branch 'testing' into 'main'

Testing

See merge request !33
parents 82a1dae3 d1c2af21
No related branches found
No related tags found
1 merge request!33Testing
Pipeline #38828 passed
// 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
......@@ -36,8 +36,6 @@ export default async function UserFollowers({ params }: { params: { userid: stri
}
}
})
console.log(fullUser?.id)
console.log(followers)
return (
<div>
......
......@@ -35,7 +35,7 @@ export default async function User({ params }: { params: { userid: string } }) {
})
if (!fullUser) {
redirect('/')
redirect('/home')
}
let favoritegames = undefined
......@@ -108,35 +108,35 @@ export default async function User({ params }: { params: { userid: string } }) {
</div >
<div className="main-content">
<Card className="w-full h-full overflow-hidden p-6 md:p-12" >
<h1 className="text-2xl font-bold pb-3">Your Favorite Games</h1>
<h1 className="text-2xl font-bold pb-3">Favorite Games</h1>
<div className="grid grid-cols-1 ss:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 2xl:grid-cols-5 gap-4 lg:gap-8 items-center">
{favoritegames ? favoritegames.map((game: IGame) => (
<GameItem id={game.id} name={game.name} cover={game.cover} key={game.id} />
))
:
<p>You have no favorites currently</p>}
<p>No favorites currently...</p>}
</div>
</Card>
<Card className="w-full h-full overflow-hidden p-6 md:p-12" >
<h1 className="text-2xl font-bold pb-3">Currently Playing</h1>
<h1 className="text-2xl font-bold pb-3">Currently playing</h1>
<div className="grid grid-cols-1 ss:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 2xl:grid-cols-5 gap-4 lg:gap-8 items-center">
{playingGames ? playingGames.map((game: IGame) => (
<GameItem id={game.id} name={game.name} cover={game.cover} key={game.id} />
))
:
<p>You are currently not playing any games</p>}
<p>Currently not playing any games...</p>}
</div>
</Card>
<Card className="w-full h-full overflow-hidden p-6 md:p-12" >
<h1 className="text-2xl font-bold pb-3">Planning on Playing</h1>
<h1 className="text-2xl font-bold pb-3">Planning to play</h1>
<div className="grid grid-cols-1 ss:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 2xl:grid-cols-5 gap-4 lg:gap-8 items-center">
{planningGames ? planningGames.map((game: IGame) => (
<GameItem id={game.id} name={game.name} cover={game.cover} key={game.id} />
))
:
<p>You are currently not planning on playing any games</p>}
<p>Currently not planning to play any games...</p>}
</div>
</Card>
......@@ -147,7 +147,7 @@ export default async function User({ params }: { params: { userid: string } }) {
<GameItem id={game.id} name={game.name} cover={game.cover} key={game.id} />
))
:
<p>You have no Games in your finished-Games-List </p>}
<p>No finished games...</p>}
</div>
</Card>
</div>
......
......@@ -19,7 +19,7 @@ export async function GET(req: NextRequest) {
}
});
} catch (error) {
console.log(error)
console.log("error", error)
}
return NextResponse.json({ status: 200, message: "fetched follows", follows })
......@@ -47,7 +47,7 @@ export async function PUT(req: NextRequest) {
followingId: data.followingId
}
});
console.log(follow)
console.log("follow", follow)
if (follow) {
// User is already following, so unfollow
......@@ -74,7 +74,7 @@ export async function PUT(req: NextRequest) {
}
} catch (error) {
console.log(error)
console.log("err", error)
}
const path = req.nextUrl.searchParams.get('path') || '/';
revalidatePath(path);
......
"use client"
// import { PrismaClient } from '@prisma/client';
import { startTransition, useEffect, useState } from 'react';
import { Follows, Prisma } from '@prisma/client';
import { useSession } from 'next-auth/react';
import { usePathname } from "next/navigation";
import { useEffect, useState } from 'react';
import { Button } from './ui/button';
import { Prisma, User, Follows } from '@prisma/client';
import { useRouter } from "next/navigation";
// 1: Define a type that includes the relation to `Post`
const userWithFollows = Prisma.validator<Prisma.UserArgs>()({
......@@ -24,7 +24,9 @@ export default function FollowButton({ user, followingId }: { user: UserWithFoll
const [isFollowing, setIsFollowing] = useState(false);
const [follows, setFollows] = useState([]);
const [buttonPressed, setButtonPress] = useState(false);
const router = useRouter();
const pathname = usePathname()
const { data: session } = useSession();
async function fetchFollows() {
......@@ -47,6 +49,8 @@ export default function FollowButton({ user, followingId }: { user: UserWithFoll
}
useEffect(() => {
fetchFollows()
// TODO: fix this warning
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [buttonPressed])
async function handleFollow(e: any) {
......@@ -60,11 +64,12 @@ export default function FollowButton({ user, followingId }: { user: UserWithFoll
setButtonPress(!buttonPressed)
}
console.log(isFollowing)
return (
<Button onClick={handleFollow}>
{isFollowing ? 'Unfollow' : 'Follow'}
</Button>
<>
{pathname !== `/${session?.user.username}` &&
<Button onClick={handleFollow}>
{isFollowing ? 'Unfollow' : 'Follow'}
</Button>}
</>
);
}
\ No newline at end of file
}
\ No newline at end of file
......@@ -11,6 +11,7 @@ import {
} from "@/components/ui/dropdown-menu";
import { toast } from "@/components/ui/use-toast";
import { env } from "@/env.mjs";
import getURL from "@/lib/utils";
import { useSession } from "next-auth/react";
import { useRef, useState } from "react";
import { IGweet } from "../types";
......@@ -35,7 +36,7 @@ export const GweetOptions = ({ gweet }: { gweet: IGweet }) => {
}
}
const url = `${env.NEXT_PUBLIC_APP_URL}/status/${gweet?.id}`;
const url = getURL(`/status/${gweet?.id}`);
return (
<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 '@testing-library/jest-dom/extend-expect';
......@@ -28,6 +28,7 @@ export function formatDate(data: number) {
})
}
// formats the time elapsed since creation
export function formatTimeElapsed(createdAt: Date) {
const now = dayjs();
const timeDiff = Math.abs(now.diff(dayjs(createdAt))); // Difference in milliseconds
......@@ -46,3 +47,12 @@ export function formatTimeElapsed(createdAt: Date) {
return seconds + 's'; // Show seconds if seconds have passed
}
}
// gets the current url for server or client
const IS_SERVER = typeof window === "undefined";
export default function getURL(path: string) {
const baseURL = IS_SERVER
? env.NEXT_PUBLIC_APP_URL!
: window.location.origin;
return new URL(path, baseURL).toString();
}
\ No newline at end of file
This diff is collapsed.
{
"name": "project_ss23_gameunity",
"version": "0.2.0",
"private": true,
"scripts": {
"dev": "next dev",
"turbo": "next dev --turbo",
"build": "next build",
"start": "next start",
"lint": "next lint",
"preview": "prisma generate && next build && next start",
"vercel-build": "prisma generate && prisma migrate deploy && next build"
},
"dependencies": {
"@auth/prisma-adapter": "^1.0.0",
"@hookform/resolvers": "^3.1.1",
"@prisma/client": "^4.16.1",
"@radix-ui/react-aspect-ratio": "^1.0.3",
"@radix-ui/react-avatar": "^1.0.3",
"@radix-ui/react-dialog": "^1.0.4",
"@radix-ui/react-dropdown-menu": "^2.0.5",
"@radix-ui/react-hover-card": "^1.0.6",
"@radix-ui/react-label": "^2.0.2",
"@radix-ui/react-scroll-area": "^1.0.4",
"@radix-ui/react-select": "^1.2.2",
"@radix-ui/react-separator": "^1.0.3",
"@radix-ui/react-slot": "^1.0.2",
"@radix-ui/react-toast": "^1.1.4",
"@t3-oss/env-nextjs": "^0.6.0",
"@tanstack/react-query": "^4.29.19",
"@uploadthing/react": "^5.1.0",
"bcrypt": "^5.1.0",
"class-variance-authority": "^0.6.1",
"clsx": "^1.2.1",
"dayjs": "^1.11.8",
"lucide-react": "^0.256.0",
"next": "^13.4.7",
"next-auth": "^4.22.1",
"next-themes": "^0.2.1",
"normalize-diacritics": "^4.0.0",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-dropzone": "^14.2.3",
"react-hook-form": "^7.45.1",
"react-infinite-scroll-component": "^6.1.0",
"react-intersection-observer": "^9.5.2",
"tailwind-merge": "^1.13.2",
"tailwindcss-animate": "^1.0.6",
"uploadthing": "^5.1.0",
"zod": "^3.21.4"
},
"devDependencies": {
"@tanstack/eslint-plugin-query": "^4.29.9",
"@types/bcrypt": "^5.0.0",
"@types/node": "^20.3.2",
"@types/react": "^18.2.14",
"@types/react-dom": "^18.2.6",
"autoprefixer": "10.4.14",
"eslint": "^8.43.0",
"eslint-config-next": "^13.4.7",
"postcss": "8.4.24",
"prisma": "^4.16.1",
"tailwindcss": "3.3.2",
"typescript": "^5.1.5"
}
}
"name": "project_ss23_gameunity",
"version": "0.2.0",
"private": true,
"scripts": {
"dev": "next dev",
"turbo": "next dev --turbo",
"build": "next build",
"start": "next start",
"lint": "next lint",
"preview": "prisma generate && next build && next start",
"vercel-build": "prisma generate && prisma migrate deploy && next build",
"test": "jest",
"coverage": "jest --coverage"
},
"dependencies": {
"@auth/prisma-adapter": "^1.0.0",
"@hookform/resolvers": "^3.1.1",
"@prisma/client": "^4.16.1",
"@radix-ui/react-aspect-ratio": "^1.0.3",
"@radix-ui/react-avatar": "^1.0.3",
"@radix-ui/react-dialog": "^1.0.4",
"@radix-ui/react-dropdown-menu": "^2.0.5",
"@radix-ui/react-hover-card": "^1.0.6",
"@radix-ui/react-label": "^2.0.2",
"@radix-ui/react-scroll-area": "^1.0.4",
"@radix-ui/react-select": "^1.2.2",
"@radix-ui/react-separator": "^1.0.3",
"@radix-ui/react-slot": "^1.0.2",
"@radix-ui/react-toast": "^1.1.4",
"@t3-oss/env-nextjs": "^0.6.0",
"@tanstack/react-query": "^4.29.19",
"@uploadthing/react": "^5.1.0",
"bcrypt": "^5.1.0",
"class-variance-authority": "^0.6.1",
"clsx": "^1.2.1",
"dayjs": "^1.11.8",
"lucide-react": "^0.256.0",
"next": "^13.4.7",
"next-auth": "^4.22.1",
"next-themes": "^0.2.1",
"normalize-diacritics": "^4.0.0",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-dropzone": "^14.2.3",
"react-hook-form": "^7.45.1",
"react-infinite-scroll-component": "^6.1.0",
"react-intersection-observer": "^9.5.2",
"tailwind-merge": "^1.13.2",
"tailwindcss-animate": "^1.0.6",
"uploadthing": "^5.1.0",
"zod": "^3.21.4"
},
"devDependencies": {
"@tanstack/eslint-plugin-query": "^4.29.9",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^14.0.0",
"@types/bcrypt": "^5.0.0",
"@types/jest": "^29.5.2",
"@types/node": "^20.3.2",
"@types/react": "^18.2.14",
"@types/react-dom": "^18.2.6",
"autoprefixer": "10.4.14",
"eslint": "^8.43.0",
"eslint-config-next": "^13.4.7",
"jest": "^29.5.0",
"jest-environment-jsdom": "^29.5.0",
"postcss": "8.4.24",
"prisma": "^4.16.1",
"tailwindcss": "3.3.2",
"typescript": "^5.1.6"
}
}
\ No newline at end of file
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