修改日志显示,合并同一轮中对应的邮箱和手机号

This commit is contained in:
QLHazyCoder
2026-05-05 03:59:09 +08:00
parent c62e1746f8
commit 24f5b79bf1
14 changed files with 377 additions and 42 deletions
@@ -198,6 +198,132 @@ test('account run history helper accepts phone-only records without forcing emai
assert.equal(normalized.finalStatus, 'failed');
});
test('account run history merges email and phone identities from the same run', async () => {
const source = fs.readFileSync('background/account-run-history.js', 'utf8');
const globalScope = {};
const api = new Function('self', `${source}; return self.MultiPageBackgroundAccountRunHistory;`)(globalScope);
let storedHistory = [
{
recordId: 'phone:+447799342687',
accountIdentifierType: 'phone',
accountIdentifier: '+447799342687',
phoneNumber: '+44 7799 342687',
email: '',
password: '',
finalStatus: 'stopped',
finishedAt: '2026-04-17T04:30:00.000Z',
failureDetail: '步骤 2 已使用手机号,流程尚未完成。',
},
{
recordId: 'tmp@example.com',
accountIdentifierType: 'email',
accountIdentifier: 'tmp@example.com',
email: 'tmp@example.com',
phoneNumber: '',
password: 'old',
finalStatus: 'stopped',
finishedAt: '2026-04-17T04:31:00.000Z',
failureDetail: '步骤 2 已使用邮箱,流程尚未完成。',
},
];
const helpers = api.createAccountRunHistoryHelpers({
chrome: {
storage: {
local: {
get: async () => ({ accountRunHistory: storedHistory }),
set: async (payload) => {
storedHistory = payload.accountRunHistory;
},
},
},
},
getState: async () => ({}),
normalizeAccountRunHistoryHelperBaseUrl: () => '',
});
const failedRecord = helpers.buildAccountRunHistoryRecord({
accountIdentifierType: 'email',
accountIdentifier: 'tmp@example.com',
email: 'tmp@example.com',
password: 'secret',
currentPhoneActivation: {
activationId: 'a1',
phoneNumber: '+44 7799 342687',
},
}, 'step9_failed', '步骤 9:手机号验证失败。');
assert.equal(failedRecord.accountIdentifierType, 'email');
assert.equal(failedRecord.accountIdentifier, 'tmp@example.com');
assert.equal(failedRecord.phoneNumber, '+44 7799 342687');
const successRecord = await helpers.appendAccountRunRecord('success', {
accountIdentifierType: 'email',
accountIdentifier: 'tmp@example.com',
email: 'tmp@example.com',
phoneNumber: '447799342687',
password: 'secret',
accountRunHistoryHelperBaseUrl: '',
});
assert.equal(successRecord.recordId, 'tmp@example.com');
assert.equal(successRecord.email, 'tmp@example.com');
assert.equal(successRecord.phoneNumber, '447799342687');
assert.equal(storedHistory.length, 1);
assert.equal(storedHistory[0].recordId, 'tmp@example.com');
assert.equal(storedHistory[0].finalStatus, 'success');
});
test('account run history keeps phone as primary identity when phone signup later binds email', async () => {
const source = fs.readFileSync('background/account-run-history.js', 'utf8');
const globalScope = {};
const api = new Function('self', `${source}; return self.MultiPageBackgroundAccountRunHistory;`)(globalScope);
let storedHistory = [{
recordId: 'phone:+447700900123',
accountIdentifierType: 'phone',
accountIdentifier: '+447700900123',
phoneNumber: '+447700900123',
email: '',
finalStatus: 'stopped',
finishedAt: '2026-04-17T04:31:00.000Z',
failureDetail: '步骤 2 已使用手机号,流程尚未完成。',
}];
const helpers = api.createAccountRunHistoryHelpers({
chrome: {
storage: {
local: {
get: async () => ({ accountRunHistory: storedHistory }),
set: async (payload) => {
storedHistory = payload.accountRunHistory;
},
},
},
},
getState: async () => ({}),
normalizeAccountRunHistoryHelperBaseUrl: () => '',
});
const record = await helpers.appendAccountRunRecord('success', {
accountIdentifierType: 'phone',
accountIdentifier: '+447700900123',
signupPhoneNumber: '+447700900123',
email: 'bound@example.com',
password: 'secret',
accountRunHistoryHelperBaseUrl: '',
});
assert.equal(record.recordId, 'phone:+447700900123');
assert.equal(record.accountIdentifierType, 'phone');
assert.equal(record.accountIdentifier, '+447700900123');
assert.equal(record.email, 'bound@example.com');
assert.equal(record.phoneNumber, '+447700900123');
assert.equal(storedHistory.length, 1);
assert.equal(storedHistory[0].recordId, 'phone:+447700900123');
assert.equal(storedHistory[0].finalStatus, 'success');
});
test('account run history records preserve Plus and contribution mode flags', () => {
const source = fs.readFileSync('background/account-run-history.js', 'utf8');
const globalScope = {};
+1
View File
@@ -1047,6 +1047,7 @@ test('phone verification helper uses HeroSMS getStatusV2 after acquiring a numbe
stateUpdates.some((entry) => entry?.currentPhoneActivation === null && entry?.currentPhoneVerificationCode === ''),
true
);
assert.equal(currentState.phoneNumber, '447911123456');
const actions = requests.map((url) => url.searchParams.get('action'));
assert.deepStrictEqual(actions, [
'getPrices',
@@ -407,3 +407,77 @@ test('account records manager displays phone-only records with account identifie
assert.match(list.innerHTML, /\+6612345/);
assert.doesNotMatch(list.innerHTML, /\(空邮箱\)/);
});
test('account records manager displays combined email and phone identities in one record', () => {
const source = fs.readFileSync('sidepanel/account-records-manager.js', 'utf8');
const windowObject = {};
const api = new Function('window', `${source}; return window.SidepanelAccountRecordsManager;`)(windowObject);
const list = createNode();
const manager = api.createAccountRecordsManager({
state: {
getLatestState: () => ({
accountRunHistory: [
{
recordId: 'phone:+447700900123',
accountIdentifierType: 'phone',
accountIdentifier: '+447700900123',
phoneNumber: '+447700900123',
email: 'bound@example.com',
finalStatus: 'success',
finishedAt: '2026-04-17T04:31:00.000Z',
retryCount: 0,
failureLabel: '流程完成',
},
{
recordId: 'mail@example.com',
accountIdentifierType: 'email',
accountIdentifier: 'mail@example.com',
phoneNumber: '447799342687',
email: 'mail@example.com',
finalStatus: 'failed',
finishedAt: '2026-04-17T04:30:00.000Z',
retryCount: 0,
failureLabel: '步骤 9 失败',
},
],
}),
syncLatestState() {},
},
dom: {
accountRecordsList: list,
accountRecordsMeta: createNode(),
accountRecordsOverlay: createNode(),
accountRecordsPageLabel: createNode(),
accountRecordsStats: createNode(),
btnAccountRecordsNext: createNode(),
btnAccountRecordsPrev: createNode(),
btnClearAccountRecords: createNode(),
btnCloseAccountRecords: createNode(),
btnDeleteSelectedAccountRecords: createNode(),
btnOpenAccountRecords: createNode(),
btnToggleAccountRecordsSelection: createNode(),
},
helpers: {
escapeHtml: (value) => String(value || ''),
},
runtime: {
sendMessage: async () => ({}),
},
constants: {
displayTimeZone: 'Asia/Shanghai',
pageSize: 10,
},
});
manager.render();
assert.match(list.innerHTML, /\+447700900123/);
assert.match(list.innerHTML, /邮箱 bound@example\.com/);
assert.match(list.innerHTML, /mail@example\.com/);
assert.match(list.innerHTML, /绑定手机号 447799342687/);
assert.match(
list.innerHTML,
/title="\+447700900123 \/ 邮箱 bound@example\.com"/
);
});