Download services/wallet/test/app.test.ts from AnthropicallyHuggingFaces/ProjectOS: direct link, hf CLI and curl.
- Browser
- Download file 2.32 kB
-
https://huggingface.co/spaces/AnthropicallyHuggingFaces/ProjectOS/resolve/main/services/wallet/test/app.test.ts
- Command line
-
hf download hf://spaces/AnthropicallyHuggingFaces/ProjectOS/services/wallet/test/app.test.ts
-
curl -L -o app.test.ts https://huggingface.co/spaces/AnthropicallyHuggingFaces/ProjectOS/resolve/main/services/wallet/test/app.test.ts
2.32 kB
| import { describe, it, expect } from "vitest"; | |
| import type { AddressInfo } from "node:net"; | |
| import { buildApp } from "../src/app.js"; | |
| import { loadConfig } from "../src/config.js"; | |
| import { Ledger } from "../src/ledger.js"; | |
| import { MemoryStore } from "../src/memoryStore.js"; | |
| const base = { WALLET_STORE: "memory", WALLET_USER_ID: "u1" }; | |
| describe("startup without Stripe", () => { | |
| it("config loads without Stripe keys", () => expect(loadConfig(base).STRIPE_SECRET_KEY).toBeUndefined()); | |
| it("still refuses live key when set", () => expect(() => loadConfig({ ...base, STRIPE_SECRET_KEY: "sk_live_x" })).toThrow(/live/)); | |
| it("503s Stripe routes, ledger + invoice routes work", async () => { | |
| const ledger = new Ledger(new MemoryStore()); | |
| await ledger.recordFunding("u1", 1000, "usd", "pi_seed"); | |
| const srv = buildApp(loadConfig(base), ledger, null).listen(0); | |
| const url = `http://127.0.0.1:${(srv.address() as AddressInfo).port}`; | |
| try { | |
| const post = (p: string, b: unknown) => fetch(url + p, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify(b) }); | |
| for (const p of ["/funding/checkout", "/funding/payment-intent", "/webhooks/stripe"]) { | |
| const r = await post(p, { amount: 500 }); | |
| expect(r.status).toBe(503); | |
| expect((await r.json()).error).toBe("Stripe not configured"); | |
| } | |
| const root = await fetch(url + "/"); | |
| expect(root.status).toBe(200); | |
| const html = await root.text(); | |
| expect(await (await fetch(url + "/common.js")).text()).toContain("TEST MODE"); | |
| expect(html).toContain('id="payForm"'); | |
| const links = await (await fetch(url + "/links.json")).json(); | |
| expect(links.apps.map((a: { name: string }) => a.name)).toEqual(["KlawChat","Klaw Command","OpenKlaw","ProcureNet","KlawPay","ProcureMe","ChargeMe"]); | |
| expect((await fetch(url + "/app.js")).status).toBe(200); | |
| expect((await (await fetch(url + "/healthz")).json())).toMatchObject({ ok: true, stripe: false }); | |
| const pay = await post("/invoices/pay", { invoice: { v: 1, invoice_id: "I1", merchant_id: "m", amount: 400, currency: "usd" } }); | |
| expect(pay.status).toBe(200); | |
| expect((await (await fetch(url + "/wallet/balance")).json()).balance).toBe(600); | |
| } finally { srv.close(); } | |
| }); | |
| }); | |