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
484 changes: 484 additions & 0 deletions .github/workflows/comprehensive-testing.yml

Large diffs are not rendered by default.

29 changes: 27 additions & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,29 @@ module.exports = {
'^.+\\.(t|j)s$': 'ts-jest',
},
collectCoverageFrom: [
'test/**/*.(t|j)s',
'src/**/*.(t|j)s',
'!src/**/*.interface.ts',
'!src/**/*.dto.ts',
'!src/**/*.config.ts',
'!src/**/*.module.ts',
'!src/main.ts',
'!src/**/*.mock.ts',
],
coverageDirectory: 'coverage',
coverageReporters: [
'text',
'lcov',
'html',
'json',
],
coverageThreshold: {
global: {
branches: 30,
functions: 35,
lines: 35,
statements: 35
},
},
testEnvironment: 'node',
roots: ['<rootDir>/test/'],
moduleNameMapper: {
Expand All @@ -18,9 +38,14 @@ module.exports = {
'/node_modules/',
'/dist/',
'/test/database/',
'integration.spec.ts',
'e2e-spec.ts',
'error_consistency.spec.ts',
'api-keys.pagination.spec.ts',
],
setupFilesAfterEnv: ['<rootDir>/test/setup.ts'],
testTimeout: 30000,
verbose: true,
detectOpenHandles: true,
forceExit: true,
maxWorkers: '50%',
};
21 changes: 15 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,24 @@
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"test": "jest --config ./jest.config.js",
"test:watch": "jest --config ./jest.config.js --watch",
"test:cov": "jest --config ./jest.config.js --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --config ./jest.config.js --runInBand",
"test:e2e": "jest --config ./test/jest-e2e.json",
"test:unit": "jest --config ./jest.config.js --testPathPattern=spec",
"test:integration": "jest --config ./jest.config.js --testPathPattern=integration --passWithNoTests",
"test:cov": "jest --config ./jest.config.js --coverage --coverageReporters=text --coverageReporters=html --coverageReporters=lcov",
"test:unit": "jest --config ./jest.config.js --testPathPattern=spec --coverageThreshold='{\"global\":{\"branches\":35,\"functions\":35,\"lines\":35,\"statements\":35}}'",
"test:integration": "jest --config ./jest.config.js --testPathPattern=integration --passWithNoTests --coverageThreshold='{\"global\":{\"branches\":80,\"functions\":80,\"lines\":80,\"statements\":80}}'",
"test:e2e": "jest --config ./jest.config.js --testPathPattern=e2e --passWithNoTests",
"test:performance": "jest --config ./jest.config.js --testPathPattern=performance --passWithNoTests",
"test:security": "jest --config ./jest.config.js --testPathPattern=security --passWithNoTests",
"test:load": "jest --config ./jest.config.js --testPathPattern=load --passWithNoTests",
"test:contracts": "jest --config ./jest.config.js --testPathPattern=contracts",
"test:all": "npm run test:unit && npm run test:integration && npm run test:e2e",
"test:all": "npm run test:unit && npm run test:integration && npm run test:e2e && npm run test:security",
"test:ci": "jest --config ./jest.config.js --coverage --ci --reporters=default --reporters=jest-junit --watchAll=false",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --config ./jest.config.js --runInBand",
"test:clear": "jest --clearCache",
"test:update-snapshots": "jest --config ./jest.config.js --updateSnapshot",
"test:coverage:report": "jest --config ./jest.config.js --coverage --coverageReporters=text --coverageReporters=html --coverageReporters=cobertura",
"test:coverage:badge": "jest --config ./jest.config.js --coverage --coverageReporters=text-summary | grep 'All files' | cut -d' ' -f2 | cut -d'%' -f1",
"test:watch:unit": "jest --config ./jest.config.js --testPathPattern=spec --watch",
"test:watch:integration": "jest --config ./jest.config.js --testPathPattern=integration --watch",
"test:watch:e2e": "jest --config ./jest.config.js --testPathPattern=e2e --watch",
"migrate": "prisma migrate dev",
"migrate:deploy": "prisma migrate deploy",
"migrate:reset": "prisma migrate reset",
Expand Down
170 changes: 170 additions & 0 deletions test/e2e-setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
import { Test, TestingModule } from '@nestjs/testing';
import { ConfigModule } from '@nestjs/config';
import { INestApplication } from '@nestjs/common';
import * as request from 'supertest';

// E2E test setup
beforeAll(async () => {
// Set E2E test environment
process.env.NODE_ENV = 'test';
process.env.DATABASE_URL = process.env.E2E_DATABASE_URL || 'postgresql://test:test@localhost:5432/propchain_e2e';
process.env.REDIS_URL = process.env.E2E_REDIS_URL || 'redis://localhost:6379/3';
process.env.PORT = '0'; // Use random port

console.log('Setting up E2E test environment...');
});

afterAll(async () => {
console.log('Cleaning up E2E test environment...');
});

// E2E test utilities
(global as any).createE2ETestApp = async (moduleImports: any[] = []) => {
const moduleRef = await Test.createTestingModule({
imports: [
ConfigModule.forRoot({
isGlobal: true,
ignoreEnvFile: true,
load: [() => ({
NODE_ENV: 'test',
DATABASE_URL: process.env.DATABASE_URL,
REDIS_URL: process.env.REDIS_URL,
JWT_SECRET: 'e2e-test-jwt-secret',
JWT_EXPIRES_IN: '1h',
S3_BUCKET: 'e2e-test-bucket',
S3_REGION: 'us-east-1',
PORT: '0',
})],
}),
...moduleImports,
],
}).compile();

const app = moduleRef.createNestApplication();

// Configure app for testing
app.enableCors({
origin: '*',
credentials: true,
});

await app.init();

return app;
};

// HTTP request utilities
(global as any).makeRequest = (app: INestApplication) => {
const agent = request.agent(app.getHttpServer());

return {
get: (url: string) => agent.get(url),
post: (url: string) => agent.post(url),
put: (url: string) => agent.put(url),
patch: (url: string) => agent.patch(url),
delete: (url: string) => agent.delete(url),

// Auth helpers
withAuth: (token: string) => ({
get: (url: string) => agent.get(url).set('Authorization', `Bearer ${token}`),
post: (url: string) => agent.post(url).set('Authorization', `Bearer ${token}`),
put: (url: string) => agent.put(url).set('Authorization', `Bearer ${token}`),
patch: (url: string) => agent.patch(url).set('Authorization', `Bearer ${token}`),
delete: (url: string) => agent.delete(url).set('Authorization', `Bearer ${token}`),
}),

// API key helpers
withApiKey: (apiKey: string) => ({
get: (url: string) => agent.get(url).set('X-API-Key', apiKey),
post: (url: string) => agent.post(url).set('X-API-Key', apiKey),
put: (url: string) => agent.put(url).set('X-API-Key', apiKey),
patch: (url: string) => agent.patch(url).set('X-API-Key', apiKey),
delete: (url: string) => agent.delete(url).set('X-API-Key', apiKey),
}),
};
};

// Test data factories for E2E
(global as any).createE2ETestUser = async (app: INestApplication) => {
const response = await (global as any).makeRequest(app)
.post('/auth/register')
.send({
email: 'e2e-test@example.com',
password: 'TestPassword123!',
firstName: 'E2E',
lastName: 'Test',
})
.expect(201);

return response.body;
};

(global as any).loginE2ETestUser = async (app: INestApplication, email: string, password: string) => {
const response = await (global as any).makeRequest(app)
.post('/auth/login')
.send({ email, password })
.expect(200);

return response.body.access_token;
};

(global as any).createE2ETestProperty = async (app: INestApplication, token: string) => {
const response = await (global as any).makeRequest(app)
.withAuth(token)
.post('/properties')
.send({
title: 'E2E Test Property',
description: 'Property for E2E testing',
price: 850000,
type: 'RESIDENTIAL',
status: 'AVAILABLE',
bedrooms: 3,
bathrooms: 2,
squareFootage: 1800,
address: {
street: '789 E2E Street',
city: 'Test City',
state: 'TS',
zipCode: '11223',
country: 'Test Country',
latitude: 40.7614,
longitude: -73.9776,
},
})
.expect(201);

return response.body;
};

// Flow testing utilities
(global as any).testUserFlow = async (app: INestApplication) => {
// 1. Register user
const user = await (global as any).createE2ETestUser(app);

// 2. Login user
const token = await (global as any).loginE2ETestUser(app, 'e2e-test@example.com', 'TestPassword123!');

// 3. Create property
const property = await (global as any).createE2ETestProperty(app, token);

// 4. Get property
const retrievedProperty = await (global as any).makeRequest(app)
.withAuth(token)
.get(`/properties/${property.id}`)
.expect(200);

// 5. Update property
const updatedProperty = await (global as any).makeRequest(app)
.withAuth(token)
.patch(`/properties/${property.id}`)
.send({ status: 'PENDING' })
.expect(200);

// 6. Delete property
await (global as any).makeRequest(app)
.withAuth(token)
.delete(`/properties/${property.id}`)
.expect(200);

return { user, token, property };
};
Loading
Loading