1 parent
4329ec51db
commit
20c50550cf
13 files changed
+380
-13
No files matched your search
@@ -0,0 +1,66 @@
|
||||
// @vitest-environment happy-dom
|
||||
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
const CONFIG_KEY = "dbx-schema-diff-configs";
|
||||
const HISTORY_KEY = "dbx-schema-diff-history";
|
||||
|
||||
function storedConfig(compareCharset?: boolean) {
|
||||
return {
|
||||
id: "saved",
|
||||
name: "Saved",
|
||||
createdAt: 1,
|
||||
updatedAt: 1,
|
||||
sourceConnectionId: "source",
|
||||
sourceDatabase: "app",
|
||||
sourceSchema: "",
|
||||
targetConnectionId: "target",
|
||||
targetDatabase: "app_copy",
|
||||
targetSchema: "",
|
||||
options: {
|
||||
tables: true,
|
||||
...(compareCharset === undefined ? {} : { compareCharset }),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
describe("schema diff charset option persistence", () => {
|
||||
beforeEach(() => {
|
||||
localStorage.clear();
|
||||
vi.resetModules();
|
||||
});
|
||||
|
||||
it("migrates legacy saved configs and history entries to comparison enabled", async () => {
|
||||
localStorage.setItem(CONFIG_KEY, JSON.stringify([storedConfig()]));
|
||||
localStorage.setItem(HISTORY_KEY, JSON.stringify([storedConfig()]));
|
||||
|
||||
const { useSchemaDiffConfig } = await import("../useSchemaDiffConfig");
|
||||
const state = useSchemaDiffConfig();
|
||||
|
||||
expect(state.configs.value[0].options.compareCharset).toBe(true);
|
||||
expect(state.recentConfigs.value[0].options.compareCharset).toBe(true);
|
||||
expect(JSON.parse(localStorage.getItem(CONFIG_KEY) ?? "[]")[0].options.compareCharset).toBe(true);
|
||||
expect(JSON.parse(localStorage.getItem(HISTORY_KEY) ?? "[]")[0].options.compareCharset).toBe(true);
|
||||
});
|
||||
|
||||
it("preserves and persists an explicitly disabled value", async () => {
|
||||
localStorage.setItem(CONFIG_KEY, JSON.stringify([storedConfig(false)]));
|
||||
|
||||
const { useSchemaDiffConfig } = await import("../useSchemaDiffConfig");
|
||||
const state = useSchemaDiffConfig();
|
||||
state.activeConfigId.value = "saved";
|
||||
|
||||
expect(state.activeConfig.value?.options.compareCharset).toBe(false);
|
||||
state.updateActiveConfigOptions({ ...state.activeConfig.value!.options, compareCharset: false });
|
||||
expect(JSON.parse(localStorage.getItem(CONFIG_KEY) ?? "[]")[0].options.compareCharset).toBe(false);
|
||||
});
|
||||
|
||||
it("migrates legacy imported configs before persisting them", async () => {
|
||||
const { useSchemaDiffConfig } = await import("../useSchemaDiffConfig");
|
||||
const state = useSchemaDiffConfig();
|
||||
|
||||
expect(state.importConfigs(JSON.stringify(storedConfig()), "replace")).toEqual({ imported: 1, renamed: 0 });
|
||||
expect(state.configs.value[0].options.compareCharset).toBe(true);
|
||||
expect(JSON.parse(localStorage.getItem(CONFIG_KEY) ?? "[]")[0].options.compareCharset).toBe(true);
|
||||
});
|
||||
});
|
||||
@@ -31,6 +31,7 @@ async function waitForSession(session: { status: string }) {
|
||||
test("defaults enable tables and functions compare for common targets", () => {
|
||||
assert.equal(DEFAULT_MYSQL_OPTIONS.tables, true);
|
||||
assert.equal(DEFAULT_MYSQL_OPTIONS.functions, true);
|
||||
assert.equal(DEFAULT_MYSQL_OPTIONS.compareCharset, true);
|
||||
assert.equal(getDefaultOptionsForDbType("oracle").tables, true);
|
||||
assert.equal(getDefaultOptionsForDbType("oracle").functions, true);
|
||||
assert.equal(getDefaultOptionsForDbType("mysql").tables, true);
|
||||
@@ -82,12 +83,49 @@ test("runs a schema diff session after the dialog is closed and retains the prep
|
||||
assert.equal(trackerMock.updateCompareTask.mock.calls.at(-1)?.[1].status, "Done");
|
||||
// MySQL defaults now enable functions compare for same-dialect pairs.
|
||||
assert.equal(apiMock.listFunctions.mock.calls.length, 2);
|
||||
assert.equal(apiMock.prepareSchemaDiff.mock.calls[0]?.[0]?.compareCharset, true);
|
||||
|
||||
const onOpen = trackerMock.addSchemaDiffTask.mock.calls[0]?.[2] as (() => void) | undefined;
|
||||
onOpen?.();
|
||||
assert.equal(openMock.mock.calls.at(-1)?.[0], session.id);
|
||||
});
|
||||
|
||||
test("forwards a disabled charset comparison to the backend", async () => {
|
||||
apiMock.prepareSchemaDiff.mockClear();
|
||||
apiMock.prepareSchemaDiff.mockResolvedValue({
|
||||
diffs: [],
|
||||
functionDiffs: [],
|
||||
sequenceDiffs: [],
|
||||
ruleDiffs: [],
|
||||
ownerDiffs: [],
|
||||
renameCandidates: [],
|
||||
syncSql: "",
|
||||
rollbackSyncSql: "",
|
||||
});
|
||||
|
||||
const session = startSchemaDiffSession(
|
||||
{
|
||||
sourceConnectionId: "source",
|
||||
sourceDatabase: "app",
|
||||
sourceSchema: "",
|
||||
targetConnectionId: "target",
|
||||
targetDatabase: "warehouse",
|
||||
targetSchema: "",
|
||||
sourceDbType: "mysql",
|
||||
targetDbType: "mysql",
|
||||
options: { compareCharset: false },
|
||||
ignoreComments: false,
|
||||
label: "charset disabled",
|
||||
},
|
||||
{ tableListLoader: { load: vi.fn().mockResolvedValue([]) } },
|
||||
);
|
||||
|
||||
await waitForSession(session);
|
||||
|
||||
assert.equal(session.status, "completed");
|
||||
assert.equal(apiMock.prepareSchemaDiff.mock.calls[0]?.[0]?.compareCharset, false);
|
||||
});
|
||||
|
||||
test("loads routines for mysql↔mysql when functions is enabled", async () => {
|
||||
apiMock.prepareSchemaDiff.mockClear();
|
||||
apiMock.listFunctions.mockClear();
|
||||
|
||||
Reference in new issue
Block a user