diff --git a/app/routes/users+/$username.test.tsx b/app/routes/users+/$username.test.tsx deleted file mode 100644 index fdc47b5d..00000000 --- a/app/routes/users+/$username.test.tsx +++ /dev/null @@ -1,99 +0,0 @@ -/** - * @vitest-environment jsdom - */ -import { faker } from '@faker-js/faker' -import { unstable_createRemixStub as createRemixStub } from '@remix-run/testing' -import { render, screen } from '@testing-library/react' -import * as setCookieParser from 'set-cookie-parser' -import { test } from 'vitest' -import { loader as rootLoader } from '#app/root.tsx' -import { sessionKey, getSessionExpirationDate } from '#app/utils/auth.server.ts' -import { prisma } from '#app/utils/db.server.ts' -import { sessionStorage } from '#app/utils/session.server.ts' -import { createUser, getUserImages } from '#tests/db-utils.ts' -import { default as UsernameRoute, loader } from './$username.tsx' - -test('The user profile when not logged in as self', async () => { - const userImages = await getUserImages() - const userImage = - userImages[faker.number.int({ min: 0, max: userImages.length - 1 })] - const user = await prisma.user.create({ - select: { id: true, name: true, username: true }, - data: { - ...createUser(), - image: { create: userImage }, - }, - }) - const App = createRemixStub([ - { - path: '/users/:username', - Component: UsernameRoute, - loader, - }, - ]) - - const routeUrl = `/users/${user.username}` - render() - - await screen.findByRole('heading', { level: 1, name: user.name! }) - await screen.findByRole('img', { name: user.name! }) - await screen.findByRole('link', { name: `${user.name}'s notes` }) -}) - -test('The user profile when logged in as self', async () => { - const userImages = await getUserImages() - const userImage = - userImages[faker.number.int({ min: 0, max: userImages.length - 1 })] - const user = await prisma.user.create({ - select: { id: true, name: true, username: true }, - data: { ...createUser(), image: { create: userImage } }, - }) - const session = await prisma.session.create({ - select: { id: true }, - data: { - expirationDate: getSessionExpirationDate(), - userId: user.id, - }, - }) - - const cookieSession = await sessionStorage.getSession() - cookieSession.set(sessionKey, session.id) - const setCookieHeader = await sessionStorage.commitSession(cookieSession) - const parsedCookie = setCookieParser.parseString(setCookieHeader) - const cookieHeader = new URLSearchParams({ - [parsedCookie.name]: parsedCookie.value, - }).toString() - - const App = createRemixStub([ - { - id: 'root', - path: '/', - loader: async args => { - // add the cookie header to the request - args.request.headers.set('cookie', cookieHeader) - return rootLoader(args) - }, - children: [ - { - path: 'users/:username', - Component: UsernameRoute, - loader: async args => { - // add the cookie header to the request - args.request.headers.set('cookie', cookieHeader) - // @ts-expect-error this will be fixed in Remix v2 - return loader(args) - }, - }, - ], - }, - ]) - - const routeUrl = `/users/${user.username}` - render() - - await screen.findByRole('heading', { level: 1, name: user.name! }) - await screen.findByRole('img', { name: user.name! }) - await screen.findByRole('button', { name: /logout/i }) - await screen.findByRole('link', { name: /my notes/i }) - await screen.findByRole('link', { name: /edit profile/i }) -})