Summary
Add tests for useFollowList (src/hooks/useFollowList.ts), which loads the current user’s kind 3 contact list from relays with followListCache (localStorage / IndexedDB). followListCache already has dedicated tests — this issue targets the hook’s query function, ordering, empty relay, and newer-vs-cache branches.
Problem
- The hook contains non-trivial branching: no user, zero relay events with optional cache fallback, sort by
created_at, isNewerThan vs relay data, extraction of p tags.
- Production logs (
debugLog) suggest this path was debugged manually — automated tests prevent regressions when relay behaviour or cache TTL logic changes.
Expected outcome
renderHook with mocked useNostr, useCurrentUser, and followListCache module:
- Assert
nostr.query filter: kinds: [3], authors: [user.pubkey], limit: 1.
- When relay returns one kind 3 event:
p tags parsed to pubkey list in tag order (or as implemented).
- When relay returns []: empty array or cached follows when cache exists (match implementation).
- When relay event is older than cache: cached follows returned (mirror
isNewerThan / getCached logic).
What needs to be tested
- Disabled / no user: query returns
[] or does not call relay — match enabled semantics in source.
- Success path: sorted events, latest wins.
- IndexedDB effect: optionally assert
followListCache.loadFromIndexedDB called when localStorage empty — may require vi.spyOn on followListCache (keep test deterministic).
Mocking strategy
vi.mock('@/lib/followListCache') with in-memory behaviour or spy real module with controlled return values.
vi.mock('@nostrify/react') → { nostr: { query: vi.fn().mockResolvedValue([...]) } }.
Acceptance criteria
Related files
| File |
Role |
src/hooks/useFollowList.ts |
Hook under test |
src/lib/followListCache.ts + followListCache.test.ts |
Existing cache tests |
Notes
useFollowRelationship already has tests — do not conflate; this issue is kind 3 list ingestion only.
- Trim overly verbose
debugLog in production later via separate chore if maintainers want — not required to close this issue.
Summary
Add tests for
useFollowList(src/hooks/useFollowList.ts), which loads the current user’s kind 3 contact list from relays withfollowListCache(localStorage / IndexedDB).followListCachealready has dedicated tests — this issue targets the hook’s query function, ordering, empty relay, and newer-vs-cache branches.Problem
created_at,isNewerThanvs relay data, extraction ofptags.debugLog) suggest this path was debugged manually — automated tests prevent regressions when relay behaviour or cache TTL logic changes.Expected outcome
renderHookwith mockeduseNostr,useCurrentUser, andfollowListCachemodule:nostr.queryfilter:kinds: [3],authors: [user.pubkey],limit: 1.ptags parsed to pubkey list in tag order (or as implemented).isNewerThan/getCachedlogic).What needs to be tested
[]or does not call relay — matchenabledsemantics in source.followListCache.loadFromIndexedDBcalled when localStorage empty — may requirevi.spyOnonfollowListCache(keep test deterministic).Mocking strategy
vi.mock('@/lib/followListCache')with in-memory behaviour or spy real module with controlled return values.vi.mock('@nostrify/react')→{ nostr: { query: vi.fn().mockResolvedValue([...]) } }.Acceptance criteria
src/hooks/useFollowList.test.tsadded.src/test/setup.ts).npm run test+npx tsc --noEmitpass.Related files
src/hooks/useFollowList.tssrc/lib/followListCache.ts+followListCache.test.tsNotes
useFollowRelationshipalready has tests — do not conflate; this issue is kind 3 list ingestion only.debugLogin production later via separate chore if maintainers want — not required to close this issue.