// SPDX-License-Identifier: AGPL-3.0-or-later // M3-T2 in a browser: add a phone number routed to a user and see the inbound dialplan reach the // live Asterisk. Run after m3-t1.mjs (needs its trunk) on the m2-live setup. // Usage: node scripts/e2e/m3-t2.mjs import assert from 'node:assert/strict'; import { spawnSync } from 'node:child_process'; import { launch } from './cdp.mjs'; const AST = 'sp-live-ast'; const sleep = (ms) => new Promise((r) => setTimeout(r, ms)); const cli = (cmd) => spawnSync('docker', ['exec', AST, 'asterisk', '-rx', cmd], { encoding: 'utf8' }).stdout ?? ''; const [base, email, pw, shotsDir] = process.argv.slice(2); const login = await fetch(`${base}/api/auth/login`, { method: 'POST', headers: { 'content-type': 'application/json', 'x-requested-with': 'selfphoneng' }, body: JSON.stringify({ email, password: pw }), }); const cookie = login.headers.get('set-cookie').split(';')[0]; const api = async (method, path, body) => { const r = await fetch(`${base}${path}`, { method, headers: { cookie, 'x-requested-with': 'selfphoneng', 'content-type': 'application/json' }, body: JSON.stringify(body), }); assert.ok(r.ok, `${method} ${path}: ${r.status} ${await r.clone().text()}`); return r.json(); }; const { user } = await api('POST', '/api/users', { email: 'dan@example.com', displayName: 'Dan Doe', }); await api('POST', '/api/extensions', { number: '101', name: 'Dan Doe', userId: user.id }); const p = await launch({ shotsDir }); /** Sets a