# Add Missing Tests to Every Pull Request in an Express API

An agent reads each pull request to an Express API, writes Jest tests for the service branches it leaves untested, runs them, and posts a patch.

[Run this on Rush](https://cloud.getrush.ai/run/test-every-pull-request/express/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

The agent checks out the pull request and maps each changed handler in `src/app/routes/article/article.controller.ts` to the function behind it in `article.service.ts`. In gothinkster/node-express-realworld-example-app those run from `getArticles` and `getFeed` to `updateArticle`, `addComment` and `favoriteArticle`; it lists each new branch no test reaches, such as a filter in `getArticles` or an ownership check in `updateArticle`, with file and line.

New cases go into `src/tests/services/article.service.test.ts` in its own shape: one `describe` per service function, Given, When, Then comments, and the `prismaMock` from `src/tests/prisma-mock.ts`, a `mockDeep<PrismaClient>()` reset before every test. Rows are typed as `src/prisma/schema.prisma` defines them, and every promise under assertion is awaited.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "claude",
  "input": "Check out this pull request and diff it against its base branch. List the new or changed behavior in src/app/routes/article/ (the controller and article.service.ts) that no existing test covers, with file and line. Write Jest tests for each item in src/tests/services/article.service.test.ts, following the existing style: the prismaMock from src/tests/prisma-mock.ts, one describe per service function, Given/When/Then, assert on the returned value or the thrown HttpException status, and await every promise you assert on. Change no application code. Run npm test. Do not push commits or open a pull request. Post one review on the pull request listing each untested behavior with file and line, the tests you wrote, the Jest summary, any test that fails against the branch's code with its failing assertion, and the tests as a patch. If this run names no pull request, in resources or after this prompt, stop and say so.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app/pull/123"
    }
  ]
}
```

1. **Get an API key.** In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
2. **Send the request.** POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
3. **Read what came back.** Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

## What comes back

One review lands on the pull request: each untested service branch with its file and line, the Jest case written for it, the `npm test` summary, and a patch that changes `article.service.test.ts` only. No commit is pushed.

The reviewer decides whether to apply the patch, and, where a case fails against the branch, whether the service throws the wrong `HttpException` status or the case set up `prismaMock` for the wrong query.

## Run it on every pull request opened against master

An automation with this request as its prompt and a `github` trigger on `pull_request.opened` and `pull_request.synchronize`, `branch_patterns` `master`, the repository's default branch, reviews each new pull request and each push to one. Only an owner, member or collaborator fires it, and a fork's pull request never does. The event text carries the URL, title, author, labels, base branch and body but no SHAs, so the agent checks out the head from the URL. A pull request that only edits `src/prisma/schema.prisma` still starts a run, and the review finds no service behavior to test.

## Why run it on Rush?

Every service test here runs against a deep mock of Prisma, so a passing case proves only that the service made the calls the test expected. The agent asserts what the caller sees, the mapped article or the thrown status, and awaits each promise, so a rejected call fails the case instead of passing after the test returns.

## Frequently asked questions

### Why does it return the tests as a patch, not push them?

The review recipe posts and never pushes, so the branch stays the author's. Applying the patch from the review adds the cases, and `npm test`, which runs `nx test`, checks them on the author's machine or CI.

### Does it test the controller routes over HTTP?

No. The repository's existing tests call service functions directly with `prismaMock`, and the agent follows them rather than adding Supertest and a database.

## More Express jobs

- [Upgrade Express Dependencies Every Week](https://getrush.ai/run/upgrade-dependencies-weekly/express/)
- [Upgrade an Express App to Node 24](https://getrush.ai/run/upgrade-node-version/express/)
- [Write k6 Load Tests for an Express API](https://getrush.ai/run/write-load-tests/express/)

## The same job on other stacks

- [Add Missing Tests to Every Pull Request in a FastAPI App](https://getrush.ai/run/test-every-pull-request/fastapi/)
- [Add Missing Tests to Every Pull Request in a Flask App](https://getrush.ai/run/test-every-pull-request/flask/)
- [Add Missing Tests to Every Pull Request in a Go Service](https://getrush.ai/run/test-every-pull-request/go/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
