Files
plugins/packages/qoder/phone-label.test.mjs
T
MYCF711 421cad6b25 qoder 0.2.50: a phone account's card shows its phone, not its uuid (#487)
A Qoder CN / QwenWork phone account's card shows its masked phone
(phoneLabel / cardName, usage's `user`), a real email first, instead of its
uuid; accountId stays exactly what main computes. A renewal reads the name
outside the plugin-wide lock from the account's own site (a VPC token never
goes to the public hosts) and renames nothing. Rebased on a06512e, keeping
3c279f6's listing-renew change.

Reviewed at 6e39e8c (round 5). Run on mote (macOS, Bun 1.4.2) in a sandbox
HOME, at that head:
- bun test packages/qoder: 335 pass / 0 fail (listing-renew.test.mjs 5/0)
- bun scripts/check.mjs qoder: ok
Broken by hand: the device sign-in's cardName `realEmailOf(email) || label`
-> `label` (index.mjs:411) turns "qoder-cn: a device sign-in with an email
and a phone shows the email" red (334/1). Earlier rounds' breaks (renewal
cardName, own site, usage `who`) were red too.
CI (test, on-npm) green at 6e39e8c. Version 0.2.49 -> 0.2.50.
Not tried: a real Qoder CN or QwenWork phone account.
2026-10-29 21:35:38 +08:00

38 lines
1.8 KiB
JavaScript

// The card's name: what a phone sign-in shows, and the uuid it used to show.
//
// Both sites answer a phone account differently — Qoder CN gives the full
// number as `security_mobile`, QwenWork gives four digits as `name` beside a
// synthetic `phone_<uuid>@phone.local` email — and the card used to show a
// uuid for either. These lock the label, not the sign-in.
import { expect, test } from "bun:test"
import { _internal as x } from "./index.mjs"
test("maskPhone: 0086- / +86 / bare / already masked, always 3+4", () => {
expect(x.maskPhone("0086-13800138000")).toBe("138****8000")
expect(x.maskPhone("+86 138 0013 8000")).toBe("138****8000")
expect(x.maskPhone("13800138000")).toBe("138****8000")
// already masked → fewer than 11 digits → not a number to mask again
expect(x.maskPhone("139****1234")).toBe("")
// not a number → empty, so the label falls through to the next candidate
expect(x.maskPhone("")).toBe("")
expect(x.maskPhone(undefined)).toBe("")
expect(x.maskPhone("123")).toBe("")
// a number that merely starts with 86 is not a country code either
expect(x.maskPhone("86123456789")).toBe("")
})
test("phoneLabelOf: the phone, or a synthetic email's four digits, else nothing", () => {
expect(x.phoneLabelOf({ security_mobile: "13800138000" }, "", "")).toBe("138****8000")
const synthetic = "phone_66666666-7777-8888-9999-000000000000@phone.local"
expect(x.phoneLabelOf({ name: "8000", email: synthetic }, synthetic, "8000")).toBe("****8000")
expect(x.phoneLabelOf({ id: "u1" }, "", "")).toBe("")
})
test("realEmailOf: a real email, never a synthetic phone one", () => {
expect(x.realEmailOf("someone@example.com")).toBe("someone@example.com")
expect(x.realEmailOf("phone_66666666-7777-8888-9999-000000000000@phone.local")).toBe("")
expect(x.realEmailOf("")).toBe("")
expect(x.realEmailOf(undefined)).toBe("")
})