Files
dbx/packages/app-tests/sqlExecutionTarget.test.ts
T
8747df53ef fix(mongodb): support multi-command execution
* fix mongodb multi-command execution

* fix(connection): 复制连接时保持在同一组内

- 修改 `addConnection` 方法以支持指定目标组 ID
- 更新 `duplicateConnection` 函数以传递目标组 ID
- 添加测试用例以验证复制连接的功能

* fix: add MongoDB data transfer entry

* feat(editor): SQL 编辑器选区大小写转换

Co-authored-by: staff <staff@qimaos-MacBook-Pro.local>

* fix(editor): 修复SQL快捷执行导致执行全量SQL的问题 (#2384)

- 将执行SQL语句的逻辑从直接请求改为通过事件发射
- 增强了代码的可扩展性和可维护性

* fix(sidebar): cache tooltip overflow measurement

* fix(dialog): allow dragging window from modal overlay

* fix(oracle): reuse shared pool for data tabs

* fix(sidebar): reduce comment text repaint cost

* fix(saved-sql): preserve folder on metadata save

* fix(agent): execute transaction control SQL as statements

* feat(vector): add Qdrant/Milvus collection dimension display (#2396)

* fix(oracle): 修复时间字段编辑和表结构修改报错

Co-authored-by: staff <staff@qimaos-MacBook-Pro.local>

* fix(agents): limit common version bumps

---------

Co-authored-by: 二丫讲梵 <eryajf@163.com>
Co-authored-by: zipg <geeky@foxmail.com>
Co-authored-by: staff <staff@qimaos-MacBook-Pro.local>
Co-authored-by: t8y2 <1156263951@qq.com>
Co-authored-by: lexmin0412 <zhangle_dev@outlook.com>
2026-07-02 12:19:38 +08:00

43 lines
1.4 KiB
TypeScript

import { strict as assert } from "node:assert";
import { beforeEach, test, vi } from "vitest";
const apiMock = vi.hoisted(() => ({
findStatementAtCursor: vi.fn(),
}));
vi.mock("@/lib/api", () => apiMock);
const { resolveExecutableSqlWithBackend } = await import("../../apps/desktop/src/lib/sqlExecutionTarget.ts");
beforeEach(() => {
apiMock.findStatementAtCursor.mockReset();
});
test("mongodb backend resolution keeps the full text when nothing is selected", async () => {
apiMock.findStatementAtCursor.mockResolvedValue("db.users.insertOne({ name: 'ignored' })");
const fullSql = "db.users.insertOne({ name: 'Ada' });\ndb.users.insertOne({ name: 'Grace' });";
const resolved = await resolveExecutableSqlWithBackend(fullSql, "", {
mode: "current",
cursorPos: fullSql.indexOf("Grace"),
databaseType: "mongodb",
});
assert.equal(resolved, fullSql);
assert.equal(apiMock.findStatementAtCursor.mock.calls.length, 0);
});
test("non-mongodb backend resolution still asks the backend for the current statement", async () => {
apiMock.findStatementAtCursor.mockResolvedValue("SELECT 2");
const fullSql = "SELECT 1;\nSELECT 2;";
const resolved = await resolveExecutableSqlWithBackend(fullSql, "", {
mode: "current",
cursorPos: fullSql.indexOf("2"),
databaseType: "postgres",
});
assert.equal(resolved, "SELECT 2");
assert.deepEqual(apiMock.findStatementAtCursor.mock.calls[0], [fullSql, fullSql.indexOf("2"), "postgres"]);
});