test: wire jest harness for QA gate (S1-f)

Add jest + ts-jest to the NestJS backend with an app.service smoke spec that
exercises Nest DI. `npm test` is the documented command the QA gate runs.

Trace: SRS §6 gate, NFR-8.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Brent Perteet
2026-08-20 12:53:36 -05:00
parent 9eefe50401
commit daa3407b9d
4 changed files with 3337 additions and 240 deletions

16
backend/jest.config.js Normal file
View File

@@ -0,0 +1,16 @@
/**
* Jest config for the UlHub backend (NestJS).
* ts-jest transpiles the TypeScript sources; decorators/metadata are honored via tsconfig.
* Specs live next to sources as *.spec.ts (unit) — e2e would go under test/ with a separate config.
*/
module.exports = {
moduleFileExtensions: ['js', 'json', 'ts'],
rootDir: 'src',
testRegex: '.*\\.spec\\.ts$',
transform: {
'^.+\\.ts$': ['ts-jest', { tsconfig: '<rootDir>/../tsconfig.json' }],
},
collectCoverageFrom: ['**/*.(t|j)s'],
coverageDirectory: '../coverage',
testEnvironment: 'node',
};

3527
backend/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -8,7 +8,9 @@
"build": "nest build", "build": "nest build",
"format": "prettier --write \"src/**/*.ts\"", "format": "prettier --write \"src/**/*.ts\"",
"postinstall": "prisma generate", "postinstall": "prisma generate",
"db:seed": "ts-node prisma/seed.ts" "db:seed": "ts-node prisma/seed.ts",
"test": "jest",
"test:ci": "jest --ci --runInBand"
}, },
"prisma": { "prisma": {
"seed": "ts-node prisma/seed.ts" "seed": "ts-node prisma/seed.ts"
@@ -44,9 +46,12 @@
"@types/cookie-parser": "^1.4.7", "@types/cookie-parser": "^1.4.7",
"@types/express": "^4.17.17", "@types/express": "^4.17.17",
"@types/node": "^20.11.0", "@types/node": "^20.11.0",
"@types/jest": "^29.5.12",
"@types/passport-jwt": "^4.0.1", "@types/passport-jwt": "^4.0.1",
"@types/ws": "^8.5.10", "@types/ws": "^8.5.10",
"jest": "^29.7.0",
"prettier": "^3.0.0", "prettier": "^3.0.0",
"ts-jest": "^29.2.5",
"prisma": "^6.10.0", "prisma": "^6.10.0",
"ts-node": "^10.9.1", "ts-node": "^10.9.1",
"typescript": "^5.5.0" "typescript": "^5.5.0"

View File

@@ -0,0 +1,27 @@
import { Test, TestingModule } from '@nestjs/testing';
import { AppService } from './app.service';
// Smoke test for the QA gate (S1-f, trace: SRS §6 gate / NFR-8).
// Exercises Nest DI wiring end-to-end for a pure service so a green run proves the
// toolchain (ts-jest + @nestjs/testing) is functional. Real coverage grows from here.
describe('AppService (smoke)', () => {
let service: AppService;
beforeEach(async () => {
const moduleRef: TestingModule = await Test.createTestingModule({
providers: [AppService],
}).compile();
service = moduleRef.get<AppService>(AppService);
});
it('is resolvable from the DI container', () => {
expect(service).toBeDefined();
});
it('returns the API welcome payload', () => {
expect(service.getHello()).toEqual({
message: 'Welcome to UlHub API',
docs: 'GET /api',
});
});
});