Files
zeekay e5967776e2 sign-in: the phone step and its numbering plan load when it is chosen
The panel imported the phone step at its top, and with it
libphonenumber's metadata (lib/auth/phone `countries`, `shown`): some
36 KB of compressed script in the first load of every page that draws
the panel, the landing's hero, /login and /signup among them, for a
step a reader reaches only by pressing Continue with phone.

What needs the metadata is lib/auth/dial now; lib/auth/phone keeps the
counts and the consent. The panel loads Dial and Texted with
next/dynamic, and formats the texted number once the plan arrives (the
raw number stands until then). First load, gzip: / 542 -> 506 KB,
/login and /signup 530 -> 490 KB.
2026-10-29 23:20:01 -07:00

43 lines
1.9 KiB
TypeScript
Raw Permalink 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.
import { test, expect } from '@playwright/test'
import { e164 } from '@hanzo/iam/validation'
import { CONSENT, RESEND, TRIES, wait } from '../../lib/auth/phone'
import { countries } from '../../lib/auth/dial'
test('IAM’s own limits: one code per number per 30 seconds, five guesses a code', () => {
expect(RESEND).toBe(30)
expect(TRIES).toBe(5)
})
test('another code waits out the rest of the 30 seconds, and never less than nothing', () => {
expect(wait(0, 0)).toBe(30)
expect(wait(0, 999)).toBe(30)
expect(wait(0, 1000)).toBe(29)
expect(wait(0, 29_999)).toBe(1)
expect(wait(0, 30_000)).toBe(0)
expect(wait(0, 90_000)).toBe(0)
})
test('every country is offered with its calling code, named in the reader’s language', () => {
const en = countries('en')
expect(en.length).toBeGreaterThan(200)
expect(en.find((c) => c.value === 'US')).toEqual({ value: 'US', label: 'United States', callingCode: '1' })
expect(en.find((c) => c.value === 'GB')?.callingCode).toBe('44')
expect(countries('fr').find((c) => c.value === 'DE')?.label).toBe('Allemagne')
// In the locale's order.
const labels = en.map((c) => c.label)
expect(labels).toEqual([...labels].sort((a, b) => a.localeCompare(b, 'en')))
})
test('the number IAM is sent is E.164, the trunk prefix dropped, read in the picked country', () => {
expect(e164('(415) 555-0134', 'US')).toBe('+14155550134')
expect(e164('07911 123456', 'GB')).toBe('+447911123456')
expect(e164('+44 7911 123456', 'US')).toBe('+447911123456')
expect(e164('555', 'US')).toBeNull()
})
test('the consent is hanzo/id’s A2P wording, for Hanzo AI', () => {
expect(CONSENT).toMatch(/^I agree to receive text messages \(SMS\) from Hanzo AI at the number provided,/)
expect(CONSENT).toContain('Reply STOP to opt out at any time, or HELP for help.')
expect(CONSENT).toMatch(/Consent is not a condition of any purchase\.$/)
})