Files

39 lines
1.9 KiB
JavaScript
Raw Permalink Normal View History

2026-10-29 11:57:29 +01:00
// Generated, do not edit. sha256:70b6740879727acfaef00d88148ac04c728d9809f7bdb7b319265eea0e2e9de7
import { describe, it } from 'node:test';
import assert from 'node:assert/strict';
const { nwcMemo } = await import('../../client/lightning/lightning-tracker.js');
const { memoLine } = await import('../../client/lightning/memo-line.js');
const ALICE = '3bf0c63fcb93463407af97a5e5ee64fa883d107ef9e558472c4eb9aaaefa459d';
const zap = { kind: 9734, pubkey: ALICE, content: 'Top', tags: [['p', 'a'.repeat(64)]] };
describe('nwcMemo', () => {
it('neemt de omschrijving, en anders het zap-verzoek uit metadata.nostr', () => {
assert.equal(nwcMemo({ description: 'Koffie' }), 'Koffie');
assert.deepEqual(nwcMemo({ description: 'b'.repeat(64), metadata: { nostr: { pubkey: ALICE, content: 'Top', tags: [] } } }),
{ kind: 9734, pubkey: ALICE, content: 'Top', tags: [] });
assert.equal(nwcMemo({ description: JSON.stringify(zap), metadata: { nostr: { pubkey: 'x' } } }), JSON.stringify(zap));
assert.equal(nwcMemo({ metadata: { comment: 'Bedankt' } }), 'Bedankt');
assert.equal(nwcMemo({}), null);
});
});
describe('memoLine', () => {
it('noemt bij binnenkomend de afzender met het bericht', () => {
assert.deepEqual(memoLine(JSON.stringify(zap), 'in'), { text: 'Zap van npub180cv…h6w6: "Top"', title: 'Zap van npub180cv…h6w6: "Top"' });
});
it('noemt bij uitgaand de ontvanger, en kort een lange regel in met de hele tekst als titel', () => {
const lang = { ...zap, content: 'x'.repeat(200) };
const r = memoLine(JSON.stringify(lang), 'out', 40);
assert.match(r.text, /^Zap aan npub1/);
assert.equal(r.text.length, 40);
assert.ok(r.title.length > 200);
});
it('een gewone memo komt zoals hij is, en geen memo geeft niets', () => {
assert.equal(memoLine('Koffie', 'out').text, 'Koffie');
assert.equal(memoLine(null, 'in'), null);
});
});