Skip to content

armgit / dbx

Public Imported from GitHub
0

25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。

2.1 KB
Raw Blame
import { describe, expect, it } from "vitest";

import { formatRedisMemberDetail, normalizeRedisJsonDraft } from "@/lib/redis/redisValuePresentation";

/** Owner-review fixture: compact save must not drop the second "role" member. */
const DUPLICATE_MEMBER_COMPACT = '{"role":"reader","role":"writer"}';
const DUPLICATE_MEMBER_PRETTY = `{
  "role": "reader",
  "role": "writer"
}`;

describe("native RedisJSON editor", () => {
  it("string JSON editor open+save keeps duplicate members end-to-end", () => {
    // Open: string JSON view pretty baseline comes from formatRedisMemberDetail.
    const opened = formatRedisMemberDetail(DUPLICATE_MEMBER_COMPACT, { allowJsonText: true });
    expect(opened.json?.formattedText).toBe(DUPLICATE_MEMBER_PRETTY);

    // Save: saveString always compact-writes through normalizeRedisJsonDraft.
    const saved = normalizeRedisJsonDraft(opened.json!.formattedText);
    expect(saved).toEqual({ ok: true, compactText: DUPLICATE_MEMBER_COMPACT });
  });

  it("hash JSON editor open+save keeps duplicate members end-to-end", () => {
    // Open: hash field JSON view uses the same detail pretty baseline.
    const opened = formatRedisMemberDetail(DUPLICATE_MEMBER_COMPACT, { allowJsonText: true });
    expect(opened.json?.formattedText).toBe(DUPLICATE_MEMBER_PRETTY);

    // Save: saveMemberEdit compact-writes hash JSON drafts through the same helper.
    const saved = normalizeRedisJsonDraft(opened.json!.formattedText);
    expect(saved).toEqual({ ok: true, compactText: DUPLICATE_MEMBER_COMPACT });
  });

  it("string and hash serialized JSON editor open+save keeps serialized quotes intact (issue #11636)", () => {
    const SERIALIZED_COMPACT = '"{\\"role\\":\\"reader\\",\\"role\\":\\"writer\\"}"';
    const opened = formatRedisMemberDetail(SERIALIZED_COMPACT, { allowJsonText: true });
    expect(opened.json?.formattedText).toBe(DUPLICATE_MEMBER_PRETTY);
    expect(opened.json?.serializedLevel).toBe(1);

    const saved = normalizeRedisJsonDraft(opened.json!.formattedText, opened.json!.serializedLevel);
    expect(saved).toEqual({ ok: true, compactText: SERIALIZED_COMPACT });
  });
});