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.
43 lines
1.4 KiB
TypeScript
43 lines
1.4 KiB
TypeScript
import { Test, TestingModule } from '@nestjs/testing';
|
|
import { INestApplication } from '@nestjs/common';
|
|
import request from 'supertest';
|
|
import { App } from 'supertest/types';
|
|
import { AppModule } from './../src/app.module';
|
|
import { HiboutikService } from './../src/services/hiboutik/hiboutik.service';
|
|
import { PrismaService } from './../prisma/prisma.service';
|
|
|
|
// Boots the real AppModule wiring, without database nor Hiboutik calls
|
|
describe('AppController (e2e)', () => {
|
|
let app: INestApplication<App>;
|
|
const hiboutikService = { startSync: jest.fn() };
|
|
|
|
beforeEach(async () => {
|
|
hiboutikService.startSync.mockReset();
|
|
const moduleFixture: TestingModule = await Test.createTestingModule({
|
|
imports: [AppModule],
|
|
})
|
|
.overrideProvider(PrismaService)
|
|
.useValue({})
|
|
.overrideProvider(HiboutikService)
|
|
.useValue(hiboutikService)
|
|
.compile();
|
|
|
|
app = moduleFixture.createNestApplication();
|
|
await app.init();
|
|
});
|
|
|
|
it('POST /sync starts a synchronization (202)', () => {
|
|
hiboutikService.startSync.mockReturnValue(true);
|
|
return request(app.getHttpServer()).post('/sync').expect(202).expect({ message: 'Hiboutik synchronization started' });
|
|
});
|
|
|
|
it('POST /sync answers 409 when a synchronization is already running', () => {
|
|
hiboutikService.startSync.mockReturnValue(false);
|
|
return request(app.getHttpServer()).post('/sync').expect(409);
|
|
});
|
|
|
|
afterEach(async () => {
|
|
await app.close();
|
|
});
|
|
});
|