Skip to content

Commit

Permalink
fix(e2e): Runs email-link tests (#4873)
Browse files Browse the repository at this point in the history
  • Loading branch information
dstaley authored Jan 13, 2025
1 parent e465921 commit 196f141
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .changeset/lazy-mice-roll.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
13 changes: 12 additions & 1 deletion integration/testUtils/emailService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ type Message = {
subject: string;
};

interface ErrorResponse {
message: string;
error: string;
}

type InboxFilterResponse = { messages: Message[] } | ErrorResponse;

export const createEmailService = () => {
const cleanEmail = (email: string) => {
return email.replace(/\+.*@/, '@');
Expand All @@ -27,7 +34,11 @@ export const createEmailService = () => {
return runWithExponentialBackOff(
async () => {
const res = await fetcher(url);
const json = (await res.json()) as unknown as { messages: Message[] };
const json = (await res.json()) as InboxFilterResponse;
if ('message' in json) {
throw new Error(`Mailsac API Error: ${json.error} - ${json.message}`);
}

const message = json.messages[0];
if (!message) {
throw new Error('message not found');
Expand Down
8 changes: 4 additions & 4 deletions integration/tests/email-link.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import type { Application } from '../models/application';
import { appConfigs } from '../presets';
import { createTestUtils } from '../testUtils';

test.describe('sign up and sign in using email link', () => {
const configs = [];
test.describe('sign up and sign in using email link @generic', () => {
const configs = [appConfigs.next.appRouter, appConfigs.react.vite];

configs.forEach(config => {
test.describe(`${config.name}`, () => {
Expand Down Expand Up @@ -81,7 +81,7 @@ const performSignUpVerificationLinkSameDevice = async (
searchParams?: URLSearchParams,
) => {
const u = createTestUtils({ app, page, context });
const fakeUser = u.services.users.createFakeUser();
const fakeUser = u.services.users.createFakeUser({ fictionalEmail: false, withPassword: true });
await u.po.signUp.goTo({ searchParams });
await u.po.signUp.signUpWithEmailAndPassword({ email: fakeUser.email, password: fakeUser.password });
await u.po.signUp.waitForEmailVerificationScreen();
Expand All @@ -103,7 +103,7 @@ const performSignUpVerificationLinkDifferentDevice = async (
searchParams?: URLSearchParams,
) => {
const u = createTestUtils({ app, page, context, browser });
const fakeUser = u.services.users.createFakeUser();
const fakeUser = u.services.users.createFakeUser({ fictionalEmail: false, withPassword: true });
await u.po.signUp.goTo({ searchParams });
await u.po.signUp.signUpWithEmailAndPassword({ email: fakeUser.email, password: fakeUser.password });
await u.po.signUp.waitForEmailVerificationScreen();
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"test:integration:elements": "E2E_APP_ID=elements.* pnpm test:integration:base --grep @elements",
"test:integration:expo-web": "E2E_APP_ID=expo.expo-web pnpm test:integration:base --grep @expo-web",
"test:integration:express": "E2E_APP_ID=express.* pnpm test:integration:base --grep @express",
"test:integration:generic": "E2E_APP_ID=react.vite.*,next.appRouter.withEmailCodes* pnpm test:integration:base --grep @generic",
"test:integration:generic": "E2E_APP_ID=react.vite.*,next.appRouter.* pnpm test:integration:base --grep @generic",
"test:integration:nextjs": "E2E_APP_ID=next.appRouter.* pnpm test:integration:base --grep @nextjs",
"test:integration:nuxt": "E2E_APP_ID=nuxt.node npm run test:integration:base -- --grep @nuxt",
"test:integration:quickstart": "E2E_APP_ID=quickstart.* pnpm test:integration:base --grep @quickstart",
Expand Down
4 changes: 2 additions & 2 deletions turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@
},
"//#test:integration:generic": {
"dependsOn": ["@clerk/clerk-js#build", "@clerk/backend#build", "@clerk/clerk-react#build"],
"env": ["CLEANUP", "DEBUG", "E2E_*", "INTEGRATION_INSTANCE_KEYS"],
"env": ["CLEANUP", "DEBUG", "E2E_*", "INTEGRATION_INSTANCE_KEYS", "MAILSAC_API_KEY"],
"inputs": ["integration/**"],
"outputLogs": "new-only"
},
Expand All @@ -163,7 +163,7 @@
},
"//#test:integration:nextjs": {
"dependsOn": ["@clerk/clerk-js#build", "@clerk/backend#build", "@clerk/nextjs#build"],
"env": ["CLEANUP", "DEBUG", "E2E_*", "INTEGRATION_INSTANCE_KEYS"],
"env": ["CLEANUP", "DEBUG", "E2E_*", "INTEGRATION_INSTANCE_KEYS", "MAILSAC_API_KEY"],
"inputs": ["integration/**"],
"outputLogs": "new-only"
},
Expand Down

0 comments on commit 196f141

Please sign in to comment.