feat: add bootstrap script for API test fixtures and enhance live API tests

This commit is contained in:
2026-06-10 20:57:07 -07:00
parent b692affdc8
commit 11d80a6f32
5 changed files with 437 additions and 5 deletions

View File

@@ -13,10 +13,16 @@ Run repository tests without network dependencies:
pnpm test
```
Create or refresh writable live-test fixtures:
```bash
pnpm api:test:bootstrap
```
Run live smoke scenarios:
```bash
API_BASE_URL=https://cfw-auth.bowong.cc/api/auth pnpm test tests/auth-live-api.test.ts
pnpm api:test:live
```
Run OpenAPI contract checks:
@@ -41,6 +47,15 @@ API_BASE_URL=https://cfw-auth.bowong.cc/api/auth MAX_EXAMPLES=100 pnpm api:test:
- `ALLOW_AUTH_WRITE_TESTS=true`: enables Vitest scenarios that create authentication data.
- `MAX_EXAMPLES`, `TEST_SEED`, `REQUEST_TIMEOUT`, `SCHEMATHESIS_PHASES`, `SCHEMATHESIS_CHECKS`, `REPORT_DIR`: tune Schemathesis execution.
`pnpm api:test:bootstrap` writes `.api-test.env`, which is ignored by git. It contains generated passwords, session cookies, API keys, and fixture IDs for later live tests:
- `API_TEST_USER_ID`, `API_TEST_USER_EMAIL`, `API_TEST_SESSION_COOKIE`
- `API_TEST_ADMIN_ID`, `API_TEST_ADMIN_EMAIL`, `API_TEST_ADMIN_SESSION_COOKIE`
- `API_TEST_ORGANIZATION_ID`, `API_TEST_ORGANIZATION_SLUG`
- `API_TEST_API_KEY_ID`, `API_TEST_API_KEY`
The bootstrap script creates users through the public auth API, then uses Wrangler D1 access to mark only those namespaced test users as email-verified and to assign the test admin role. This keeps administrator bootstrap outside the public auth API.
## Coverage
OpenAPI automation covers static schema linting and schema-driven request/response checks. The default Schemathesis phases are `examples,coverage` to avoid broad fuzzing against production by accident.
@@ -52,6 +67,7 @@ Vitest live tests currently cover:
- anonymous `GET /get-session` behavior.
- invalid email sign-in rejection.
- optional namespaced email sign-up when write tests are explicitly enabled.
- bootstrapped user session, admin user lookup, organization listing, and API key listing when `.api-test.env` exists.
## Safety