mirror of
https://github.com/dadosfera/maestro.git
synced 2026-10-11 22:39:08 +00:00
76 lines
1.9 KiB
TypeScript
76 lines
1.9 KiB
TypeScript
import { Test, TestingModule } from '@nestjs/testing';
|
|
import { InputsController } from './inputs.controller';
|
|
import { InputsService } from './inputs.service';
|
|
import DadosferaLogger from '@dadosfera/dadosfera-logs';
|
|
import { CreateCdcInputReq } from './dtos/input.model';
|
|
import { RequestUser } from 'src/decorators/user.decorator';
|
|
|
|
describe('InputsController', () => {
|
|
let controller: InputsController;
|
|
let inputsService: { createCdc: jest.Mock };
|
|
|
|
beforeEach(async () => {
|
|
inputsService = {
|
|
createCdc: jest.fn().mockResolvedValue({ input: {} }),
|
|
};
|
|
|
|
const module: TestingModule = await Test.createTestingModule({
|
|
controllers: [InputsController],
|
|
providers: [
|
|
{
|
|
provide: DadosferaLogger,
|
|
useValue: { logger: { info: jest.fn() } },
|
|
},
|
|
{
|
|
provide: InputsService,
|
|
useValue: inputsService,
|
|
},
|
|
],
|
|
}).compile();
|
|
|
|
controller = module.get<InputsController>(InputsController);
|
|
});
|
|
|
|
it('should be defined', () => {
|
|
expect(controller).toBeDefined();
|
|
});
|
|
|
|
it('forwards destination.iceberg.namespace to InputsService.createCdc', async () => {
|
|
const body: CreateCdcInputReq = {
|
|
name: 'my-cdc-input',
|
|
plugin: 'mysql_cdc',
|
|
tables: [
|
|
{
|
|
name: 'orders',
|
|
table_schema: 'public',
|
|
iceberg_table_name: 'orders_iceberg',
|
|
},
|
|
],
|
|
destination: {
|
|
iceberg: {
|
|
namespace: 'my_namespace',
|
|
},
|
|
},
|
|
};
|
|
const user: RequestUser = {
|
|
user_id: 'user-1',
|
|
customer_id: 'customer-1',
|
|
customer_name: 'customer',
|
|
} as RequestUser;
|
|
|
|
await controller.createCdc(body, user);
|
|
|
|
expect(inputsService.createCdc).toHaveBeenCalledWith(
|
|
expect.objectContaining({
|
|
body: expect.objectContaining({
|
|
destination: {
|
|
iceberg: {
|
|
namespace: 'my_namespace',
|
|
},
|
|
},
|
|
}),
|
|
}),
|
|
);
|
|
});
|
|
});
|