aboutsummaryrefslogtreecommitdiffstats
path: root/names/lnurl-params.test.js
blob: c198853310af7281f64575480966ac802d3d1291 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// bun test names/lnurl-params.test.js
import { test, expect } from 'bun:test';
import { tolerantParams } from './lnurl-params.js';

const p = (q) => tolerantParams(new URL('https://x/lnurlp/a/cb' + q).search);

test('a well-formed callback is read as is', () => {
  const r = p('?domain=coinos.io&amount=21000&comment=hi%3F');
  expect(r.get('domain')).toBe('coinos.io');
  expect(r.get('amount')).toBe('21000');
  expect(r.get('comment')).toBe('hi?');
});
test('a second ? (amount appended with ? instead of &) still finds the name and amount', () => {
  const r = p('?domain=coinos.io?amount=21000&nostr=%7B%7D');
  expect(r.get('domain')).toBe('coinos.io');
  expect(r.get('amount')).toBe('21000');
  expect(r.get('nostr')).toBe('{}');
});
test("parameters already in the URL aren't overridden", () => {
  const r = p('?amount=5000&domain=coinos.io?amount=21000');
  expect(r.get('amount')).toBe('5000');
});