89 89. Step 15: Automated Testing and Troubleshooting
As of Oct 22, 2026 · Official docs: Jest
Automated tests help ensure everything works after changes.
89.1 Integration Tests
The project includes integration tests in tests/integration/. They talk to your real Supabase project and your Stripe sandbox: they create test users, tasks and payments there. Use a test project, not one with real users.
The test files end in .test.ts (for example 2_auth.test.ts). The test runner, Jest, runs only files whose names end that way.
89.2 Set Up Test Environment
In the project root (the
task-appfolder), copy the tests’ example settings file,.env.test.example, to a new file named.env.test.local:cp .env.test.example .env.test.localcpcopies the first file to the second. The tests read their settings from.env.test.localin the project root. Like.env.local, it is ignored by Git, so your keys stay off GitHub.Open
.env.test.localand fill in all six variables. Your worksheet’s Commands sheet has the six lines ready to paste; replace the file’s six placeholder lines with them and save the file. Paste keys only into the file, never into Claude’s chat.Variable Value NEXT_PUBLIC_SUPABASE_URLYour Supabase project URL NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEYYour Supabase publishable key ( sb_publishable_...)SUPABASE_SECRET_KEYYour Supabase secret key ( sb_secret_...)STRIPE_SECRET_KEYYour Stripe sandbox secret key ( sk_test_...)STRIPE_PRICE_IDYour price’s ID ( price_...)STRIPE_WEBHOOK_SECRETYour webhook’s signing secret ( whsec_...)The Supabase secret key is under Project Settings > API Keys (Secret keys) in the Supabase dashboard. It bypasses all of the database’s security rules, so the tests can create and delete test data, and so it goes only in this file, never in
.env.localor in aNEXT_PUBLIC_variable of the app.Keep the test settings separate from production credentials.
89.3 Run Tests
Run all tests:
npm testType it in VS Code’s terminal, in the task-app folder, and press Enter. npm test runs the project’s test script, which runs the tests with a testing tool named Jest.
Run one test file:
npm test tests/integration/2_auth.test.tsIf you see failures due to cold starts or timeouts:
- Run the tests again.
- Check that your Edge Functions are deployed and reachable.
89.4 Troubleshooting
A few quick checks for common problems.
89.4.1 Environment Variables Not Loading
- Verify the filenames:
- Local Next.js:
.env.local - Supabase:
supabase/.env(if applicable) and Supabase secrets.
- Local Next.js:
- Restart the dev server after any env changes.
- Confirm the variables are defined in:
- The Next.js runtime (
console.log(process.env.NEXT_PUBLIC_... )). - Supabase dashboard (for secrets).
- The Next.js runtime (
89.4.2 Authentication Errors
- In Google Cloud Console (the OAuth client), check that:
- The Authorized redirect URI is exactly your Supabase callback URL,
https://[your-project-ref].supabase.co/auth/v1/callback. - The Authorized JavaScript origins include
http://localhost:3000and, once the app is online, your Vercel address.
- The Authorized redirect URI is exactly your Supabase callback URL,
- In Supabase (Authentication > URL Configuration), check that:
- The Site URL is
http://localhost:3000while you work locally, and your Vercel address once the app is online. - The Redirect URLs include
http://localhost:3000/**and, once the app is online,https://YOUR-APP.vercel.app/**.
- The Site URL is
- Inspect the browser network tab for auth-related errors.
89.4.3 Edge Functions Failing
- Check that all required secrets are set (
OPENAI_API_KEY,STRIPE_SECRET_KEY,STRIPE_PRICE_ID,STRIPE_WEBHOOK_SECRET).npx supabase secrets listshows their names. - In Supabase:
- Open Edge Functions, click the function, and read its Logs to see runtime errors.
- An “Invalid JWT” (401) error, with none of the function’s own messages in its logs: one known fix is to turn off Verify JWT with legacy secret for that function (Edge Functions > the function > Details). This is safe here: the functions check the user’s login themselves.
- “No Supabase key found in SUPABASE_PUBLISHABLE_KEYS” (or
SUPABASE_SECRET_KEYS): Supabase gives the functions these keys automatically, so check Project Settings > API Keys in the dashboard. - Make sure code imports are correct and dependencies are installed.
89.4.4 Stripe Webhook Not Working
- Confirm that Verify JWT with legacy secret is off for
stripe-webhook(Edge Functions > stripe-webhook > Details). - Check that the Stripe event destination uses the Snapshot payload style and sends
checkout.session.completedandcustomer.subscription.deleted. - Double-check the webhook URL in Stripe:
- It must match the function URL exactly (including
https).
- It must match the function URL exactly (including
- Ensure the Signing secret in Supabase matches the current secret shown in Stripe.
- Buy a subscription with a test card, then read the
stripe-webhooklogs in Supabase (see Step 11).
89.4.5 Database Errors
- Ensure
npx supabase db pushran successfully without errors. - Check that RLS policies allow the operation you’re trying.
- Confirm that the user is authenticated when performing actions that require auth.
- Inspect Supabase logs or use the SQL editor to run queries manually.
Practice Questions
Easy
Question 1 · Short answer
What is an integration test, and what is its advantage over clicking through the app yourself after every change?
Question 2 · Write the command
Write the command that runs all of the project’s automated tests.
Question 3 · Multiple choice
Which file holds the environment variables for the Next.js app when you run it on your own computer?
.env.localpackage.json.gitignoreREADME.md
Question 4 · True or false
It’s fine to point the integration tests at your production Supabase project, the one that holds real users’ data.
Question 5 · Multiple choice
In .env.test.local, which variable holds your Supabase secret key (sb_secret_...)?
NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEYSUPABASE_SECRET_KEYNEXT_PUBLIC_SUPABASE_SECRET_KEYSTRIPE_SECRET_KEY
Medium
Question 6 · Write the command
The project contains the test file tests/integration/3_storage.test.ts. Following the pattern on this page, write the command that runs only this file.
Question 7 · Short answer
A test fails with a timeout the first time you run the tests, then passes when you run them again right away. What is a likely cause, and what does the page suggest?
Question 8 · Multiple choice
Your deployed edge functions need keys such as OPENAI_API_KEY. Where do they read these values from?
- The
supabase/.envfile on your laptop - The secrets stored in your Supabase project (set with
npx supabase secrets set ...) - The environment variables of your Vercel project
- The
.env.localfile
Question 9 · Matching
Match each symptom with the section of the troubleshooting checklist you would turn to first.
| Symptom | Checklist section | |
|---|---|---|
1. On the live site, after signing in with Google you land on localhost |
A. Database Errors | |
| 2. Saving data fails with an error that mentions a “row-level security policy” | B. Edge Functions Failing | |
| 3. Stripe test payments succeed, but nothing changes in your database | C. Environment Variables Not Loading | |
| 4. AI labels stopped appearing, and the function’s logs show errors | D. Authentication Errors | |
5. You added a new key to .env.local, but the app still behaves as if it isn’t there |
E. Stripe Webhook Not Working |
Question 10 · Short answer
An Edge Function’s logs show the error “No Supabase key found in SUPABASE_SECRET_KEYS”. Should you fix it with npx supabase secrets set? What do you check instead?
Hard
Question 11 · Scenario
You deleted your old Stripe webhook endpoint and created a new one with the correct URL. Stripe now delivers events to your stripe-webhook function, but the database is never updated, and the function’s logs show a signature-verification error. What’s wrong, and how do you fix it?
Question 12 · Scenario
Clicking “Sign in with Google” takes you to a Google error page that says Error 400: redirect_uri_mismatch. What is the most likely cause, and what exactly would you compare?
Question 13 · Scenario
Maria signs in and opens the dashboard, but her task list is empty. In the Supabase Table Editor you can see rows in the tasks table that belong to her. Using the “Database Errors” checklist, what two things would you check, and why might there be no error message at all?
Question 14 · Scenario
Maria creates a task, but no AI label appears. In the create-task-with-ai logs she finds an “Invalid JWT” (401) error, and none of the messages the function’s code prints. Which section of the troubleshooting checklist applies, what is one known fix, and why is it safe?