fix(gpc): consume local helper OTP by selected record
This commit is contained in:
@@ -135,3 +135,67 @@ print(json.dumps(payload))
|
||||
global_after: '222222',
|
||||
});
|
||||
});
|
||||
|
||||
test('GPC SMS helper consume keeps newer same-phone OTP when consuming an older record', () => {
|
||||
const code = `
|
||||
import importlib.util
|
||||
import json
|
||||
|
||||
script_path = ${JSON.stringify(scriptPath)}
|
||||
spec = importlib.util.spec_from_file_location("gpc_sms_helper_macos", script_path)
|
||||
module = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(module)
|
||||
|
||||
record_old = {
|
||||
"otp": "111111",
|
||||
"code": "111111",
|
||||
"message_id": "old",
|
||||
"rowid": 1,
|
||||
"phone_e164": "+8613800138000",
|
||||
"account_phone": "+8613800138000",
|
||||
"received_at": "2026-05-05T00:00:00+00:00",
|
||||
}
|
||||
record_new = {
|
||||
"otp": "222222",
|
||||
"code": "222222",
|
||||
"message_id": "new",
|
||||
"rowid": 2,
|
||||
"phone_e164": "+8613800138000",
|
||||
"account_phone": "+8613800138000",
|
||||
"received_at": "2026-05-05T00:00:10+00:00",
|
||||
}
|
||||
record_other = {
|
||||
"otp": "333333",
|
||||
"code": "333333",
|
||||
"message_id": "other",
|
||||
"rowid": 3,
|
||||
"phone_e164": "+8618984829950",
|
||||
"account_phone": "+8618984829950",
|
||||
"received_at": "2026-05-05T00:00:20+00:00",
|
||||
}
|
||||
module.STATE.update({"last_otp": record_new, "otps": [record_new, record_old, record_other]})
|
||||
module.consume_otp_record(phone="+8613800138000", record=record_old)
|
||||
state_after = module.get_state()
|
||||
payload = {
|
||||
"same_phone_after": module.select_otp_record(state_after, phone="+8613800138000")["otp"],
|
||||
"other_phone_after": module.select_otp_record(state_after, phone="+8618984829950")["otp"],
|
||||
"records_after": [item["message_id"] for item in state_after.get("otps", [])],
|
||||
"global_after": module.select_otp_record(state_after)["otp"],
|
||||
}
|
||||
print(json.dumps(payload))
|
||||
`;
|
||||
const run = runPython(['-c', code], {
|
||||
timeout: 3000,
|
||||
env: { GPC_SMS_HELPER_ALLOW_NON_MAC: '1' },
|
||||
});
|
||||
if (!run) {
|
||||
return;
|
||||
}
|
||||
assert.equal(run.status, 0, run.stderr);
|
||||
assert.deepEqual(JSON.parse(run.stdout.trim()), {
|
||||
same_phone_after: '222222',
|
||||
other_phone_after: '333333',
|
||||
records_after: ['new', 'other'],
|
||||
global_after: '222222',
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user