Skip to content

Commit 96553f9

Browse files
committed
test: add WITH...SELECT LIMIT injection tests
Cover the CTE branch of LIMIT injection logic — both appending LIMIT to a bare WITH...SELECT and skipping when one already exists.
1 parent a926242 commit 96553f9

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

‎packages/drivers/test/clickhouse-unit.test.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,18 @@ describe("ClickHouse driver unit tests", () => {
109109
// --- LIMIT injection ---
110110

111111
describe("LIMIT injection", () => {
112+
test("appends LIMIT to WITH...SELECT without one", async () => {
113+
mockQueryResult = [{ id: 1 }]
114+
await connector.execute("WITH cte AS (SELECT * FROM t) SELECT * FROM cte", 10)
115+
expect(mockQueryCalls[0].query).toContain("LIMIT 11")
116+
})
117+
118+
test("does NOT double-LIMIT WITH...SELECT that already has one", async () => {
119+
mockQueryResult = [{ id: 1 }]
120+
await connector.execute("WITH cte AS (SELECT * FROM t) SELECT * FROM cte LIMIT 5", 10)
121+
expect(mockQueryCalls[0].query).not.toContain("LIMIT 11")
122+
})
123+
112124
test("appends LIMIT to SELECT without one", async () => {
113125
mockQueryResult = [{ id: 1 }]
114126
await connector.execute("SELECT * FROM t", 10)

0 commit comments

Comments
 (0)