Skip to content

test(server): unit tests for parseResponse (mention/citation/visibility scoring) #243

Closed

Description

@gkhngyk

Summary

parseResponse (and its helper countBrandMentions) in server/src/lib/response-parser.js is a pure function — it takes a model response plus brand/competitor metadata and computes mention count, citation count, sentiment passthrough, a 0–100 visibility score, and per-competitor mentions. No network, no Redis, no Supabase.

This is exactly the half of the manual test-tracking.js smoke script (see #240) that can be tested for free: mock/skip the paid OpenAI call and feed the parser fixtures instead. It makes a good first concrete server test — the same spirit as the web-side toCsv/classifyDomain tests (#196, #198).

Depends on

Suggested coverage

Colocate server/src/lib/response-parser.test.js and cover the pure behavior with fixtures:

  • Brand mention count — counts brand.brandName and each brand.domains entry; verify URL stripping prevents double-counting a domain that also appears inside a citation URL.
  • Citation count — case-insensitive domain match against citations[].url; counts a citation once even if multiple domains match.
  • Visibility score — a few representative { mentionCount, citationCount, totalCitations, sentiment } inputs map to expected 0–100 outputs; sentiment affects the result.
  • Competitor mentions — each competitor gets its own mention/citation/score; missing comp.domain is handled.
  • Edge cases — empty text, empty citations, zero mentions.

Pure assertions only — no live API calls.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issue

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions