Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,42 @@ jobs:
node-version: 22
cache: npm
- run: npm ci
- run: npm run lint:check
- run: npm run test
- run: npm run build

e2e:
name: e2e
runs-on: ubuntu-latest
timeout-minutes: 10
services:
postgres:
image: postgres:18-alpine
env:
POSTGRES_USER: fleet
POSTGRES_PASSWORD: fleet
POSTGRES_DB: fleet
ports:
- 5432:5432
options: >-
--health-cmd "pg_isready -U fleet"
--health-interval 5s
--health-timeout 5s
--health-retries 10
env:
DB_HOST: localhost
DB_PORT: 5432
DB_USER: fleet
DB_PASSWORD: fleet
DB_NAME: fleet
JWT_SECRET: ci-only-secret
JWT_EXPIRES_IN: 1h
NODE_ENV: test
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
cache: npm
- run: npm ci
- run: npm run test:e2e
24 changes: 18 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ A NestJS and TypeORM backend for a fleet management app. Right now it handles ac

## What's in it

- **Sign-up** validates the body with class-validator (strong password rules, max 128 characters) and rejects a duplicate email with `409 Conflict`.
- **Sign-up** validates the body with class-validator (at least 8 characters with a lowercase letter, an uppercase letter, a number and a symbol, max 128) and rejects a duplicate email with `409 Conflict`.
- **Passwords** are hashed with Argon2id and never leave the database: the `passwordHash` column is excluded from queries by default.
- **Login** goes through a Passport local strategy and returns a signed JWT. Protected routes use a Passport JWT strategy behind a `JwtGuard`.
- **Errors** go through two global filters, one for HTTP exceptions and one that turns a PostgreSQL unique violation (`23505`) into a `409` instead of a `500`.
Expand All @@ -21,6 +21,7 @@ A NestJS and TypeORM backend for a fleet management app. Right now it handles ac
| Database | PostgreSQL 18 through TypeORM |
| Auth | Passport (local and JWT strategies), `@nestjs/jwt`, Argon2 |
| Validation | class-validator, global `ValidationPipe` with whitelisting |
| Testing | Vitest with SWC (for Nest's decorator metadata), Supertest |
| Local infra | Docker Compose for PostgreSQL |

## Getting started
Expand Down Expand Up @@ -52,11 +53,11 @@ A quick round trip:
```bash
curl -X POST http://localhost:3000/auth/register \
-H "Content-Type: application/json" \
-d '{"name":"Ana","email":"ana@example.com","password":"Secret123"}'
-d '{"name":"Ana","email":"ana@example.com","password":"Secret123!"}'

curl -X POST http://localhost:3000/auth/login \
-H "Content-Type: application/json" \
-d '{"email":"ana@example.com","password":"Secret123"}'
-d '{"email":"ana@example.com","password":"Secret123!"}'

curl http://localhost:3000/auth/profile -H "Authorization: Bearer <access_token>"
```
Expand All @@ -83,8 +84,19 @@ npm run build # compile to dist/
npm run start:prod # run the compiled build
npm run lint # ESLint with --fix
npm run test # unit tests
npm run test:e2e # end-to-end tests
npm run test:watch # unit tests in watch mode
npm run test:e2e # end-to-end tests, needs PostgreSQL running
```

> [!WARNING]
> The Jest suites don't run yet. `@nestjs/typeorm` 11 ships as ESM and uses `import.meta`, which the current Jest and ts-jest setup can't load, and the specs import with `src/...` paths that Jest doesn't map. CI only builds the project until that's fixed.
## Tests

Unit tests run with Vitest and mock the TypeORM repository and `JwtService`, so they don't need a database. They cover sign-up (duplicate email, Argon2 hashing, no hash in the response), login, the users service, the controllers and the password rules.

The end-to-end test boots the whole app against PostgreSQL and walks through register, login and `/auth/profile`, plus the `409` and `401` cases:

```bash
docker compose up -d
npm run test:e2e
```

CI runs lint, the unit tests and the build on every pull request, and the end-to-end test against a PostgreSQL service container.
1 change: 0 additions & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export default tseslint.config(
languageOptions: {
globals: {
...globals.node,
...globals.jest,
},
sourceType: 'commonjs',
parserOptions: {
Expand Down
Loading
Loading