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
3 changes: 3 additions & 0 deletions .github/workflows/backend-ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ jobs:
- name: Generate OpenAPI and SDK artifacts
run: pnpm run generate:api-sdk

- name: Run contract tests
run: cd backend && npm run test:contract

- name: Upload generated SDK artifact
uses: actions/upload-artifact@v4
with:
Expand Down
3 changes: 3 additions & 0 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "jest --config ./test/jest-e2e.js",
"test:e2e:ci": "jest --config ./test/jest-e2e.js --runInBand",
"test:contract": "npm run generate:openapi && jest --config ./test/jest-contract.js",
"generate:openapi": "ts-node -r tsconfig-paths/register scripts/generate-openapi-spec.ts",
"generate:sdk": "pnpm --dir .. run generate:api-sdk",
"generate:error-docs": "ts-node -r tsconfig-paths/register src/scripts/generate-error-docs.ts"
Expand Down Expand Up @@ -63,6 +64,7 @@
"ioredis": "^5.11.1",
"isomorphic-dompurify": "^3.15.0",
"joi": "^18.0.2",
"js-yaml": "^5.2.0",
"multer": "^2.1.1",
"nestjs-pino": "^4.6.1",
"nodemailer": "^8.0.1",
Expand Down Expand Up @@ -93,6 +95,7 @@
"@types/compression": "^1.7.6",
"@types/express": "^5.0.0",
"@types/jest": "^29.5.14",
"@types/js-yaml": "^4.0.9",
"@types/multer": "^2.0.0",
"@types/node": "^22.10.7",
"@types/nodemailer": "^7.0.11",
Expand Down
1 change: 0 additions & 1 deletion backend/src/modules/feature-flags/feature-flags.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,4 +283,3 @@ export class FeatureFlagsService {
await this.cacheManager.del(this.cacheKey(key));
}
}
}
19 changes: 19 additions & 0 deletions backend/test/jest-contract.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module.exports = {
moduleFileExtensions: ['js', 'json', 'ts'],
rootDir: '..',
testEnvironment: 'node',
testRegex: '.contract.spec.ts$',
transform: {
'^.+\\.(t|j)s$': [
'ts-jest',
{
tsconfig: {
skipLibCheck: true,
forceConsistentCasingInFileNames: true,
moduleResolution: 'bundler',
types: ['jest', 'node'],
},
},
],
},
};
41 changes: 41 additions & 0 deletions backend/test/openapi-contract.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import * as fs from 'fs';
import * as path from 'path';

describe('OpenAPI Contract Tests', () => {
let openApiSpec: any;

beforeAll(() => {
const specPath = path.join(__dirname, '../openapi-v2.json');
if (!fs.existsSync(specPath)) {
throw new Error(`OpenAPI spec not found at ${specPath}. Run 'pnpm run generate:openapi' first.`);
}
openApiSpec = JSON.parse(fs.readFileSync(specPath, 'utf-8'));
});

it('should match the snapshot', () => {
expect(openApiSpec).toMatchSnapshot();
});

it('should have required paths', () => {
const requiredPaths = [
'/api/v2/auth/login',
'/api/v2/auth/register',
];

requiredPaths.forEach((path) => {
expect(openApiSpec.paths).toHaveProperty(path);
});
});

it('should have required components', () => {
const requiredComponents = [
'PageDto',
'PaginatedResponseDto',
'StandardErrorResponseDto',
];

requiredComponents.forEach((component) => {
expect(openApiSpec.components.schemas).toHaveProperty(component);
});
});
});
19 changes: 19 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading