+22
-43
@@ -1,56 +1,35 @@
|
||||
# Testing
|
||||
|
||||
## Running Tests
|
||||
|
||||
```bash
|
||||
# All unit tests
|
||||
pnpm test
|
||||
|
||||
# E2E tests
|
||||
pnpm test:e2e
|
||||
|
||||
# Specific test file
|
||||
cd apps/api
|
||||
npx jest --testPathPattern="auth.service.spec.ts"
|
||||
pnpm test # every package's unit tests
|
||||
pnpm test:e2e # the API against a real database
|
||||
```
|
||||
|
||||
## Test Structure
|
||||
## Unit tests
|
||||
|
||||
### Unit Tests
|
||||
Located in `apps/api/src/` alongside source files with `.spec.ts` suffix.
|
||||
- Authentication service tests
|
||||
- Device token generation and validation
|
||||
- Command creation and acknowledgement
|
||||
- Venue isolation enforcement
|
||||
- Rate limiting
|
||||
- `apps/api/src/**/*.spec.ts` (Jest): the rules in `ledger/` (tabs, drinks, settling, stock, product merges), event
|
||||
parsing, the app version gate, consistency checks, email templates and image processing. Pure, no database.
|
||||
- `apps/dashboard/src/**/*.test.ts` (Vitest): the customer import, amount parsing, and that every translation key the
|
||||
dashboard uses exists in English and Dutch.
|
||||
|
||||
### Integration/E2E Tests
|
||||
Located in `apps/api/test/` with `.e2e-spec.ts` suffix.
|
||||
- Login flow
|
||||
- Device registration and sync
|
||||
- Command lifecycle (create → sync → ack)
|
||||
- Device revocation
|
||||
- Cross-venue access prevention
|
||||
## End-to-end tests
|
||||
|
||||
## Writing Tests
|
||||
`apps/api/test/api.e2e-spec.ts` starts the whole API against the database in `DATABASE_URL` (migrated, and
|
||||
**wiped** by the test) and plays a terminal and the dashboard together: pairing, syncing events once, settling on a
|
||||
terminal and on the dashboard, customers getting tabs, stock movements, unpairing, venue access, and the superadmin
|
||||
page.
|
||||
|
||||
```typescript
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { AuthService } from './auth.service';
|
||||
Locally, `docker compose up -d` creates a `kooltap_test` database too:
|
||||
|
||||
describe('AuthService', () => {
|
||||
let service: AuthService;
|
||||
```bash
|
||||
cd apps/api
|
||||
DATABASE_URL=postgresql://kooltap:kooltap@localhost:5432/kooltap_test npx prisma migrate deploy
|
||||
DATABASE_URL=postgresql://kooltap:kooltap@localhost:5432/kooltap_test pnpm test:e2e
|
||||
```
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [AuthService, /* mocks */],
|
||||
}).compile();
|
||||
CI runs both, checks that the Prisma schema matches the migrations, builds everything and exports the terminal
|
||||
protocol's JSON Schema.
|
||||
|
||||
service = module.get<AuthService>(AuthService);
|
||||
});
|
||||
## By hand
|
||||
|
||||
it('should generate valid device tokens', () => {
|
||||
// ...
|
||||
});
|
||||
});
|
||||
```
|
||||
`pnpm simulate` is a terminal on the command line: open tabs, ring up drinks and settle, and watch the dashboard follow.
|
||||
|
||||
Reference in New Issue
Block a user