forked from epicweb-dev/epic-stack
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
upgrade to v2 and add another test while we're at it
- Loading branch information
1 parent
de3e427
commit 474fd2f
Showing
24 changed files
with
1,492 additions
and
3,073 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/** | ||
* @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 setCookieParser from 'set-cookie-parser' | ||
import { test } from 'vitest' | ||
import { loader as rootLoader } from '#app/root.tsx' | ||
import { getSessionExpirationDate, sessionKey } 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, username: true, name: true }, | ||
data: { ...createUser(), image: { create: userImage } }, | ||
}) | ||
const App = createRemixStub([ | ||
{ | ||
path: '/users/:username', | ||
Component: UsernameRoute, | ||
loader, | ||
}, | ||
]) | ||
|
||
const routeUrl = `/users/${user.username}` | ||
render(<App initialEntries={[routeUrl]} />) | ||
|
||
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, username: true, name: 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) | ||
return loader(args) | ||
}, | ||
}, | ||
], | ||
}, | ||
]) | ||
|
||
const routeUrl = `/users/${user.username}` | ||
await render(<App initialEntries={[routeUrl]} />) | ||
|
||
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 }) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.