feat(docs): Remove outdated service templates and enhance Vietnamese architecture documentation

- Deleted obsolete service architecture templates in both English and Vietnamese to streamline content.
- Updated the Vietnamese architecture documentation with improved Mermaid diagrams for better visual clarity.
- Enhanced color coding in diagrams to improve readability and consistency across documentation.
- Added a new section detailing visual indicators for better understanding of architecture components.
This commit is contained in:
Ho Ngoc Hai
2026-01-10 21:00:02 +07:00
parent b89e07f4cb
commit 4e595d0746
50 changed files with 36 additions and 28 deletions

View File

@@ -0,0 +1,124 @@
import request from 'supertest';
import express from 'express';
import { setupSwagger, specs } from '../swagger';
// EN: Import actual swagger specs for testing
// VI: Import actual swagger specs để test
// EN: Type definition for OpenAPI specs
// VI: Định nghĩa type cho OpenAPI specs
interface OpenAPISpec {
openapi: string;
info: {
title: string;
version: string;
[key: string]: any;
};
servers?: Array<{ url: string; [key: string]: any }>;
components?: {
securitySchemes?: {
[key: string]: {
type: string;
scheme: string;
[key: string]: any;
};
};
schemas?: {
[key: string]: any;
};
[key: string]: any;
};
[key: string]: any;
}
describe('Swagger Documentation', () => {
let app: express.Application;
beforeEach(() => {
app = express();
app.use(express.json());
// Reset mock
(setupSwagger as jest.Mock).mockClear();
});
describe('specs', () => {
it('should have valid OpenAPI structure', () => {
const typedSpecs = specs as OpenAPISpec;
expect(typedSpecs.openapi).toBe('3.0.0');
expect(typedSpecs.info).toBeDefined();
expect(typedSpecs.info.title).toBe('Microservice Template API');
expect(typedSpecs.info.version).toBe('1.0.0');
expect(typedSpecs.servers).toBeDefined();
expect(typedSpecs.components).toBeDefined();
});
it('should define security schemes', () => {
const typedSpecs = specs as OpenAPISpec;
expect(typedSpecs.components?.securitySchemes).toBeDefined();
expect(typedSpecs.components?.securitySchemes?.bearerAuth).toBeDefined();
expect(typedSpecs.components?.securitySchemes?.bearerAuth?.type).toBe('http');
expect(typedSpecs.components?.securitySchemes?.bearerAuth?.scheme).toBe('bearer');
});
it('should define response schemas', () => {
const typedSpecs = specs as OpenAPISpec;
const schemas = typedSpecs.components?.schemas;
expect(schemas?.ApiResponse).toBeDefined();
expect(schemas?.ErrorResponse).toBeDefined();
expect(schemas?.Feature).toBeDefined();
expect(schemas?.CreateFeatureRequest).toBeDefined();
expect(schemas?.UpdateFeatureRequest).toBeDefined();
expect(schemas?.UserInfo).toBeDefined();
});
it('should have server configurations', () => {
const typedSpecs = specs as OpenAPISpec;
expect(typedSpecs.servers).toBeInstanceOf(Array);
expect(typedSpecs.servers?.length).toBeGreaterThan(0);
expect(typedSpecs.servers?.[0]?.url).toContain('localhost');
});
});
describe('setupSwagger', () => {
it('should be callable', () => {
expect(typeof setupSwagger).toBe('function');
});
it('should accept app and basePath parameters', () => {
const mockApp = {
use: jest.fn(),
get: jest.fn(),
} as any;
setupSwagger(mockApp, '/docs');
expect(setupSwagger).toHaveBeenCalledWith(mockApp, '/docs');
});
});
describe('Swagger UI endpoints', () => {
beforeEach(() => {
// Setup real swagger for integration test
const realSetupSwagger = jest.requireActual('../swagger').setupSwagger;
realSetupSwagger(app, '/test-docs');
});
it('should serve swagger json endpoint', async () => {
const response = await request(app)
.get('/test-docs.json')
.expect(200);
expect(response.headers['content-type']).toContain('application/json');
expect(response.body.openapi).toBe('3.0.0');
});
it('should serve swagger yaml endpoint', async () => {
const response = await request(app)
.get('/test-docs.yaml')
.expect(200);
expect(response.headers['content-type']).toContain('application/yaml');
expect(response.text).toBeDefined();
});
});
});