SPB Git

Repository Public

native-peer.ts 1.6 KB 28 lines typescript

1// Companion for testing the native apps against a live server with two throwaway accounts:2// "tester" (the app will join as its second device, with the recovery key) and "echo" (answers every message).3// Usage: SPM_TEST_ORIGIN=https://… tsx tests/native-peer.ts <invite-url-1> <invite-url-2>4import fs from "node:fs"5import { Actor, tokenOf, until } from "./harness"6const [l1, l2] = process.argv.slice(2)7const tester = new Actor("nativetest.one"), echo = new Actor("nativetest.echo")8await tester.register(tokenOf(l1))9await echo.register(tokenOf(l2))10const recovery = await tester.setup()11await echo.setup()12const dm = await tester.engine.createConversation("dm", [echo.me.id])13await tester.engine.send(dm, { t: "text", body: "Premier message, envoyé avant l’ajout de l’app (illisible pour elle)." })14await until(() => echo.engine.convs.has(dm), "echo joined")15fs.writeFileSync("/tmp/spm-native.json", JSON.stringify({ cookie: tester.t.cookie, recovery, dm }))16console.log("READY")17const seen = new Set<string>()18setInterval(() => {19  for (const c of echo.engine.convs.values())20    for (const m of c.messages)21      if (m.kind === "text" && m.from !== echo.me.id && !seen.has(m.id) && m.seq) {22        seen.add(m.id)23        void echo.engine.markRead(c.id)24        if (m.body && !m.body.startsWith("Premier")) void echo.engine.send(c.id, { t: "text", body: `Écho : ${m.body}`, reply: { id: m.id, from: m.from, excerpt: m.body.slice(0, 80) } }).then(() => echo.engine.send(c.id, { t: "react", target: m.id, emoji: "👍", on: true }))25      }26  // approve nothing, never: device approval is tested from the app side27}, 400)28
Files main
Menu

Theme