From 028d41d585b3df896a96b0efc61b85ae5e48d135 Mon Sep 17 00:00:00 2001 From: "P. Reis" Date: Fri, 14 Feb 2025 11:52:37 -0300 Subject: [PATCH] refactor: use fetch mock --- src/controllers/api/cashu.test.ts | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/src/controllers/api/cashu.test.ts b/src/controllers/api/cashu.test.ts index 7bdb801d..3f53bb10 100644 --- a/src/controllers/api/cashu.test.ts +++ b/src/controllers/api/cashu.test.ts @@ -9,6 +9,12 @@ import { createTestDB, genEvent } from '@/test.ts'; import cashuApp from '@/controllers/api/cashu.ts'; import { walletSchema } from '@/schema.ts'; +import { stub } from '@std/testing/mock'; + +stub(globalThis, 'fetch', () => { + return Promise.resolve(new Response()); +}); + interface AppEnv extends HonoEnv { Variables: { /** Signer to get the logged-in user's pubkey, relays, and to sign events. */ @@ -45,9 +51,9 @@ Deno.test('PUT /wallet must be successful', { headers: [['content-type', 'application/json']], body: JSON.stringify({ mints: [ - 'ditto://houston.mint.com', - 'ditto://houston.mint.com', // duplicate on purpose - 'ditto://cuiaba.mint.com', + 'https://houston.mint.com', + 'https://houston.mint.com', // duplicate on purpose + 'https://cuiaba.mint.com', ], }), }); @@ -75,8 +81,8 @@ Deno.test('PUT /wallet must be successful', { assertEquals(data.pubkey_p2pk, p2pk); assertEquals(data.mints, [ - 'ditto://houston.mint.com', - 'ditto://cuiaba.mint.com', + 'https://houston.mint.com', + 'https://cuiaba.mint.com', ]); assertEquals(data.relays, [ 'ws://localhost:4036/relay', @@ -153,7 +159,7 @@ Deno.test('PUT /wallet must NOT be successful: wallet already exists', async () method: 'PUT', headers: [['content-type', 'application/json']], body: JSON.stringify({ - mints: ['ditto://mint.heart.com'], + mints: ['https://mint.heart.com'], }), }); @@ -191,7 +197,7 @@ Deno.test('GET /wallet must be successful', async () => { pubkey, JSON.stringify([ ['privkey', privkey], - ['mint', 'ditto://mint.soul.com'], + ['mint', 'https://mint.soul.com'], ]), ), }, sk)); @@ -201,7 +207,7 @@ Deno.test('GET /wallet must be successful', async () => { kind: 10019, tags: [ ['pubkey', p2pk], - ['mint', 'ditto://mint.soul.com'], + ['mint', 'https://mint.soul.com'], ], }, sk)); @@ -211,7 +217,7 @@ Deno.test('GET /wallet must be successful', async () => { content: await signer.nip44.encrypt( pubkey, JSON.stringify({ - mint: 'ditto://mint.soul.com', + mint: 'https://mint.soul.com', proofs: [ { id: '005c2502034d4f12', @@ -252,7 +258,7 @@ Deno.test('GET /wallet must be successful', async () => { content: 'Nice post!', tags: [ ['p', pubkey], - ['u', 'ditto://mint.soul.com'], + ['u', 'https://mint.soul.com'], [ 'proof', '{"amount":1,"C":"02277c66191736eb72fce9d975d08e3191f8f96afb73ab1eec37e4465683066d3f","id":"000a93d6f8a1d2c4","secret":"[\\"P2PK\\",{\\"nonce\\":\\"b00bdd0467b0090a25bdf2d2f0d45ac4e355c482c1418350f273a04fedaaee83\\",\\"data\\":\\"02eaee8939e3565e48cc62967e2fde9d8e2a4b3ec0081f29eceff5c64ef10ac1ed\\"}]"}', @@ -269,7 +275,7 @@ Deno.test('GET /wallet must be successful', async () => { assertEquals(response.status, 200); assertEquals(body, { pubkey_p2pk: p2pk, - mints: ['ditto://mint.soul.com'], + mints: ['https://mint.soul.com'], relays: ['ws://localhost:4036/relay'], balance: 100, });