refactor: use fetch mock

This commit is contained in:
P. Reis 2025-02-14 11:52:37 -03:00
parent cb475f1126
commit 028d41d585

View file

@ -9,6 +9,12 @@ import { createTestDB, genEvent } from '@/test.ts';
import cashuApp from '@/controllers/api/cashu.ts'; import cashuApp from '@/controllers/api/cashu.ts';
import { walletSchema } from '@/schema.ts'; import { walletSchema } from '@/schema.ts';
import { stub } from '@std/testing/mock';
stub(globalThis, 'fetch', () => {
return Promise.resolve(new Response());
});
interface AppEnv extends HonoEnv { interface AppEnv extends HonoEnv {
Variables: { Variables: {
/** Signer to get the logged-in user's pubkey, relays, and to sign events. */ /** 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']], headers: [['content-type', 'application/json']],
body: JSON.stringify({ body: JSON.stringify({
mints: [ mints: [
'ditto://houston.mint.com', 'https://houston.mint.com',
'ditto://houston.mint.com', // duplicate on purpose 'https://houston.mint.com', // duplicate on purpose
'ditto://cuiaba.mint.com', 'https://cuiaba.mint.com',
], ],
}), }),
}); });
@ -75,8 +81,8 @@ Deno.test('PUT /wallet must be successful', {
assertEquals(data.pubkey_p2pk, p2pk); assertEquals(data.pubkey_p2pk, p2pk);
assertEquals(data.mints, [ assertEquals(data.mints, [
'ditto://houston.mint.com', 'https://houston.mint.com',
'ditto://cuiaba.mint.com', 'https://cuiaba.mint.com',
]); ]);
assertEquals(data.relays, [ assertEquals(data.relays, [
'ws://localhost:4036/relay', 'ws://localhost:4036/relay',
@ -153,7 +159,7 @@ Deno.test('PUT /wallet must NOT be successful: wallet already exists', async ()
method: 'PUT', method: 'PUT',
headers: [['content-type', 'application/json']], headers: [['content-type', 'application/json']],
body: JSON.stringify({ 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, pubkey,
JSON.stringify([ JSON.stringify([
['privkey', privkey], ['privkey', privkey],
['mint', 'ditto://mint.soul.com'], ['mint', 'https://mint.soul.com'],
]), ]),
), ),
}, sk)); }, sk));
@ -201,7 +207,7 @@ Deno.test('GET /wallet must be successful', async () => {
kind: 10019, kind: 10019,
tags: [ tags: [
['pubkey', p2pk], ['pubkey', p2pk],
['mint', 'ditto://mint.soul.com'], ['mint', 'https://mint.soul.com'],
], ],
}, sk)); }, sk));
@ -211,7 +217,7 @@ Deno.test('GET /wallet must be successful', async () => {
content: await signer.nip44.encrypt( content: await signer.nip44.encrypt(
pubkey, pubkey,
JSON.stringify({ JSON.stringify({
mint: 'ditto://mint.soul.com', mint: 'https://mint.soul.com',
proofs: [ proofs: [
{ {
id: '005c2502034d4f12', id: '005c2502034d4f12',
@ -252,7 +258,7 @@ Deno.test('GET /wallet must be successful', async () => {
content: 'Nice post!', content: 'Nice post!',
tags: [ tags: [
['p', pubkey], ['p', pubkey],
['u', 'ditto://mint.soul.com'], ['u', 'https://mint.soul.com'],
[ [
'proof', 'proof',
'{"amount":1,"C":"02277c66191736eb72fce9d975d08e3191f8f96afb73ab1eec37e4465683066d3f","id":"000a93d6f8a1d2c4","secret":"[\\"P2PK\\",{\\"nonce\\":\\"b00bdd0467b0090a25bdf2d2f0d45ac4e355c482c1418350f273a04fedaaee83\\",\\"data\\":\\"02eaee8939e3565e48cc62967e2fde9d8e2a4b3ec0081f29eceff5c64ef10ac1ed\\"}]"}', '{"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(response.status, 200);
assertEquals(body, { assertEquals(body, {
pubkey_p2pk: p2pk, pubkey_p2pk: p2pk,
mints: ['ditto://mint.soul.com'], mints: ['https://mint.soul.com'],
relays: ['ws://localhost:4036/relay'], relays: ['ws://localhost:4036/relay'],
balance: 100, balance: 100,
}); });