REST API built with Node.js, Express, and Prisma ORM featuring a full CRUD implementation for lessons, covered by both unit tests and end-to-end tests.
- Node.js + TypeScript
- Express
- Prisma ORM
- PostgreSQL
- Jest + Supertest
- Docker Compose
- ESLint
The project follows the Repository Pattern with Dependency Injection:
src/services/— Business logic (one class per use case)src/repositories/— Repository interface contractssrc/repositories/prisma/— Prisma implementationstest/repositories/— In-memory implementations for unit testsprisma/— Schema, migrations, and E2E test environment
| Method | Route | Description |
|---|---|---|
POST |
/lessons |
Create a lesson |
GET |
/lessons |
List all lessons |
GET |
/lessons/:id |
Get a lesson by ID |
PUT |
/lessons/:id |
Update a lesson |
DELETE |
/lessons/:id |
Delete a lesson |
POST /lessons
// Request body
{ "title": "Introduction to Node.js", "description": "Optional description" }
// Response 201
{ "id": "uuid", "title": "Introduction to Node.js", "description": "Optional description" }PUT /lessons/:id
// Request body
{ "title": "Updated title", "description": "Updated description" }
// Response 200
{ "id": "uuid", "title": "Updated title", "description": "Updated description" }- Node.js 18+
- Docker and Docker Compose
git clone https://github.com/luizcurti/node-e2e-tests.git
cd node-e2e-testsCreate a .env file at the project root:
DATABASE_USER=postgres
DATABASE_PASS=postgres
DATABASE_HOST=localhost
DATABASE_PORT=5432
DATABASE_NAME=lessons
DATABASE_URL=postgresql://postgres:postgres@localhost:5432/lessonsdocker compose up -dnpm installnpx prisma migrate deploy# Development
npm run dev
# Build
npm run build
# Production
npm start# Unit tests
npm test
# End-to-end tests (requires Docker running)
npm run test:e2e
# Lint
npm run lintEach service has its own spec file covering happy paths and error cases:
CreateLesson.spec.ts— title validation, trim whitespaceListLessons.spec.ts— empty list, multiple itemsGetLesson.spec.ts— found by ID, not foundUpdateLesson.spec.ts— update, trim, not found, empty titleDeleteLesson.spec.ts— delete, not found
The E2E environment (prisma/prisma-test-environment.ts) creates an isolated PostgreSQL schema for each test run and drops it automatically on teardown, ensuring test isolation without affecting the development database.