mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-04-07 14:41:19 +08:00
Each OMO provider now stores its complete configuration directly in settings_config.otherFields instead of relying on a shared OmoGlobalConfig merged at write time. This simplifies the data flow from a 4-tuple (agents, categories, otherFields, useCommonConfig) to a 3-tuple and eliminates an entire DB table, two Tauri commands, and ~1700 lines of merge/sync code across frontend and backend. Backend: - Delete database/dao/omo.rs (OmoGlobalConfig struct + get/save methods) - Remove get/set_config_snippet from settings DAO - Remove get/set_common_config_snippet Tauri commands - Replace merge_config() with build_config() in services/omo.rs - Simplify OmoVariant (remove config_key, known_keys) - Simplify import_from_local and build_local_file_data - Rewrite all OMO service tests Frontend: - Delete OmoCommonConfigEditor.tsx and OmoGlobalConfigFields.tsx - Delete src/lib/api/config.ts - Remove OmoGlobalConfig type and merge preview functions - Remove useGlobalConfig/useSaveGlobalConfig query hooks - Simplify useOmoDraftState (remove all common config state) - Replace OmoCommonConfigEditor with read-only JsonEditor preview - Clean i18n keys (zh/en/ja)
31 lines
940 B
TypeScript
31 lines
940 B
TypeScript
import { describe, expect, it } from "vitest";
|
|
import {
|
|
buildOmoProfilePreview,
|
|
parseOmoOtherFieldsObject,
|
|
} from "@/types/omo";
|
|
|
|
describe("parseOmoOtherFieldsObject", () => {
|
|
it("解析对象 JSON", () => {
|
|
expect(parseOmoOtherFieldsObject('{ "foo": 1 }')).toEqual({ foo: 1 });
|
|
});
|
|
|
|
it("数组/字符串返回 undefined", () => {
|
|
expect(parseOmoOtherFieldsObject('["a"]')).toBeUndefined();
|
|
expect(parseOmoOtherFieldsObject('"hello"')).toBeUndefined();
|
|
});
|
|
|
|
it("非法 JSON 抛出异常", () => {
|
|
expect(() => parseOmoOtherFieldsObject("{")).toThrow();
|
|
});
|
|
});
|
|
|
|
describe("buildOmoProfilePreview", () => {
|
|
it("只合并 otherFields 的对象值,忽略数组", () => {
|
|
const fromArray = buildOmoProfilePreview({}, {}, '["a", "b"]');
|
|
expect(fromArray).toEqual({});
|
|
|
|
const fromObject = buildOmoProfilePreview({}, {}, '{ "foo": "bar" }');
|
|
expect(fromObject).toEqual({ foo: "bar" });
|
|
});
|
|
});
|