- Validate the environment at startup (src/config): required variables must be present, HIBOUTIK_BASE_URL must be HTTPS. - Global ValidationPipe (whitelist, forbidNonWhitelisted, transform). - Helmet, CORS disabled unless CORS_ORIGINS is set, TRUST_PROXY support, HTTP header/request timeouts, shutdown hooks. - Rate limiting: 60 req/min/IP globally, 5 req/min on POST /sync. - AllExceptionsFilter: unexpected errors are logged (message + stack, never the raw error object) and answered with a generic 500. - Postgres advisory lock (dedicated connection) so only one synchronization runs at a time across all instances; released by Postgres itself if the process dies. - Fix the Jest moduleNameMapper (unescaped dot also matched .cjs files). - Document the input validation and security rules in CLAUDE.md. - Add class-validator, class-transformer, helmet and @nestjs/throttler; npm audit fix refreshed package-lock.json. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
30 lines
1.1 KiB
TypeScript
30 lines
1.1 KiB
TypeScript
import { ConflictException } from '@nestjs/common';
|
|
import { Test, TestingModule } from '@nestjs/testing';
|
|
import { AppController } from './app.controller';
|
|
import { HiboutikService } from './services/hiboutik/hiboutik.service';
|
|
|
|
describe('AppController', () => {
|
|
let controller: AppController;
|
|
const hiboutikService = { startSync: jest.fn() };
|
|
|
|
beforeEach(async () => {
|
|
hiboutikService.startSync.mockReset();
|
|
const module: TestingModule = await Test.createTestingModule({
|
|
controllers: [AppController],
|
|
providers: [{ provide: HiboutikService, useValue: hiboutikService }],
|
|
}).compile();
|
|
controller = module.get(AppController);
|
|
});
|
|
|
|
it('starts a synchronization', async () => {
|
|
hiboutikService.startSync.mockResolvedValue(true);
|
|
await expect(controller.hiboutikSync()).resolves.toEqual({ message: 'Hiboutik synchronization started' });
|
|
expect(hiboutikService.startSync).toHaveBeenCalledTimes(1);
|
|
});
|
|
|
|
it('rejects a synchronization when one is already running', async () => {
|
|
hiboutikService.startSync.mockResolvedValue(false);
|
|
await expect(controller.hiboutikSync()).rejects.toThrow(ConflictException);
|
|
});
|
|
});
|