aboutsummaryrefslogtreecommitdiffstats
path: root/test/onchain.test.ts
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2026-03-15 21:53:52 -0700
committerAdam Soltys <[email protected]>2026-03-15 21:53:52 -0700
commitddfe2e3279706f6476364cecfe23427dcabcfd3e (patch)
treef37a2ea3d8e904214c7d8b695c3d87dca7c56466 /test/onchain.test.ts
parentfddfe10f84908c058e239b93985dfe02ba37df04 (diff)
downloadcoinos-server-ddfe2e3279706f6476364cecfe23427dcabcfd3e.tar.gz
coinos-server-ddfe2e3279706f6476364cecfe23427dcabcfd3e.zip
tests
Diffstat (limited to 'test/onchain.test.ts')
-rw-r--r--test/onchain.test.ts86
1 files changed, 42 insertions, 44 deletions
diff --git a/test/onchain.test.ts b/test/onchain.test.ts
index 9850bba3..884bcbc9 100644
--- a/test/onchain.test.ts
+++ b/test/onchain.test.ts
@@ -98,19 +98,30 @@ const resetAll = () => {
seedUser(makeUser());
};
-const makeRes = () => {
+const makeContext = (opts: { body?: any; user?: any } = {}) => {
let sent: any;
- return {
- send: (data: any) => {
+ const ctx: any = {
+ req: {
+ json: async () => opts.body,
+ header: () => undefined,
+ path: "/test",
+ method: "POST",
+ query: () => ({}),
+ raw: { clone: () => ({ json: async () => opts.body }) },
+ },
+ get: (key: string) => {
+ if (key === "user") return opts.user;
+ return undefined;
+ },
+ set: () => {},
+ json: (data: any, _status?: number) => {
sent = data;
+ return new Response(JSON.stringify(data), { status: _status || 200 });
},
- code: (_code: number) => ({
- send: (data: any) => {
- sent = data;
- },
- }),
+ env: {},
getSent: () => sent,
};
+ return ctx;
};
// =====================================================================
@@ -325,13 +336,12 @@ describe("confirm (liquid)", () => {
beforeEach(resetAll);
test("ignores non-liquid types", async () => {
- const req = {
+ const ctx = makeContext({
body: { txid: "btctx100", wallet: "test", type: PaymentType.bitcoin },
- };
- const res = makeRes();
+ });
- await routes.confirm(req as any, res as any);
- expect((res as any).getSent()).toEqual({});
+ await routes.confirm(ctx);
+ expect(ctx.getSent()).toEqual({});
expect(mockTbCredit).not.toHaveBeenCalled();
});
@@ -354,13 +364,11 @@ describe("confirm (liquid)", () => {
}),
};
- const req = {
+ const ctx = makeContext({
body: { txid: "lqtx001", wallet: "test", type: PaymentType.liquid },
- };
- const res = makeRes();
-
- await routes.confirm(req as any, res as any);
- expect((res as any).getSent()).toEqual({});
+ });
+ await routes.confirm(ctx);
+ expect(ctx.getSent()).toEqual({});
// Payment should be created via credit()
const pid = JSON.parse(store().kvStore[`payment:lqtx001:0`]);
@@ -401,12 +409,10 @@ describe("confirm (liquid)", () => {
}),
};
- const req = {
+ const ctx = makeContext({
body: { txid: "lqtx002", wallet: "test", type: PaymentType.liquid },
- };
- const res = makeRes();
-
- await routes.confirm(req as any, res as any);
+ });
+ await routes.confirm(ctx);
// Payment confirmed
const p = JSON.parse(store().kvStore[`payment:${pendingPayment.id}`]);
@@ -437,12 +443,10 @@ describe("confirm (liquid)", () => {
}),
};
- const req = {
+ const ctx = makeContext({
body: { txid: "lqtx003", wallet: "test", type: PaymentType.liquid },
- };
- const res = makeRes();
-
- await routes.confirm(req as any, res as any);
+ });
+ await routes.confirm(ctx);
expect(mockTbCredit).not.toHaveBeenCalled();
expect(mockTbConfirm).not.toHaveBeenCalled();
});
@@ -463,12 +467,10 @@ describe("confirm (liquid)", () => {
}),
};
- const req = {
+ const ctx = makeContext({
body: { txid: "lqtx004", wallet: "test", type: PaymentType.liquid },
- };
- const res = makeRes();
-
- await routes.confirm(req as any, res as any);
+ });
+ await routes.confirm(ctx);
expect(mockTbCredit).not.toHaveBeenCalled();
});
@@ -494,12 +496,10 @@ describe("confirm (liquid)", () => {
}),
};
- const req = {
+ const ctx = makeContext({
body: { txid: "lqtx005", wallet: "test", type: PaymentType.liquid },
- };
- const res = makeRes();
-
- await routes.confirm(req as any, res as any);
+ });
+ await routes.confirm(ctx);
expect(mockTbCredit).not.toHaveBeenCalled();
});
@@ -533,12 +533,10 @@ describe("confirm (liquid)", () => {
}),
};
- const req = {
+ const ctx = makeContext({
body: { txid: "lqtx006", wallet: "test", type: PaymentType.liquid },
- };
- const res = makeRes();
-
- await routes.confirm(req as any, res as any);
+ });
+ await routes.confirm(ctx);
expect(mockTbConfirm).not.toHaveBeenCalled();
});
});