mirror of
https://github.com/dadosfera/maestro.git
synced 2026-08-31 19:58:21 +00:00
test(inputs): add service-level test for CDC create field-mapping
InputsService.createCdc builds InputCreateCdcRequest by enumerating fields (not spreading), so a revert of the destination/iceberg_table_name mapping lines would not be caught by the existing controller spec, which only mocks InputsService. Add a unit test at the service boundary that asserts destination and per-table iceberg_table_name reach the gRPC request, plus a back-compat case with no destination. Also mark CdcTableReq.iceberg_table_name as advisory/reserved: the platform derives the Iceberg table name itself today and does not yet consume this field. Co-Authored-By: WOZCODE <contact@withwoz.com>
This commit is contained in:
@@ -73,6 +73,7 @@ export class CdcTableReq {
|
||||
table_schema?: string;
|
||||
@ApiPropertyOptional({ type: [String] })
|
||||
primary_keys?: string[];
|
||||
// Advisory/reserved: the platform currently derives the Iceberg table name itself (create_iceberg_table_name); this value is persisted but not yet consumed on the create/add path. Do not treat as the authoritative table name.
|
||||
@ApiPropertyOptional()
|
||||
iceberg_table_name?: string;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
import { of } from 'rxjs';
|
||||
import { InputsService } from './inputs.service';
|
||||
import DadosferaLogger from '@dadosfera/dadosfera-logs/dist';
|
||||
import { CreateCdcInputReq } from './dtos/input.model';
|
||||
import { Info } from '@dadosfera/protospack-v2/dist/lib/Input/interfaces/entities';
|
||||
|
||||
const info = { customer_id: 'cid', user_id: 'u' } as unknown as Info;
|
||||
|
||||
describe('InputsService.createCdc', () => {
|
||||
let service: InputsService;
|
||||
let inputCreateCdcMock: jest.Mock;
|
||||
|
||||
beforeEach(async () => {
|
||||
inputCreateCdcMock = jest
|
||||
.fn()
|
||||
.mockImplementation((req) => of({ input: req.input }));
|
||||
|
||||
const grpcClient: any = {
|
||||
getService: jest.fn().mockReturnValue({
|
||||
InputCreateCdc: inputCreateCdcMock,
|
||||
}),
|
||||
};
|
||||
|
||||
service = new InputsService(new DadosferaLogger(), grpcClient);
|
||||
await service.onModuleInit();
|
||||
});
|
||||
|
||||
it('forwards destination and per-table iceberg_table_name to the gRPC request', async () => {
|
||||
const body: CreateCdcInputReq = {
|
||||
name: 'CDC Iceberg Test',
|
||||
plugin: 'mysql_cdc',
|
||||
read_only: true,
|
||||
destination: { iceberg: { namespace: 'cdc_raw' } },
|
||||
tables: [
|
||||
{
|
||||
name: 'orders',
|
||||
table_schema: 'mydb',
|
||||
primary_keys: ['id'],
|
||||
iceberg_table_name: 'cdc_raw.mydb__orders',
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
await service.createCdc({ body, info });
|
||||
|
||||
expect(inputCreateCdcMock).toHaveBeenCalledTimes(1);
|
||||
const sentRequest = inputCreateCdcMock.mock.calls[0][0];
|
||||
|
||||
expect(sentRequest.input).toEqual(
|
||||
expect.objectContaining({
|
||||
destination: { iceberg: { namespace: 'cdc_raw' } },
|
||||
}),
|
||||
);
|
||||
expect(sentRequest.input.tables[0]).toEqual(
|
||||
expect.objectContaining({
|
||||
iceberg_table_name: 'cdc_raw.mydb__orders',
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it('back-compat: a body with no destination sends destination undefined, not an error', async () => {
|
||||
const body: CreateCdcInputReq = {
|
||||
name: 'CDC Legacy Test',
|
||||
plugin: 'mysql_cdc',
|
||||
read_only: true,
|
||||
tables: [
|
||||
{
|
||||
name: 'pedidos',
|
||||
table_schema: 'cadastros',
|
||||
primary_keys: ['id'],
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const result = await service.createCdc({ body, info });
|
||||
|
||||
expect(inputCreateCdcMock).toHaveBeenCalledTimes(1);
|
||||
const sentRequest = inputCreateCdcMock.mock.calls[0][0];
|
||||
|
||||
expect(sentRequest.input.destination).toBeUndefined();
|
||||
expect(sentRequest.input.tables[0].iceberg_table_name).toBeUndefined();
|
||||
expect(result.input).toBeDefined();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user