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。

1.4 KB
Raw Blame
import { strict as assert } from "node:assert";
import { test } from "vitest";
import { expandNestedJsonStringsForCopy } from "../../apps/desktop/src/lib/common/jsonCopyValue.ts";

test("expands nested JSON strings for copied rows", () => {
  const value = {
    _id: "67218700e884ae1f527640b6",
    accountId: 581,
    data: '{"endingBalance":{"beginningBalance":"0","endingBalance":"20000","endingDate":"2024-10-30"},"financeChargeInfo":null,"interestChargeInfo":null,"Line":[]}',
    status: "draft",
  };

  assert.deepEqual(expandNestedJsonStringsForCopy(value), {
    _id: "67218700e884ae1f527640b6",
    accountId: 581,
    data: {
      endingBalance: {
        beginningBalance: "0",
        endingBalance: "20000",
        endingDate: "2024-10-30",
      },
      financeChargeInfo: null,
      interestChargeInfo: null,
      Line: [],
    },
    status: "draft",
  });
});

test("recursively expands JSON strings in arrays and objects", () => {
  const value = {
    items: ['{"id":1,"meta":"{\\"ok\\":true}"}', "plain text"],
  };

  assert.deepEqual(expandNestedJsonStringsForCopy(value), {
    items: [{ id: 1, meta: { ok: true } }, "plain text"],
  });
});

test("keeps non-object JSON-like cell strings unchanged", () => {
  assert.equal(expandNestedJsonStringsForCopy("123"), "123");
  assert.equal(expandNestedJsonStringsForCopy('"text"'), '"text"');
  assert.equal(expandNestedJsonStringsForCopy("2024-10-30T01:08:14.454Z"), "2024-10-30T01:08:14.454Z");
});