Skip to content

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

Merged
JuliaKalder merged 4 commits into
mainfrom
fix/issue-80
Jun 3, 2026
Merged

refactor: decouple infrastructure from replaceVariables in template-insert.js#196
JuliaKalder merged 4 commits 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

JuliBot and others added 4 commits May 19, 2026 11:12
…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>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
# Conflicts:
#	modules/template-insert.js
@JuliaKalder JuliaKalder merged commit a88eafd into main Jun 3, 2026
1 check passed
@JuliaKalder JuliaKalder deleted the fix/issue-80 branch June 3, 2026 12:45
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