fix(ai): preserve Dameng database and schema scopes
This commit is contained in:
16 files changed
+634
-76
No files matched your search
@@ -17,6 +17,8 @@ const mocks = vi.hoisted(() => ({
|
||||
getConfig: vi.fn(),
|
||||
listDatabases: vi.fn(),
|
||||
listSchemas: vi.fn(),
|
||||
redisListDatabases: vi.fn(),
|
||||
mongoListDatabases: vi.fn(),
|
||||
listDorisCatalogs: vi.fn(),
|
||||
listDorisCatalogDatabases: vi.fn(),
|
||||
}));
|
||||
@@ -24,6 +26,8 @@ const mocks = vi.hoisted(() => ({
|
||||
vi.mock("@/lib/backend/api", () => ({
|
||||
listDatabases: mocks.listDatabases,
|
||||
listSchemas: mocks.listSchemas,
|
||||
redisListDatabases: mocks.redisListDatabases,
|
||||
mongoListDatabases: mocks.mongoListDatabases,
|
||||
listDorisCatalogs: mocks.listDorisCatalogs,
|
||||
listDorisCatalogDatabases: mocks.listDorisCatalogDatabases,
|
||||
}));
|
||||
@@ -185,3 +189,33 @@ describe("namespace options", () => {
|
||||
expect(mocks.listSchemas).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe("database options loader", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
it("uses the Redis database API", async () => {
|
||||
mocks.getConfig.mockReturnValue({ db_type: "redis" });
|
||||
mocks.redisListDatabases.mockResolvedValue([{ db: 0 }, { db: 1 }]);
|
||||
const options = useDatabaseOptions();
|
||||
|
||||
await options.loadDatabaseOptions("connection-1");
|
||||
|
||||
expect(options.databaseOptions.value["connection-1"]).toEqual(["0", "1"]);
|
||||
expect(mocks.redisListDatabases).toHaveBeenCalledWith("connection-1");
|
||||
expect(mocks.listDatabases).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("uses the MongoDB database API", async () => {
|
||||
mocks.getConfig.mockReturnValue({ db_type: "mongodb" });
|
||||
mocks.mongoListDatabases.mockResolvedValue(["app", "analytics"]);
|
||||
const options = useDatabaseOptions();
|
||||
|
||||
await options.loadDatabaseOptions("connection-1");
|
||||
|
||||
expect(options.databaseOptions.value["connection-1"]).toEqual(["app", "analytics"]);
|
||||
expect(mocks.mongoListDatabases).toHaveBeenCalledWith("connection-1");
|
||||
expect(mocks.listDatabases).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user