Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
lukevella committed Feb 12, 2025
1 parent 3c959eb commit 30f6d0d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
1 change: 1 addition & 0 deletions apps/web/.env.test
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
PORT=3002
NEXT_PUBLIC_BASE_URL=http://localhost:3002
AUTH_URL=http://localhost:3002
SECRET_PASSWORD=abcdef1234567890abcdef1234567890
DATABASE_URL=postgres://postgres:postgres@localhost:5450/rallly
SUPPORT_EMAIL=[email protected]
Expand Down
1 change: 1 addition & 0 deletions apps/web/src/auth/legacy/next-auth-cookie-migration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export function withAuthMigration(
res.cookies.set(newCookieName, encodedCookie, {
httpOnly: true,
secure: isSecureCookie,
expires: new Date(Date.now() + 1000 * 60 * 60 * 24 * 7),
sameSite: "lax",
path: "/",
});
Expand Down
3 changes: 1 addition & 2 deletions apps/web/tests/helpers/next-auth-v4.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import hkdf from "@panva/hkdf";
import { nanoid } from "@rallly/utils/nanoid";
import { EncryptJWT } from "jose";
import type { JWT } from "next-auth/jwt";

Expand Down Expand Up @@ -32,6 +31,6 @@ export async function encode(params: JWTEncodeParams) {
.setProtectedHeader({ alg: "dir", enc: "A256GCM" })
.setIssuedAt()
.setExpirationTime(now() + maxAge)
.setJti(nanoid())
.setJti("some-random-id")
.encrypt(encryptionSecret);
}
17 changes: 10 additions & 7 deletions apps/web/tests/next-auth-migration.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { expect, test } from "@playwright/test";
import { prisma } from "@rallly/database";
import { nanoid } from "@rallly/utils/nanoid";

import { encode } from "./helpers/next-auth-v4";

Expand All @@ -12,8 +11,8 @@ test.describe.serial(() => {
data: {
id: "legacy-guest-poll",
title: "Test Poll",
adminUrlId: nanoid(),
participantUrlId: nanoid(),
adminUrlId: "admin-url-id",
participantUrlId: "participant-url-id",
guestId: legacyGuestId,
},
});
Expand All @@ -28,7 +27,7 @@ test.describe.serial(() => {

test("should see poll on login page", async ({ page }) => {
const context = page.context();
const token = await encode({
const legacyToken = await encode({
token: {
sub: legacyGuestId,
},
Expand All @@ -39,15 +38,19 @@ test.describe.serial(() => {
await context.addCookies([
{
name: "next-auth.session-token",
value: token,
value: legacyToken,
httpOnly: true,
expires: Date.now() / 1000 + 60 * 60 * 24 * 7,
secure: false,
sameSite: "Lax",
path: "/",
domain: "localhost",
path: "/",
},
]);
await page.goto("/login");

await page.goto("/");

// Check if the poll title exists in the page content
await expect(page.getByText("Test Poll")).toBeVisible();
});
});

0 comments on commit 30f6d0d

Please sign in to comment.