feat(sync): synchronize Hiboutik data through POST /sync

POST /sync starts the full synchronization in the background (202, or 409 when one is already running). Entities are synced in dependency order: brands, categories, suppliers, products (with versions and stocks), customers. Each row is synced independently so that a failure is logged without stopping the rest. Replaces the default AppService.
This commit is contained in:
MastersGame
2026-11-05 23:00:49 +01:00
parent 27d0e0149d
commit c5f65dcb62
17 changed files with 878 additions and 34 deletions

View File

@@ -1,22 +1,29 @@
import { ConflictException } from '@nestjs/common';
import { Test, TestingModule } from '@nestjs/testing';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { HiboutikService } from './services/hiboutik/hiboutik.service';
describe('AppController', () => {
let appController: AppController;
let controller: AppController;
const hiboutikService = { startSync: jest.fn() };
beforeEach(async () => {
const app: TestingModule = await Test.createTestingModule({
hiboutikService.startSync.mockReset();
const module: TestingModule = await Test.createTestingModule({
controllers: [AppController],
providers: [AppService],
providers: [{ provide: HiboutikService, useValue: hiboutikService }],
}).compile();
appController = app.get<AppController>(AppController);
controller = module.get(AppController);
});
describe('root', () => {
it('should return "Hello World!"', () => {
expect(appController.getHello()).toBe('Hello World!');
});
it('starts a synchronization', () => {
hiboutikService.startSync.mockReturnValue(true);
expect(controller.hiboutikSync()).toEqual({ message: 'Hiboutik synchronization started' });
expect(hiboutikService.startSync).toHaveBeenCalledTimes(1);
});
it('rejects a synchronization when one is already running', () => {
hiboutikService.startSync.mockReturnValue(false);
expect(() => controller.hiboutikSync()).toThrow(ConflictException);
});
});