Logins, test data and payments
How Testis signs in to apps with accounts and roles, keeps your data safe, and handles checkouts, without you configuring any of it by hand.
Real apps have sign-in pages, an admin area that nobody can register for, and checkouts. Testis reads your project when you run testis init, so you do not have to explain these things. Run testis inspect at any time to see what it found. It changes nothing.
What Testis works out by itself#
- How to start the app and where it listens. From your scripts, workspaces and dev-server settings, including a client and a server started together.
- The sign-in page and which accounts exist. Test logins are found by name in your
.envor.env.example: a pair likeADMIN_EMAILandADMIN_PASSWORDbecomes theadminaccount,CUSTOMER_EMAILandCUSTOMER_PASSWORDbecomescustomer. Mail and database credentials (SMTP_USER,DB_PASSWORD) are ignored. When there are none, the setup page also looks at the script that fills your development database (for exampleprisma/seed.ts): a user it creates with a plain-text password ({ email: 'admin@example.com', password: 'admin123', role: 'ADMIN' }) is offered as a login. The page shows the e-mail and where it was found, never the password; when you save, the password goes into.testis/secrets.env(git-ignored), never into the config. - A reset route, if your app has one made for tests (for example
POST /__test/reset). - Whether your database is local and whether payments are in test mode.
The config it writes holds only variable names. Passwords stay in your .env and never reach the repo, the logs or the AI.
Accounts and roles#
Testis signs in once per run for each account, through your real sign-in form, and saves the browser session in .testis/cache/ (ignored by git). Every test then starts already signed in. There is no login to repeat, and the AI never types a password.
targets:
- kind: web
baseUrl: http://localhost:3000
auth:
loginPath: /login
default: customer
accounts:
customer: { email: "{{CUSTOMER_EMAIL}}", password: "{{CUSTOMER_PASSWORD}}" }
admin: { email: "{{ADMIN_EMAIL}}", password: "{{ADMIN_PASSWORD}}" }
environments:
local:
secretRefs:
CUSTOMER_EMAIL: MYAPP_CUSTOMER_EMAIL
CUSTOMER_PASSWORD: MYAPP_CUSTOMER_PASSWORD
ADMIN_EMAIL: MYAPP_ADMIN_EMAIL
ADMIN_PASSWORD: MYAPP_ADMIN_PASSWORD
- A test runs as the account in
setup.account, or the default. The default is an ordinary person, never the admin.account: noneruns signed out. - While exploring, Testis visits your pages as every account, so it knows which pages only an admin can open. The planner then writes admin cases that run as the admin, and checks that a customer cannot open them.
- If a sign-in fails, Testis says what the app answered and what to check (usually that the account is seeded in the local database).
There is no registration step for admin accounts: seed them into your local database, put their login in .env, and Testis does the rest.
Test data#
Tests create and change data, so Testis protects you before it touches anything:
- It will not run against a database that is not on this machine. If your
.envpoints at a hosted database (Neon, Supabase, RDS, MongoDB Atlas, or any public host), Testis stops and tells you which setting. Use a local database (a SQLite file, or Postgres in Docker) for testing. OnlyallowRemoteData: trueoverrides this, for a throwaway database you own. - A reset route puts the data back to its seeded state before each test, so tests start from the same place every time. It only runs against an app on this machine. An app that keeps its data in memory can use
reset: { restart: true }instead: Testis starts it again before each test. - A login's
passwordcan be left out: it defaults to{{<NAME>_PASSWORD}}(forcustomer,{{CUSTOMER_PASSWORD}}). - Deployed apps are different: they have no dev server for Testis to start, and you choose the environment explicitly with
-e. Mark productionreadOnly: trueso nothing can change it.
Checkouts and payments#
- Test mode only. If your project defines a sandbox card (for example
TEST_CARD) or uses test keys (sk_test_...), Testis setspurchases: sandbox. The planner then includes checkout cases and pays with that card. - Live keys stop the run. A live key such as
sk_live_...anywhere in the settings your app loads blocks Testis completely, and that cannot be overridden. - Unknown means no. If a payment provider is in use but nothing says it is in test mode, Testis does not press buy and pay buttons, and tells you why.
Troubleshooting#
- "Could not sign in as admin": the account is not in your local database yet. Run your seed script, or let the reset route do it.
- "Testis stopped before touching your app": read the line it prints. It names the file and the setting.
- The app does not start: Testis prints the last lines of its output and a plain-words guess (a Node version mismatch, a busy port, a missing install). See Troubleshooting.
Something unclear or wrong? Write to hello@testis.dev.