mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 03:19:46 +00:00
Test that DittoRelayStore generates nip05 request set event
This commit is contained in:
parent
0dd085b559
commit
b8b6174fcc
3 changed files with 40 additions and 2 deletions
|
|
@ -74,6 +74,7 @@
|
|||
"@soapbox/logi": "jsr:@soapbox/logi@^0.3.0",
|
||||
"@soapbox/safe-fetch": "jsr:@soapbox/safe-fetch@^2.0.0",
|
||||
"@std/assert": "jsr:@std/assert@^0.225.1",
|
||||
"@std/async": "jsr:@std/async@^1.0.10",
|
||||
"@std/cli": "jsr:@std/cli@^0.223.0",
|
||||
"@std/crypto": "jsr:@std/crypto@^0.224.0",
|
||||
"@std/encoding": "jsr:@std/encoding@^0.224.0",
|
||||
|
|
|
|||
5
deno.lock
generated
5
deno.lock
generated
|
|
@ -58,6 +58,7 @@
|
|||
"jsr:@std/assert@^1.0.10": "1.0.11",
|
||||
"jsr:@std/assert@~0.213.1": "0.213.1",
|
||||
"jsr:@std/assert@~0.225.1": "0.225.3",
|
||||
"jsr:@std/async@^1.0.10": "1.0.10",
|
||||
"jsr:@std/bytes@0.223": "0.223.0",
|
||||
"jsr:@std/bytes@0.224": "0.224.0",
|
||||
"jsr:@std/bytes@0.224.0": "0.224.0",
|
||||
|
|
@ -604,6 +605,9 @@
|
|||
"jsr:@std/internal@^1.0.5"
|
||||
]
|
||||
},
|
||||
"@std/async@1.0.10": {
|
||||
"integrity": "2ff1b1c7d33d1416159989b0f69e59ec7ee8cb58510df01e454def2108b3dbec"
|
||||
},
|
||||
"@std/bytes@0.223.0": {
|
||||
"integrity": "84b75052cd8680942c397c2631318772b295019098f40aac5c36cead4cba51a8"
|
||||
},
|
||||
|
|
@ -2489,6 +2493,7 @@
|
|||
"jsr:@soapbox/logi@0.3",
|
||||
"jsr:@soapbox/safe-fetch@2",
|
||||
"jsr:@std/assert@~0.225.1",
|
||||
"jsr:@std/async@^1.0.10",
|
||||
"jsr:@std/cli@0.223",
|
||||
"jsr:@std/crypto@0.224",
|
||||
"jsr:@std/encoding@0.224",
|
||||
|
|
|
|||
|
|
@ -2,12 +2,39 @@ import { DittoPolyPg } from '@ditto/db';
|
|||
import { DittoConf } from '@ditto/conf';
|
||||
import { genEvent, MockRelay } from '@nostrify/nostrify/test';
|
||||
import { assertEquals } from '@std/assert';
|
||||
import { waitFor } from '@std/async/unstable-wait-for';
|
||||
import { generateSecretKey, getPublicKey } from 'nostr-tools';
|
||||
|
||||
import { DittoRelayStore } from './DittoRelayStore.ts';
|
||||
|
||||
import type { NostrMetadata } from '@nostrify/types';
|
||||
|
||||
Deno.test('generates set event for nip05 request', async () => {
|
||||
await using test = setupTest();
|
||||
|
||||
const admin = await test.conf.signer.getPublicKey();
|
||||
const event = genEvent({ kind: 3036, tags: [['r', 'alex@gleasonator.dev'], ['p', admin]] });
|
||||
|
||||
await test.store.event(event);
|
||||
|
||||
const filter = { kinds: [30383], authors: [admin], '#d': [event.id] };
|
||||
|
||||
await waitFor(async () => {
|
||||
const { count } = await test.store.count([filter]);
|
||||
return count > 0;
|
||||
}, 3000);
|
||||
|
||||
const [result] = await test.store.query([filter]);
|
||||
|
||||
assertEquals(result?.tags, [
|
||||
['d', event.id],
|
||||
['p', event.pubkey],
|
||||
['k', '3036'],
|
||||
['r', 'alex@gleasonator.dev'],
|
||||
['n', 'pending'],
|
||||
]);
|
||||
});
|
||||
|
||||
Deno.test('updateAuthorData sets nip05', async () => {
|
||||
const alex = generateSecretKey();
|
||||
|
||||
|
|
@ -38,20 +65,25 @@ Deno.test('updateAuthorData sets nip05', async () => {
|
|||
assertEquals(row?.nip05_hostname, 'gleasonator.dev');
|
||||
});
|
||||
|
||||
function setupTest(cb: (req: Request) => Response | Promise<Response>) {
|
||||
function setupTest(cb?: (req: Request) => Response | Promise<Response>) {
|
||||
const conf = new DittoConf(Deno.env);
|
||||
const db = new DittoPolyPg(conf.databaseUrl);
|
||||
const relay = new MockRelay();
|
||||
|
||||
const mockFetch: typeof fetch = async (input, init) => {
|
||||
const req = new Request(input, init);
|
||||
if (cb) {
|
||||
return await cb(req);
|
||||
} else {
|
||||
return new Response('Not mocked', { status: 404 });
|
||||
}
|
||||
};
|
||||
|
||||
const store = new DittoRelayStore({ conf, db, relay, fetch: mockFetch });
|
||||
|
||||
return {
|
||||
db,
|
||||
conf,
|
||||
store,
|
||||
[Symbol.asyncDispose]: async () => {
|
||||
await store[Symbol.asyncDispose]();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue