mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 03:19:46 +00:00
Add push controller test
This commit is contained in:
parent
b6925a5491
commit
94cf3b2931
2 changed files with 36 additions and 1 deletions
|
|
@ -4,9 +4,11 @@ import { serveStatic } from '@hono/hono/deno';
|
|||
import { logger } from '@hono/hono/logger';
|
||||
import { NostrEvent, NostrSigner, NStore, NUploader } from '@nostrify/nostrify';
|
||||
import Debug from '@soapbox/stickynotes/debug';
|
||||
import { Kysely } from 'kysely';
|
||||
|
||||
import '@/startup.ts';
|
||||
|
||||
import { DittoTables } from '@/db/DittoTables.ts';
|
||||
import { Time } from '@/utils/time.ts';
|
||||
|
||||
import {
|
||||
|
|
@ -133,7 +135,7 @@ import { storeMiddleware } from '@/middleware/storeMiddleware.ts';
|
|||
import { uploaderMiddleware } from '@/middleware/uploaderMiddleware.ts';
|
||||
import { translatorMiddleware } from '@/middleware/translatorMiddleware.ts';
|
||||
|
||||
interface AppEnv extends HonoEnv {
|
||||
export interface AppEnv extends HonoEnv {
|
||||
Variables: {
|
||||
/** Signer to get the logged-in user's pubkey, relays, and to sign events, or `undefined` if the user isn't logged in. */
|
||||
signer?: NostrSigner;
|
||||
|
|
@ -141,6 +143,8 @@ interface AppEnv extends HonoEnv {
|
|||
uploader?: NUploader;
|
||||
/** NIP-98 signed event proving the pubkey is owned by the user. */
|
||||
proof?: NostrEvent;
|
||||
/** Kysely instance for the database. */
|
||||
kysely: Kysely<DittoTables>;
|
||||
/** Storage for the user, might filter out unwanted content. */
|
||||
store: NStore;
|
||||
/** Normalized pagination params. */
|
||||
|
|
|
|||
31
src/controllers/api/push.test.ts
Normal file
31
src/controllers/api/push.test.ts
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
import { Hono } from '@hono/hono';
|
||||
import { NSecSigner } from '@nostrify/nostrify';
|
||||
import { generateSecretKey } from 'nostr-tools';
|
||||
|
||||
import { type AppEnv } from '@/app.ts';
|
||||
import { createTestDB } from '@/test.ts';
|
||||
import { pushSubscribeController } from '@/controllers/api/push.ts';
|
||||
import { assertEquals } from '@std/assert';
|
||||
|
||||
Deno.test('POST /api/v1/push/subscription creates the subscription in the database', async () => {
|
||||
await using db = await createTestDB();
|
||||
const signer = new NSecSigner(generateSecretKey());
|
||||
|
||||
const app = new Hono<AppEnv>().all((c) => {
|
||||
c.set('kysely', db.kysely);
|
||||
c.set('store', db.store);
|
||||
c.set('signer', signer);
|
||||
}, pushSubscribeController);
|
||||
|
||||
const response = await app.request('/api/v1/push/subscription', {
|
||||
body: JSON.stringify({
|
||||
endpoint: 'https://example.com',
|
||||
keys: {
|
||||
p256dh: 'p256dh',
|
||||
auth: 'auth',
|
||||
},
|
||||
}),
|
||||
});
|
||||
|
||||
assertEquals(response.status, 200);
|
||||
});
|
||||
Loading…
Add table
Reference in a new issue