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