forked from Shared/esg
Implement normalized error handling with Persian translations across all exception types, replace legacy NestJS exceptions with AppException, and add unit, integration, and smoke tests. - Add error catalog with gateway-owned codes and Persian messages - Introduce AppException wrapping normalized error envelopes - Add translateError helper for automatic messageFa population - Remove claims module and update provider error normalization - Add unit tests for error contracts and helper functions - Add integration tests for admin and inquiry endpoints - Add smoke tests for real provider connectivity - Add test support utilities (auth mocks, assertions, app factory)
41 lines
1.5 KiB
TypeScript
41 lines
1.5 KiB
TypeScript
import { INestApplication, ValidationPipe } from '@nestjs/common';
|
|
import { ModuleMetadata } from '@nestjs/common/interfaces';
|
|
import { Test, TestingModuleBuilder } from '@nestjs/testing';
|
|
import { AllExceptionsFilter } from '../../src/common/filters/all-exceptions.filter';
|
|
import { AppException } from '../../src/common/exceptions/app-exception';
|
|
import { buildValidationErrorResponse } from '../../src/common/helpers/validation-error.helper';
|
|
|
|
export async function createHttpTestApp(
|
|
metadata: ModuleMetadata,
|
|
configure: (builder: TestingModuleBuilder) => TestingModuleBuilder = (builder) => builder,
|
|
): Promise<INestApplication> {
|
|
const moduleRef = await configure(Test.createTestingModule(metadata)).compile();
|
|
const app = moduleRef.createNestApplication();
|
|
|
|
app.use((req: { requestId?: string }, _res: unknown, next: () => void) => {
|
|
req.requestId = 'test-request-id';
|
|
next();
|
|
});
|
|
app.useGlobalFilters(new AllExceptionsFilter());
|
|
app.useGlobalPipes(
|
|
new ValidationPipe({
|
|
whitelist: true,
|
|
forbidNonWhitelisted: true,
|
|
transform: true,
|
|
transformOptions: { enableImplicitConversion: true },
|
|
exceptionFactory: (errors) => {
|
|
const { normalizedError } = buildValidationErrorResponse(errors);
|
|
|
|
return new AppException('VALIDATION_ERROR', {
|
|
message: normalizedError.message,
|
|
messageFa: normalizedError.messageFa,
|
|
details: normalizedError.details,
|
|
});
|
|
},
|
|
}),
|
|
);
|
|
|
|
await app.init();
|
|
return app;
|
|
}
|