mirror of
https://github.com/Kaelio/ktx.git
synced 2026-07-01 08:59:39 +02:00
* fix: store Metabase mappings in ktx.yaml * docs: note KTX has no public users * refactor: drop setup progress compatibility
68 lines
2.6 KiB
TypeScript
68 lines
2.6 KiB
TypeScript
import { mkdtemp, rm } from 'node:fs/promises';
|
|
import { tmpdir } from 'node:os';
|
|
import { join } from 'node:path';
|
|
import { afterEach, describe, expect, it } from 'vitest';
|
|
import { ktxLocalStateDbPath, type KtxLocalProject } from '../project/index.js';
|
|
import { LocalLookerRuntimeStore } from './adapters/looker/local-runtime-store.js';
|
|
import { seedLocalMappingStateFromKtxYaml } from './local-mapping-reconcile.js';
|
|
|
|
describe('local mapping yaml reconciliation bridge', () => {
|
|
let tempDir: string;
|
|
|
|
afterEach(async () => {
|
|
if (tempDir) {
|
|
await rm(tempDir, { recursive: true, force: true });
|
|
}
|
|
});
|
|
|
|
function projectWithConnections(connections: KtxLocalProject['config']['connections']): KtxLocalProject {
|
|
return {
|
|
projectDir: tempDir,
|
|
config: { connections },
|
|
} as KtxLocalProject;
|
|
}
|
|
|
|
it('does not copy Metabase mapping intent into local SQLite state', async () => {
|
|
tempDir = await mkdtemp(join(tmpdir(), 'ktx-metabase-yaml-seed-'));
|
|
const project = projectWithConnections({
|
|
'prod-metabase': {
|
|
driver: 'metabase',
|
|
mappings: {
|
|
databaseMappings: { '1': 'prod-warehouse' },
|
|
syncEnabled: { '1': true },
|
|
syncMode: 'ONLY',
|
|
selections: { collections: [12] },
|
|
defaultTagNames: ['ktx'],
|
|
},
|
|
},
|
|
'prod-warehouse': { driver: 'postgres', url: 'postgresql://readonly@db.test/analytics' },
|
|
});
|
|
|
|
await expect(seedLocalMappingStateFromKtxYaml(project, 'prod-metabase')).resolves.toBeUndefined();
|
|
});
|
|
|
|
it('seeds Looker local mappings from ktx.yaml mapping intent', async () => {
|
|
tempDir = await mkdtemp(join(tmpdir(), 'ktx-looker-yaml-seed-'));
|
|
const project = projectWithConnections({
|
|
'prod-looker': {
|
|
driver: 'looker',
|
|
mappings: { connectionMappings: { analytics: 'prod-warehouse' } },
|
|
},
|
|
'prod-warehouse': { driver: 'postgres', url: 'postgresql://readonly@db.test/analytics' },
|
|
});
|
|
|
|
await seedLocalMappingStateFromKtxYaml(project, 'prod-looker');
|
|
|
|
const store = new LocalLookerRuntimeStore({ dbPath: ktxLocalStateDbPath(project) });
|
|
await expect(store.listConnectionMappings('prod-looker')).resolves.toMatchObject([
|
|
{ lookerConnectionName: 'analytics', ktxConnectionId: 'prod-warehouse', source: 'ktx.yaml' },
|
|
]);
|
|
});
|
|
|
|
it('does nothing for connections without mapping bootstrap intent', async () => {
|
|
tempDir = await mkdtemp(join(tmpdir(), 'ktx-no-yaml-seed-'));
|
|
const project = projectWithConnections({ warehouse: { driver: 'postgres', url: 'env:DATABASE_URL' } });
|
|
|
|
await expect(seedLocalMappingStateFromKtxYaml(project, 'warehouse')).resolves.toBeUndefined();
|
|
});
|
|
});
|