Skip to content

Commit a885a7e

Browse files
mdesmetclaude
andcommitted
test(dbt-tools): add unit tests for build command routing
Covers: no-model → project build, --model → single model, --downstream flag. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 99aacab commit a885a7e

1 file changed

Lines changed: 47 additions & 0 deletions

File tree

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { describe, test, expect, mock } from "bun:test"
2+
import { build, project } from "../src/commands/build"
3+
import type { DBTProjectIntegrationAdapter } from "@altimateai/dbt-integration"
4+
5+
function makeAdapter(overrides: Partial<DBTProjectIntegrationAdapter> = {}): DBTProjectIntegrationAdapter {
6+
return {
7+
unsafeBuildModelImmediately: mock(() => Promise.resolve({ stdout: "model built", stderr: "" })),
8+
unsafeBuildProjectImmediately: mock(() => Promise.resolve({ stdout: "project built", stderr: "" })),
9+
unsafeRunModelImmediately: mock(() => Promise.resolve({ stdout: "", stderr: "" })),
10+
unsafeRunModelTestImmediately: mock(() => Promise.resolve({ stdout: "", stderr: "" })),
11+
dispose: mock(() => Promise.resolve()),
12+
...overrides,
13+
} as unknown as DBTProjectIntegrationAdapter
14+
}
15+
16+
describe("build command", () => {
17+
test("build without --model builds entire project", async () => {
18+
const adapter = makeAdapter()
19+
const result = await build(adapter, [])
20+
expect(adapter.unsafeBuildProjectImmediately).toHaveBeenCalledTimes(1)
21+
expect(adapter.unsafeBuildModelImmediately).not.toHaveBeenCalled()
22+
expect(result).toEqual({ stdout: "project built" })
23+
})
24+
25+
test("build --model <name> builds single model", async () => {
26+
const adapter = makeAdapter()
27+
const result = await build(adapter, ["--model", "orders"])
28+
expect(adapter.unsafeBuildModelImmediately).toHaveBeenCalledTimes(1)
29+
expect(adapter.unsafeBuildModelImmediately).toHaveBeenCalledWith({
30+
plusOperatorLeft: "",
31+
modelName: "orders",
32+
plusOperatorRight: "",
33+
})
34+
expect(adapter.unsafeBuildProjectImmediately).not.toHaveBeenCalled()
35+
expect(result).toEqual({ stdout: "model built" })
36+
})
37+
38+
test("build --model <name> --downstream sets plusOperatorRight", async () => {
39+
const adapter = makeAdapter()
40+
await build(adapter, ["--model", "orders", "--downstream"])
41+
expect(adapter.unsafeBuildModelImmediately).toHaveBeenCalledWith({
42+
plusOperatorLeft: "",
43+
modelName: "orders",
44+
plusOperatorRight: "+",
45+
})
46+
})
47+
})

0 commit comments

Comments
 (0)