From e5657d67c0dc9ec5408ee0d5b761c646b8911f82 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Fri, 21 Feb 2025 15:08:37 -0600 Subject: [PATCH] app -> route --- packages/ditto/controllers/api/cashu.test.ts | 42 ++++++++++---------- packages/ditto/controllers/api/cashu.ts | 10 ++--- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/packages/ditto/controllers/api/cashu.test.ts b/packages/ditto/controllers/api/cashu.test.ts index bb80128f..22e9a38f 100644 --- a/packages/ditto/controllers/api/cashu.test.ts +++ b/packages/ditto/controllers/api/cashu.test.ts @@ -10,19 +10,19 @@ import { generateSecretKey, getPublicKey, nip19 } from 'nostr-tools'; import { createTestDB } from '@/test.ts'; -import cashuApp from '@/controllers/api/cashu.ts'; +import cashuRoute from './cashu.ts'; import { walletSchema } from '@/schema.ts'; Deno.test('PUT /wallet must be successful', { sanitizeOps: false, sanitizeResources: false, }, async () => { - await using test = await createTestApp(); + await using test = await createTestRoute(); - const { app, signer, sk, relay } = test; + const { route, signer, sk, relay } = test; const nostrPrivateKey = bytesToString('hex', sk); - const response = await app.request('/wallet', { + const response = await route.request('/wallet', { method: 'PUT', headers: { 'content-type': 'application/json', @@ -82,10 +82,10 @@ Deno.test('PUT /wallet must be successful', { }); Deno.test('PUT /wallet must NOT be successful: wrong request body/schema', async () => { - await using test = await createTestApp(); - const { app } = test; + await using test = await createTestRoute(); + const { route } = test; - const response = await app.request('/wallet', { + const response = await route.request('/wallet', { method: 'PUT', headers: { 'content-type': 'application/json', @@ -105,12 +105,12 @@ Deno.test('PUT /wallet must NOT be successful: wallet already exists', { sanitizeOps: false, sanitizeResources: false, }, async () => { - await using test = await createTestApp(); - const { app, sk, relay } = test; + await using test = await createTestRoute(); + const { route, sk, relay } = test; await relay.event(genEvent({ kind: 17375 }, sk)); - const response = await app.request('/wallet', { + const response = await route.request('/wallet', { method: 'PUT', headers: { 'authorization': `Bearer ${nip19.nsecEncode(sk)}`, @@ -131,8 +131,8 @@ Deno.test('GET /wallet must be successful', { sanitizeOps: false, sanitizeResources: false, }, async () => { - await using test = await createTestApp(); - const { app, sk, relay, signer } = test; + await using test = await createTestRoute(); + const { route, sk, relay, signer } = test; const pubkey = await signer.getPublicKey(); const privkey = bytesToString('hex', sk); @@ -214,7 +214,7 @@ Deno.test('GET /wallet must be successful', { ], }, senderSk)); - const response = await app.request('/wallet', { + const response = await route.request('/wallet', { method: 'GET', }); @@ -230,10 +230,10 @@ Deno.test('GET /wallet must be successful', { }); Deno.test('GET /mints must be successful', async () => { - await using test = await createTestApp(); - const { app } = test; + await using test = await createTestRoute(); + const { route } = test; - const response = await app.request('/mints', { + const response = await route.request('/mints', { method: 'GET', }); @@ -243,7 +243,7 @@ Deno.test('GET /mints must be successful', async () => { assertEquals(body, { mints: [] }); }); -async function createTestApp() { +async function createTestRoute() { const conf = new DittoConf(new Map()); const db = await createTestDB(); @@ -252,17 +252,17 @@ async function createTestApp() { const sk = generateSecretKey(); const signer = new NSecSigner(sk); - const app = new DittoApp({ db, relay, conf }); + const route = new DittoApp({ db, relay, conf }); - app.use(testUserMiddleware({ signer, relay })); - app.route('/', cashuApp); + route.use(testUserMiddleware({ signer, relay })); + route.route('/', cashuRoute); const mock = stub(globalThis, 'fetch', () => { return Promise.resolve(new Response()); }); return { - app, + route, db, conf, sk, diff --git a/packages/ditto/controllers/api/cashu.ts b/packages/ditto/controllers/api/cashu.ts index 9c7dcab0..2d3a1519 100644 --- a/packages/ditto/controllers/api/cashu.ts +++ b/packages/ditto/controllers/api/cashu.ts @@ -14,7 +14,7 @@ import { errorJson } from '@/utils/log.ts'; type Wallet = z.infer; -const app = new DittoRoute(); +const route = new DittoRoute(); // app.delete('/wallet') -> 204 @@ -42,7 +42,7 @@ const createCashuWalletAndNutzapInfoSchema = z.object({ * https://github.com/nostr-protocol/nips/blob/master/60.md * https://github.com/nostr-protocol/nips/blob/master/61.md#nutzap-informational-event */ -app.put('/wallet', userMiddleware('nip44'), async (c) => { +route.put('/wallet', userMiddleware('nip44'), async (c) => { const { conf, user, relay, signal } = c.var; const pubkey = await user.signer.getPublicKey(); @@ -104,7 +104,7 @@ app.put('/wallet', userMiddleware('nip44'), async (c) => { }); /** Gets a wallet, if it exists. */ -app.get('/wallet', userMiddleware('nip44'), swapNutzapsMiddleware, async (c) => { +route.get('/wallet', userMiddleware('nip44'), swapNutzapsMiddleware, async (c) => { const { conf, relay, user, signal } = c.var; const pubkey = await user.signer.getPublicKey(); @@ -157,7 +157,7 @@ app.get('/wallet', userMiddleware('nip44'), swapNutzapsMiddleware, async (c) => }); /** Get mints set by the CASHU_MINTS environment variable. */ -app.get('/mints', (c) => { +route.get('/mints', (c) => { const { conf } = c.var; // TODO: Return full Mint information: https://github.com/cashubtc/nuts/blob/main/06.md @@ -166,4 +166,4 @@ app.get('/mints', (c) => { return c.json({ mints }, 200); }); -export default app; +export default route;