Files
trade-message-center/apps/server/test/onetalk-business-card-marker-migration.test.ts
T

32 lines
1.3 KiB
TypeScript

// 验证 OneTalk 名片资料从消息 JSONB 中移除的迁移边界
import assert from "node:assert/strict";
import { existsSync } from "node:fs";
import { readFile } from "node:fs/promises";
import { fileURLToPath } from "node:url";
import test from "node:test";
import { migrationDirectory } from "../src/database/migration-config.ts";
const migrationPathUrl = new URL(
`../${migrationDirectory}/0011_mushy_baron_strucker.sql`,
import.meta.url,
);
const migrationPath = fileURLToPath(
existsSync(migrationPathUrl)
? migrationPathUrl
: new URL(`../../${migrationDirectory}/0011_mushy_baron_strucker.sql`, import.meta.url),
);
test("normalizes every persisted business-card payload before enforcing the marker-only check", async () => {
const sql = await readFile(migrationPath, "utf8");
assert.match(sql, /DROP CONSTRAINT\s+"onetalk_message_content_v1_chk"/i);
assert.match(sql, /UPDATE\s+"onetalk_message"\s+SET\s+"content"\s*=/i);
assert.match(sql, /WHERE\s+"content"\s*->>\s*'kind'\s*=\s*'business_card'/i);
assert.match(sql, /\{"version":1,"kind":"business_card"\}/);
assert.match(sql, /ADD CONSTRAINT\s+"onetalk_message_content_v1_chk"/i);
assert.equal((sql.match(/\bUPDATE\b/gi) ?? []).length, 1);
assert.equal((sql.match(/--> statement-breakpoint/g) ?? []).length, 2);
});