spa(task 5 polish): jsdoc auf naddr-helpers, coverage-lücken geschlossen
- JSDoc zu NaddrArgs, buildNaddr, buildHablaLink (Stil konsistent mit config.ts). - Neue Tests: ohne relays (Default-`?? []`-Pfad), unterschiedliche Inputs erzeugen unterschiedliche Links (Guard gegen konstanten Rückgabewert). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
c539c4fee3
commit
1fb77669e6
|
|
@ -1,22 +1,34 @@
|
|||
import { nip19 } from 'nostr-tools';
|
||||
import { HABLA_BASE } from './config';
|
||||
|
||||
/**
|
||||
* Argumente für NIP-19 addressable-event-Pointer.
|
||||
* Validierung (hex-Länge etc.) wird an `nip19.naddrEncode` delegiert.
|
||||
*/
|
||||
export interface NaddrArgs {
|
||||
pubkey: string;
|
||||
kind: number;
|
||||
identifier: string;
|
||||
relays?: string[];
|
||||
pubkey: string;
|
||||
kind: number;
|
||||
identifier: string;
|
||||
relays?: string[];
|
||||
}
|
||||
|
||||
/**
|
||||
* Baut einen `naddr1…`-Bech32-String (NIP-19) für ein addressable Event.
|
||||
* Wird u. a. für Habla.news-Deep-Links genutzt.
|
||||
*/
|
||||
export function buildNaddr(args: NaddrArgs): string {
|
||||
return nip19.naddrEncode({
|
||||
pubkey: args.pubkey,
|
||||
kind: args.kind,
|
||||
identifier: args.identifier,
|
||||
relays: args.relays ?? [],
|
||||
});
|
||||
return nip19.naddrEncode({
|
||||
pubkey: args.pubkey,
|
||||
kind: args.kind,
|
||||
identifier: args.identifier,
|
||||
relays: args.relays ?? []
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Habla.news-Deep-Link auf ein addressable Event.
|
||||
* Fallback für „Post nicht gefunden" / JS-lose Clients.
|
||||
*/
|
||||
export function buildHablaLink(args: NaddrArgs): string {
|
||||
return `${HABLA_BASE}${buildNaddr(args)}`;
|
||||
return `${HABLA_BASE}${buildNaddr(args)}`;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,4 +21,24 @@ describe('buildHablaLink', () => {
|
|||
};
|
||||
expect(buildHablaLink(args)).toBe(buildHablaLink(args));
|
||||
});
|
||||
|
||||
it('funktioniert ohne relays (optional)', () => {
|
||||
const link = buildHablaLink({
|
||||
pubkey: '4fa5d1c413e2b45e10d40bf3562ab701a5331206e359c90baae0e99bfd6c6e41',
|
||||
kind: 30023,
|
||||
identifier: 'foo',
|
||||
});
|
||||
expect(link).toMatch(/^https:\/\/habla\.news\/a\/naddr1[a-z0-9]+$/);
|
||||
});
|
||||
|
||||
it('erzeugt unterschiedliche Links für unterschiedliche Inputs', () => {
|
||||
const base = {
|
||||
pubkey: '4fa5d1c413e2b45e10d40bf3562ab701a5331206e359c90baae0e99bfd6c6e41',
|
||||
kind: 30023,
|
||||
relays: [],
|
||||
};
|
||||
const a = buildHablaLink({ ...base, identifier: 'foo' });
|
||||
const b = buildHablaLink({ ...base, identifier: 'bar' });
|
||||
expect(a).not.toBe(b);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue