Files
creator-hub/web/tests/error-reason.test.cjs
T
rogee f1a62e25de
douyin-release-gate / verify (push) Failing after 4m22s
feat(account): create browser environments before verified login
2026-10-06 05:55:53 +08:00

19 lines
1.2 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
const assert = require('node:assert/strict');
const { readFileSync } = require('node:fs');
const { test } = require('node:test');
const ts = require('typescript');
const source = readFileSync(`${__dirname}/../src/utils/helpers.ts`, 'utf8');
const compiled = ts.transpileModule(source, { compilerOptions: { module: ts.ModuleKind.CommonJS } }).outputText;
const loaded = { exports: {} };
new Function('module', 'exports', compiled)(loaded, loaded.exports);
const { conflictMessage } = loaded.exports;
test('不可用错误显示后端具体原因,而不是通用 capability 提示', () => {
assert.equal(conflictMessage({ status: 503, message: 'creator capability is unavailable', body: { error: 'creator capability is unavailable', reason: 'browser runtime is not running' } }), 'browser runtime is not running');
});
test('没有具体原因时保留原始错误,409 保留操作提示与原因码', () => {
assert.equal(conflictMessage({ status: 502, message: 'gateway unavailable' }), 'gateway unavailable');
assert.equal(conflictMessage({ status: 409, message: 'conflict', body: { reason_code: 'account_paused' } }, '请恢复账号'), 'conflict:请恢复账号(account_paused)');
});