refactor: decouple infrastructure from replaceVariables in template-insert.js#196
Open
JuliaKalder wants to merge 1 commit into
Open
refactor: decouple infrastructure from replaceVariables in template-insert.js#196JuliaKalder wants to merge 1 commit into
JuliaKalder wants to merge 1 commit into
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
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 }.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 toapplyVariables.insertTemplateIntoTabto callresolveIdentityVars(tabId)once, then pass the result to all threereplaceVariablesinvocations (body × 2 paths, subject).replaceVariablesintests/template-insert.test.jscovering identity substitution, HTML encoding, date/time token replacement, and null/undefined passthrough.Verification
All 37 tests in
tests/template-insert.test.jspass (node --test tests/template-insert.test.js). The pre-existing failures intemplate-store.test.jsare unrelated to this change.Fixes #80