# Add Missing Tests to Every Pull Request in a NestJS API

An agent finds what a NestJS pull request leaves untested in auth and users, writes Jest unit and e2e specs, runs both suites, and reviews with a patch.

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

## What the agent does

The agent maps the diff onto `src/auth/auth.service.ts`, `src/auth/auth.controller.ts` and `src/users/users.service.ts`, and lists which methods it changes, such as `validateLogin` or `register`, and which new branch nothing tests yet.

brocoders/nestjs-boilerplate tests in two places. `npm test` runs Jest with `rootDir` `src` and matches `*.spec.ts`, though no unit spec ships there; the real tests are `test/admin/auth.e2e-spec.ts`, `test/admin/users.e2e-spec.ts` and `test/user/auth.e2e-spec.ts`, which `npm run test:e2e` runs with `test/jest-e2e.json` through supertest, logging in as the admin in `test/utils/constants.ts`. Service logic gets a spec beside its source built with `Test.createTestingModule`; HTTP behavior gets new `it` cases in the e2e files, run against the stack `docker-compose.relational.test.yaml` starts.

## Start it with one API call

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

```json
{
  "agent": "claude",
  "input": "Review this pull request for untested behavior. Check it out and read its diff against the base branch. List each new or changed behavior in src/auth and src/users that no existing test covers. For service logic, write Jest unit specs next to the source (for example src/auth/auth.service.spec.ts) with Test.createTestingModule from @nestjs/testing and test doubles for the injected services, and run npm test. For behavior visible over HTTP, add cases to the existing specs in test/admin and test/user in their style (supertest against APP_URL, the admin login from test/utils/constants.ts), start the relational stack with env-example-relational, and run npm run test:e2e. If the stack cannot start, say which e2e cases were written but not run. Do not change application code: if a test fails because the code is wrong, keep it out of the patch and describe the failure. Do not push commits, commit to the branch or open a pull request. Post one review on the pull request that lists each untested behavior with file and line, each test you wrote, which command ran each test and its result, and the new tests as one 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 on the pull request: each untested behavior with file and line in `src/auth/` or `src/users/`, the specs that cover it, and which command ran each, `npm test` or `npm run test:e2e`. If the relational stack could not start, the review says which e2e cases were written but not run. The patch adds `*.spec.ts` files and e2e cases only; nothing is pushed.

A reviewer decides whether to apply it, and whether a failing expectation the agent reported, such as a login accepted for an inactive user, is a bug in `auth.service.ts`.

## Run it on every pull request opened against main

An automation with this request as its prompt and a `github` trigger on `pull_request.opened` and `pull_request.synchronize`, `branch_patterns` `main`, starts a review per pull request and per push to it. Owners, members and collaborators fire it; forks never do. The event text carries the pull request URL and base branch but no SHAs, so the agent resolves the head commit from the URL, then runs both Jest configs against it.

## Why run it on Rush?

A unit spec here proves a service method with doubles in place of `UsersService` and `MailService`; only the e2e specs prove the HTTP contract against Postgres. The review labels which level each test ran at, so a reviewer can tell a behavior proven end to end from one proven only with doubles, which a green check alone hides.

## Frequently asked questions

### Why add unit specs when the repository only has e2e tests?

The Jest config in `package.json` already matches `*.spec.ts` under `src`, so a spec beside `auth.service.ts` runs under `npm test` with no setup, and it reaches branches an HTTP call cannot reach cheaply.

### Why does the patch not land on the branch?

The review recipe tells the agent not to push. The patch applies with `git apply`, and the new e2e cases sit inside the existing `describe` blocks, so the author reviews a small diff.

## More NestJS jobs

- [Upgrade NestJS Dependencies Every Week](https://getrush.ai/run/upgrade-dependencies-weekly/nestjs/)
- [Upgrade a NestJS App to Node 24](https://getrush.ai/run/upgrade-node-version/nestjs/)
- [Write API Integration Tests for a NestJS App](https://getrush.ai/run/write-api-tests/nestjs/)

## The same job on other stacks

- [Add Missing Tests to Every Pull Request in a Next.js App](https://getrush.ai/run/test-every-pull-request/nextjs/)
- [Add Missing Tests to Every Pull Request in a Nuxt App](https://getrush.ai/run/test-every-pull-request/nuxt/)
- [Add Missing Tests to Every Pull Request in a Phoenix App](https://getrush.ai/run/test-every-pull-request/phoenix/)

## 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/)
