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); }); });