Skip to content

refactor: decouple infrastructure from replaceVariables in template-insert.js#196

Open
JuliaKalder wants to merge 1 commit into
mainfrom
fix/issue-80
Open

refactor: decouple infrastructure from replaceVariables in template-insert.js#196
JuliaKalder wants to merge 1 commit into
mainfrom
fix/issue-80

Conversation

@JuliaKalder
Copy link
Copy Markdown
Owner

Summary

  • Extracts resolveIdentityVars(tabId) — a new exported async helper that calls the three Thunderbird messenger APIs (compose.getComposeDetails, identities.get, accounts.list) and returns { senderName, senderEmail, accountName, accountEmail }.
  • Changes replaceVariables(text, tabId, isHtml)replaceVariables(text, vars, isHtml): now a pure synchronous function that only merges date/time vars with the pre-resolved identity vars and delegates to applyVariables.
  • Updates insertTemplateIntoTab to call resolveIdentityVars(tabId) once, then pass the result to all three replaceVariables invocations (body × 2 paths, subject).
  • Adds 11 unit tests for replaceVariables in tests/template-insert.test.js covering identity substitution, HTML encoding, date/time token replacement, and null/undefined passthrough.

Verification

All 37 tests in tests/template-insert.test.js pass (node --test tests/template-insert.test.js). The pre-existing failures in template-store.test.js are unrelated to this change.

Fixes #80

…g unit tests (#80)

Extract the three messenger API calls (getComposeDetails, identities.get,
accounts.list) into a new exported `resolveIdentityVars(tabId)` helper.
Change `replaceVariables` to accept a pre-resolved vars object instead of a
tabId, making it a pure synchronous function that only calls `applyVariables`.
Update `insertTemplateIntoTab` to call `resolveIdentityVars` once and pass
the result to all `replaceVariables` invocations.

Add 11 unit tests for the now-infrastructure-free `replaceVariables`.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[MEDIUM] replaceVariables mixes messenger API calls (infrastructure) with variable substitution (domain), blocking unit tests

1 participant