mirror of
https://github.com/dadosfera/maestro.git
synced 2026-11-26 17:20:05 +00:00
The pipeline create body carries `config.tables[].destinations`, which the CDC path in pi-factory needs to honor a user-supplied raw Snowflake table name. The gRPC PipelineV2CreateRequest previously had no `config` field, so `...body` dropped it on the wire. Bump protospack to cdc.3 (adds optional `config` string). Serialize `body.config` into the create request the same way `properties` is handled, and add `config?` to the ICreatePipelineV2Req DTO so it's typed. Add a spec asserting the gRPC request carries a stringified config with the destination intact. Co-Authored-By: WOZCODE <contact@withwoz.com> Claude-Session: https://claude.ai/code/session_01145m1zZMfx8RSJBxAhySdg
143 lines
4.5 KiB
TypeScript
143 lines
4.5 KiB
TypeScript
// These imported modules pull in gRPC client-config / service modules that read
|
|
// process.env at load time; mock them (hoisted before imports) so the spec needs
|
|
// no runtime env. Each mock severs an entire import subtree while still providing
|
|
// a class usable as a value/DI token. Mirrors platform-api.controller.spec.ts.
|
|
jest.mock('./pipelines-client', () => ({ PipelinesClientConfiguration: class {} }));
|
|
jest.mock('../connector/client.service', () => ({ ConnectorClientService: class {} }));
|
|
jest.mock('../inputs/inputs.service', () => ({ InputsService: class {} }));
|
|
jest.mock('../transformations/transformations.service', () => ({ TransformationsService: class {} }));
|
|
jest.mock('../platform-api/platform-api.service', () => ({ PlatformApiService: class {} }));
|
|
jest.mock('src/services/nimbus/nimbus.service', () => ({ NimbusService: class {} }));
|
|
jest.mock('../catalog/catalog.service', () => ({ CatalogService: class {} }));
|
|
|
|
import { of } from 'rxjs';
|
|
import { PipelinesService } from './pipelines.service';
|
|
|
|
const logger = {
|
|
info: jest.fn(),
|
|
error: jest.fn(),
|
|
};
|
|
|
|
const cdcOldInput = { input: { plugin: 'mysql_cdc', tables: [] } };
|
|
const batchOldInput = { input: { plugin: 'mysql', type: 'database', tables: [] } };
|
|
|
|
const updateResponse = {
|
|
input: { type: 'database' },
|
|
tablesUpdate: [],
|
|
dataAssetUpdate: [],
|
|
};
|
|
|
|
const user: any = { customer_modules: [] };
|
|
const updateInputDTO: any = { tables: [] };
|
|
const info: any = { customer: 'cust' };
|
|
const metadata: any = {};
|
|
|
|
function buildService(oldInput: any) {
|
|
const inputsService: any = {
|
|
findOne: jest.fn().mockResolvedValue(oldInput),
|
|
update: jest.fn().mockResolvedValue(updateResponse),
|
|
rollbackUpdate: jest.fn().mockResolvedValue({}),
|
|
};
|
|
const nimbusService: any = { renameTable: jest.fn().mockResolvedValue({}) };
|
|
|
|
const service = new PipelinesService(
|
|
{ logger } as any, // dadosferaLogger
|
|
{} as any, // grpcClient
|
|
{} as any, // connectorService
|
|
inputsService, // inputsService
|
|
{} as any, // transformationsService
|
|
{} as any, // platformAPI
|
|
nimbusService, // nimbusService
|
|
{} as any, // catalogService
|
|
);
|
|
|
|
const updatePlatformJobsSpy = jest
|
|
.spyOn(service, 'updatePlatformJobs')
|
|
.mockResolvedValue(undefined as any);
|
|
|
|
return { service, inputsService, updatePlatformJobsSpy };
|
|
}
|
|
|
|
describe('PipelinesService - updatePipelineInput', () => {
|
|
afterEach(() => jest.clearAllMocks());
|
|
|
|
it('CDC input skips updatePlatformJobs', async () => {
|
|
const { service, inputsService, updatePlatformJobsSpy } = buildService(cdcOldInput);
|
|
|
|
const result = await service.updatePipelineInput(
|
|
'pipeline-id',
|
|
'input-id',
|
|
updateInputDTO,
|
|
info,
|
|
user,
|
|
metadata,
|
|
);
|
|
|
|
expect(updatePlatformJobsSpy).not.toHaveBeenCalled();
|
|
expect(inputsService.update).toHaveBeenCalled();
|
|
expect(result).toBe(updateResponse);
|
|
});
|
|
|
|
it('batch input calls updatePlatformJobs', async () => {
|
|
const { service, inputsService, updatePlatformJobsSpy } = buildService(batchOldInput);
|
|
|
|
await service.updatePipelineInput(
|
|
'pipeline-id',
|
|
'input-id',
|
|
updateInputDTO,
|
|
info,
|
|
user,
|
|
metadata,
|
|
);
|
|
|
|
expect(updatePlatformJobsSpy).toHaveBeenCalled();
|
|
expect(inputsService.update).toHaveBeenCalled();
|
|
});
|
|
});
|
|
|
|
describe('PipelinesService - create', () => {
|
|
afterEach(() => jest.clearAllMocks());
|
|
|
|
// The body's `config` (carrying CDC destinations) must reach pi-factory as a
|
|
// JSON string — the gRPC proto field is a string, so an object would be
|
|
// stripped on the wire. Mirrors how `properties` is serialized.
|
|
it('serializes the body config into the gRPC create request', async () => {
|
|
const { service } = buildService(cdcOldInput);
|
|
|
|
let captured: any;
|
|
(service as any).pipelineWriteService = {
|
|
PipelineV2Create: (req: any) => {
|
|
captured = req;
|
|
// The service does `lastValueFrom(...)`; return a real Observable.
|
|
return of({ pipeline: {} });
|
|
},
|
|
};
|
|
|
|
const body: any = {
|
|
name: 'p',
|
|
input_id: 'i',
|
|
transformations_ids: [],
|
|
tags: [],
|
|
properties: { schema: 'cadastros' },
|
|
config: {
|
|
cron: '@once',
|
|
tables: [
|
|
{
|
|
name: 'pedidos',
|
|
destinations: {
|
|
raw: { table_schema: 'PUBLIC', table_name: 'pedidos_001' },
|
|
},
|
|
},
|
|
],
|
|
},
|
|
};
|
|
|
|
await service.create(body, metadata);
|
|
|
|
expect(typeof captured.config).toBe('string');
|
|
expect(JSON.parse(captured.config).tables[0].destinations.raw.table_name).toBe(
|
|
'pedidos_001',
|
|
);
|
|
});
|
|
});
|