79 lines
3.2 KiB
JavaScript
79 lines
3.2 KiB
JavaScript
const assert = require('assert');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
const vm = require('vm');
|
|
|
|
const appSource = fs.readFileSync(path.join(__dirname, '..', 'public', 'app.js'), 'utf8');
|
|
const context = vm.createContext({
|
|
console,
|
|
Set,
|
|
Map,
|
|
Date,
|
|
JSON,
|
|
Math,
|
|
String,
|
|
Object,
|
|
Array,
|
|
RegExp,
|
|
setTimeout,
|
|
clearTimeout,
|
|
});
|
|
vm.runInContext(`${appSource}\nthis.__geminiApp = geminiApp;`, context, { filename: 'public/app.js' });
|
|
|
|
const app = context.__geminiApp();
|
|
app.accountLogs = {};
|
|
app.accounts = [
|
|
{ email: 'network@example.com', status_reason: 'NETWORK_PROXY', message: '代理连接异常,页面加载失败' },
|
|
{ email: 'oauth@example.com', status_reason: 'OAUTH_CHALLENGE_STUCK', message: 'OAuth身份验证页面无法切换到其它方式:/v3/signin/challenge/dp' },
|
|
{ email: 'twofa@example.com', status_reason: 'TOTP_KEY_INCORRECT', message: 'Wrong code. Try again.' },
|
|
{ email: 'login@example.com', status_reason: 'RISK', message: '历史风控详情' },
|
|
{ email: 'password@example.com', message: '登录失败:密码错误' },
|
|
{ email: 'password-changed@example.com', status_reason: 'PASSWORD_CHANGED_RECENTLY', message: 'Your password was changed 10 days ago' },
|
|
{ email: 'captcha@example.com', status_reason: 'CAPTCHA', message: '触发人机验证' },
|
|
];
|
|
app._accountByEmail = new Map(app.accounts.map(account => [account.email, account]));
|
|
|
|
assert.strictEqual(app._getAccountFailureLabel(app.accounts[0]), '切换ip重试');
|
|
assert.strictEqual(app._getAccountFailureLabel(app.accounts[1]), '要等7天');
|
|
assert.strictEqual(app._getAccountFailureLabel(app.accounts[2]), '2fa密钥不正确');
|
|
assert.strictEqual(app._getAccountFailureLabel(app.accounts[3]), '无法登录');
|
|
assert.strictEqual(app._getAccountFailureLabel(app.accounts[4]), '密码错误');
|
|
assert.strictEqual(app._getAccountFailureLabel(app.accounts[5]), '密码已被修改');
|
|
assert.strictEqual(app._getAccountFailureLabel(app.accounts[6]), '人机验证');
|
|
|
|
for (const [keyword, email] of [
|
|
['切换ip重试', 'network@example.com'],
|
|
['要等7天', 'oauth@example.com'],
|
|
['2fa密钥不正确', 'twofa@example.com'],
|
|
['无法登录', 'login@example.com'],
|
|
['密码错误', 'password@example.com'],
|
|
['密码已被修改', 'password-changed@example.com'],
|
|
['人机验证', 'captcha@example.com'],
|
|
]) {
|
|
const account = app.accounts.find(item => item.email === email);
|
|
assert.strictEqual(app._matchSearch(account, keyword), true, `${keyword} 应可直接搜索到对应账号`);
|
|
}
|
|
|
|
assert.strictEqual(app.getLiveMessage(app.accounts[1]), '要等7天');
|
|
assert.strictEqual(
|
|
app._isOAuthWait7Account({
|
|
ag_status: '可重新授权',
|
|
status_reason: 'OAUTH_CHALLENGE_STUCK',
|
|
message: '要等7天',
|
|
}),
|
|
true,
|
|
'本次 OAuth 等待原因应覆盖旧的“可重新授权”状态',
|
|
);
|
|
|
|
app._queueAccountUpdate({
|
|
email: 'oauth@example.com',
|
|
message: '要等7天',
|
|
status_reason: 'OAUTH_TIMEOUT',
|
|
failure_label: '要等7天',
|
|
ag_status: 'OAuth等待7天',
|
|
});
|
|
app._flushAccountUpdates();
|
|
assert.strictEqual(app.accounts[1].ag_status, 'OAuth等待7天', 'SSE 应实时同步等待7天分组状态');
|
|
|
|
console.log('failure_label_search.test.js: PASS');
|