43 lines
1.3 KiB
JavaScript
43 lines
1.3 KiB
JavaScript
|
|
// End-to-end smoke test of the live SignalR backend (server must be running).
|
||
|
|
import { HubConnectionBuilder, LogLevel } from "@microsoft/signalr";
|
||
|
|
|
||
|
|
const SERVER = "http://localhost:5005";
|
||
|
|
|
||
|
|
const res = await fetch(`${SERVER}/api/auth/otp/verify`, {
|
||
|
|
method: "POST",
|
||
|
|
headers: { "Content-Type": "application/json" },
|
||
|
|
body: JSON.stringify({ phone: "0912", code: "1234", name: "Tester" }),
|
||
|
|
});
|
||
|
|
const { token, userId } = await res.json();
|
||
|
|
if (!token) throw new Error("no token");
|
||
|
|
|
||
|
|
const conn = new HubConnectionBuilder()
|
||
|
|
.withUrl(`${SERVER}/hub/game`, { accessTokenFactory: () => token })
|
||
|
|
.configureLogging(LogLevel.Error)
|
||
|
|
.build();
|
||
|
|
|
||
|
|
let matchFound = false;
|
||
|
|
let states = 0;
|
||
|
|
let sawHand = false;
|
||
|
|
let phases = new Set();
|
||
|
|
let mySeat = null;
|
||
|
|
|
||
|
|
conn.on("matchFound", (m) => { matchFound = true; mySeat = m.seat; });
|
||
|
|
conn.on("state", (s) => {
|
||
|
|
states++;
|
||
|
|
phases.add(s.phase);
|
||
|
|
const me = s.players.find((p) => p.seat === s.mySeat);
|
||
|
|
if (me?.hand?.length) sawHand = true;
|
||
|
|
});
|
||
|
|
|
||
|
|
await conn.start();
|
||
|
|
await conn.invoke("StartMatchmaking", { name: "Tester", avatar: "a-fox", level: 3, plan: "pro" });
|
||
|
|
await new Promise((r) => setTimeout(r, 7000));
|
||
|
|
|
||
|
|
console.log(JSON.stringify({
|
||
|
|
userId, matchFound, mySeat, states, sawHand, phases: [...phases],
|
||
|
|
}));
|
||
|
|
|
||
|
|
await conn.stop();
|
||
|
|
process.exit(0);
|