import { describe, it, expect } from "vitest"; import { BalanceSchema, TopupSchema, PaymentsSchema, AuthRequestSchema, TgSessionSchema, TgPollSchema } from "./driver"; describe("driver api schemas", () => { it("parses balance", () => { const v = BalanceSchema.parse({ accounts: [{ bucket: "Долг аренда", balance: -3200 }] }); expect(v.accounts[0].bucket).toBe("Долг аренда"); }); it("parses topup", () => { const v = TopupSchema.parse({ order_id: "o1", pay_url: "https://x", commission: 52, total: 1052 }); expect(v.pay_url).toBe("https://x"); }); it("parses auth request onboarding + code_sent", () => { expect(AuthRequestSchema.parse({ status: "code_sent", channel: "tg" }).status).toBe("code_sent"); const pair = { pair_session: "S", poll_secret: "SEC", confirm_code: "4217" }; const o = AuthRequestSchema.parse({ status: "onboarding", deep_links: { tg: "t", max: "m" }, ...pair }); expect(o.status === "onboarding" && o.deep_links.tg).toBe("t"); // prod: MAX bot not configured → backend omits `max`, must still parse (regression guard) const tgOnly = AuthRequestSchema.parse({ status: "onboarding", deep_links: { tg: "t" }, ...pair }); expect(tgOnly.status === "onboarding" && tgOnly.deep_links.tg).toBe("t"); }); it("parses payments history", () => { const v = PaymentsSchema.parse({ payments: [{ order_id: "o1", bucket: "b", amount: 100, commission: 5.2, method: "qr", status: "PAID", created_at: "2026-06-18T09:00:00Z", paid_at: null }] }); expect(v.payments[0].status).toBe("PAID"); }); }); describe("tg verified-login schemas", () => { it("parses tg session", () => { const v = TgSessionSchema.parse({ pair_session: "S", poll_secret: "SEC", confirm_code: "4217", deep_link: "https://t.me/x?start=S" }); expect(v.pair_session).toBe("S"); expect(v.poll_secret).toBe("SEC"); // вторая половина ключа в deep-link не уходит expect(v.deep_link).not.toContain("SEC"); }); it("parses tg poll states", () => { expect(TgPollSchema.parse({ status: "pending" }).status).toBe("pending"); expect(TgPollSchema.parse({ status: "expired" }).status).toBe("expired"); const a = TgPollSchema.parse({ status: "authenticated", token: "T", driver_id: 7 }); expect(a.status === "authenticated" && a.token).toBe("T"); }); });