Files
trade-message-center/apps/server/test/onetalk-image-dimensions-migration.test.ts
T

32 lines
1.2 KiB
TypeScript

// 验证 OneTalk 图片宽高数据迁移的结构边界
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}/0009_remove_image_dimensions.sql`,
import.meta.url,
);
const migrationPath = fileURLToPath(
existsSync(migrationPathUrl)
? migrationPathUrl
: new URL(`../../${migrationDirectory}/0009_remove_image_dimensions.sql`, import.meta.url),
);
test("keeps the image-dimensions migration as one breakpoint-delimited data statement", async () => {
const sql = await readFile(migrationPath, "utf8");
assert.match(sql, /--> statement-breakpoint\s*$/);
assert.match(sql, /UPDATE\s+"onetalk_message"/i);
assert.match(sql, /SET\s+"content"\s*=\s*"content"\s*-\s*'width'\s*-\s*'height'/i);
assert.match(sql, /WHERE\s+"content"\s*->>\s*'kind'\s*=\s*'image'/i);
assert.equal((sql.match(/\bUPDATE\b/gi) ?? []).length, 1);
assert.equal((sql.match(/\bDELETE\b/gi) ?? []).length, 0);
assert.equal((sql.match(/\bALTER\b/gi) ?? []).length, 0);
});