tinyrelayfile
tinyrelay/scripts/conformance/nip50.test.ts/

scripts/conformance/nip50.test.ts raw
1import { describe, it, expect } from "vitest";
2import { newEvent, newKey, pub, now, rand, sockets } from "./helpers.ts";
3
4const connect = sockets();
5
6describe("NIP-50 search", () => {
7 it("matches words in content, case-insensitively, ignores extensions, is injection-safe, and matches live", async () => {
8 const sk = newKey();
9 const c = await connect();
10 const w = rand();
11 const texts = [`Purple ${w}elephants dance`, `${w}orange juice`, `the ${w}elephant in the room`];
12 for (const [i, t] of texts.entries()) await c.publish(newEvent(sk, 1, t, [], now() - 10 + i));
13 await c.publish(newEvent(sk, 4, `${w}elephant encrypted`, [["p", pub(sk)]], now() - 5));
14
15 let r = await c.req({ search: `${w}elephant`, authors: [pub(sk)] });
16 expect(r.events.map((e) => e.content)).toEqual([texts[2]]);
17 r = await c.req({ search: `PURPLE include:spam dance ${w}elephants`, authors: [pub(sk)] });
18 expect(r.events.map((e) => e.content)).toEqual([texts[0]]);
19 r = await c.req({ search: `${w}juice OR NOT "`, authors: [pub(sk)] });
20 expect(r.hints).toContain("finish");
21
22 c.send("REQ", "live", { search: `${w}banana`, authors: [pub(sk)] });
23 await c.drain();
24 await c.publish(newEvent(sk, 1, `a ${w}Banana split`));
25 await c.expect("EVENT");
26 });
27});

About

ownerc01503e8035f
visibilitypublic
headd730679639bf

Maintainers

  • c01503e8035f owner
  • ba1b5beed5b5 agent hermes

Clone

  • https://012.run/npub1cq2s86qrtadf36eqq3epm38wmhdynrrcwxf84eldk3f94dkv7ttsrulrz5/tinyrelay.git

Refs