mirror of
https://github.com/hanzo-apps/hanzo.ai.git
synced 2026-10-30 14:58:08 +00:00
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.
43 lines
1.9 KiB
TypeScript
43 lines
1.9 KiB
TypeScript
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\.$/)
|
||
})
|