mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
app -> route
This commit is contained in:
parent
d0c7cc7a45
commit
e5657d67c0
2 changed files with 26 additions and 26 deletions
|
|
@ -10,19 +10,19 @@ import { generateSecretKey, getPublicKey, nip19 } from 'nostr-tools';
|
||||||
|
|
||||||
import { createTestDB } from '@/test.ts';
|
import { createTestDB } from '@/test.ts';
|
||||||
|
|
||||||
import cashuApp from '@/controllers/api/cashu.ts';
|
import cashuRoute from './cashu.ts';
|
||||||
import { walletSchema } from '@/schema.ts';
|
import { walletSchema } from '@/schema.ts';
|
||||||
|
|
||||||
Deno.test('PUT /wallet must be successful', {
|
Deno.test('PUT /wallet must be successful', {
|
||||||
sanitizeOps: false,
|
sanitizeOps: false,
|
||||||
sanitizeResources: false,
|
sanitizeResources: false,
|
||||||
}, async () => {
|
}, 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 nostrPrivateKey = bytesToString('hex', sk);
|
||||||
|
|
||||||
const response = await app.request('/wallet', {
|
const response = await route.request('/wallet', {
|
||||||
method: 'PUT',
|
method: 'PUT',
|
||||||
headers: {
|
headers: {
|
||||||
'content-type': 'application/json',
|
'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 () => {
|
Deno.test('PUT /wallet must NOT be successful: wrong request body/schema', async () => {
|
||||||
await using test = await createTestApp();
|
await using test = await createTestRoute();
|
||||||
const { app } = test;
|
const { route } = test;
|
||||||
|
|
||||||
const response = await app.request('/wallet', {
|
const response = await route.request('/wallet', {
|
||||||
method: 'PUT',
|
method: 'PUT',
|
||||||
headers: {
|
headers: {
|
||||||
'content-type': 'application/json',
|
'content-type': 'application/json',
|
||||||
|
|
@ -105,12 +105,12 @@ Deno.test('PUT /wallet must NOT be successful: wallet already exists', {
|
||||||
sanitizeOps: false,
|
sanitizeOps: false,
|
||||||
sanitizeResources: false,
|
sanitizeResources: false,
|
||||||
}, async () => {
|
}, async () => {
|
||||||
await using test = await createTestApp();
|
await using test = await createTestRoute();
|
||||||
const { app, sk, relay } = test;
|
const { route, sk, relay } = test;
|
||||||
|
|
||||||
await relay.event(genEvent({ kind: 17375 }, sk));
|
await relay.event(genEvent({ kind: 17375 }, sk));
|
||||||
|
|
||||||
const response = await app.request('/wallet', {
|
const response = await route.request('/wallet', {
|
||||||
method: 'PUT',
|
method: 'PUT',
|
||||||
headers: {
|
headers: {
|
||||||
'authorization': `Bearer ${nip19.nsecEncode(sk)}`,
|
'authorization': `Bearer ${nip19.nsecEncode(sk)}`,
|
||||||
|
|
@ -131,8 +131,8 @@ Deno.test('GET /wallet must be successful', {
|
||||||
sanitizeOps: false,
|
sanitizeOps: false,
|
||||||
sanitizeResources: false,
|
sanitizeResources: false,
|
||||||
}, async () => {
|
}, async () => {
|
||||||
await using test = await createTestApp();
|
await using test = await createTestRoute();
|
||||||
const { app, sk, relay, signer } = test;
|
const { route, sk, relay, signer } = test;
|
||||||
|
|
||||||
const pubkey = await signer.getPublicKey();
|
const pubkey = await signer.getPublicKey();
|
||||||
const privkey = bytesToString('hex', sk);
|
const privkey = bytesToString('hex', sk);
|
||||||
|
|
@ -214,7 +214,7 @@ Deno.test('GET /wallet must be successful', {
|
||||||
],
|
],
|
||||||
}, senderSk));
|
}, senderSk));
|
||||||
|
|
||||||
const response = await app.request('/wallet', {
|
const response = await route.request('/wallet', {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -230,10 +230,10 @@ Deno.test('GET /wallet must be successful', {
|
||||||
});
|
});
|
||||||
|
|
||||||
Deno.test('GET /mints must be successful', async () => {
|
Deno.test('GET /mints must be successful', async () => {
|
||||||
await using test = await createTestApp();
|
await using test = await createTestRoute();
|
||||||
const { app } = test;
|
const { route } = test;
|
||||||
|
|
||||||
const response = await app.request('/mints', {
|
const response = await route.request('/mints', {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -243,7 +243,7 @@ Deno.test('GET /mints must be successful', async () => {
|
||||||
assertEquals(body, { mints: [] });
|
assertEquals(body, { mints: [] });
|
||||||
});
|
});
|
||||||
|
|
||||||
async function createTestApp() {
|
async function createTestRoute() {
|
||||||
const conf = new DittoConf(new Map());
|
const conf = new DittoConf(new Map());
|
||||||
|
|
||||||
const db = await createTestDB();
|
const db = await createTestDB();
|
||||||
|
|
@ -252,17 +252,17 @@ async function createTestApp() {
|
||||||
const sk = generateSecretKey();
|
const sk = generateSecretKey();
|
||||||
const signer = new NSecSigner(sk);
|
const signer = new NSecSigner(sk);
|
||||||
|
|
||||||
const app = new DittoApp({ db, relay, conf });
|
const route = new DittoApp({ db, relay, conf });
|
||||||
|
|
||||||
app.use(testUserMiddleware({ signer, relay }));
|
route.use(testUserMiddleware({ signer, relay }));
|
||||||
app.route('/', cashuApp);
|
route.route('/', cashuRoute);
|
||||||
|
|
||||||
const mock = stub(globalThis, 'fetch', () => {
|
const mock = stub(globalThis, 'fetch', () => {
|
||||||
return Promise.resolve(new Response());
|
return Promise.resolve(new Response());
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
app,
|
route,
|
||||||
db,
|
db,
|
||||||
conf,
|
conf,
|
||||||
sk,
|
sk,
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ import { errorJson } from '@/utils/log.ts';
|
||||||
|
|
||||||
type Wallet = z.infer<typeof walletSchema>;
|
type Wallet = z.infer<typeof walletSchema>;
|
||||||
|
|
||||||
const app = new DittoRoute();
|
const route = new DittoRoute();
|
||||||
|
|
||||||
// app.delete('/wallet') -> 204
|
// 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/60.md
|
||||||
* https://github.com/nostr-protocol/nips/blob/master/61.md#nutzap-informational-event
|
* 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 { conf, user, relay, signal } = c.var;
|
||||||
|
|
||||||
const pubkey = await user.signer.getPublicKey();
|
const pubkey = await user.signer.getPublicKey();
|
||||||
|
|
@ -104,7 +104,7 @@ app.put('/wallet', userMiddleware('nip44'), async (c) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
/** Gets a wallet, if it exists. */
|
/** 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 { conf, relay, user, signal } = c.var;
|
||||||
|
|
||||||
const pubkey = await user.signer.getPublicKey();
|
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. */
|
/** Get mints set by the CASHU_MINTS environment variable. */
|
||||||
app.get('/mints', (c) => {
|
route.get('/mints', (c) => {
|
||||||
const { conf } = c.var;
|
const { conf } = c.var;
|
||||||
|
|
||||||
// TODO: Return full Mint information: https://github.com/cashubtc/nuts/blob/main/06.md
|
// 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);
|
return c.json({ mints }, 200);
|
||||||
});
|
});
|
||||||
|
|
||||||
export default app;
|
export default route;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue