Skip to content

test: Add unit tests for templateVarHandler to improve coverage#34963

Closed
MatheussBrant wants to merge 2 commits intoRocketChat:developfrom
MatheussBrant:develop
Closed

test: Add unit tests for templateVarHandler to improve coverage#34963
MatheussBrant wants to merge 2 commits intoRocketChat:developfrom
MatheussBrant:develop

Conversation

@MatheussBrant
Copy link

Proposed changes (including videos or screenshots)

Issue(s)

Steps to test or reproduce

Further comments

Proposed Changes

This pull request introduces unit tests for the templateVarHandler function to improve test coverage and ensure correct behavior under different conditions.
Key Changes:

Created a dedicated test file for the templateVarHandler function in the directory:
tests/unit/app/utils/lib/templateVarHandler.spec.ts.
Added comprehensive unit tests to cover all logical branches and edge cases of the function.
Fixed coverage gaps, increasing coverage from:
    Statements: 41.66% → 100%
    Branch: 9.09% → 81.81%
    Functions: 100% → 100%
    Lines: 39.13% → 100%.

Screenshots (Coverage Changes):

Before:
image

After:
image

@MatheussBrant MatheussBrant requested a review from a team as a code owner January 17, 2025 19:18
@dionisio-bot
Copy link
Contributor

dionisio-bot bot commented Jan 17, 2025

Looks like this PR is not ready to merge, because of the following issues:

  • This PR is missing the 'stat: QA assured' label
  • This PR is missing the required milestone or project

Please fix the issues and try again

If you have any trouble, please check the PR guidelines

@changeset-bot
Copy link

changeset-bot bot commented Jan 17, 2025

⚠️ No Changeset found

Latest commit: a15c317

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

});
};

describe('templateVarHandler', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think of, instead of creating a new describe for each item, you construct an array of "test cases" and then you loop on them to do the test?

Something like:

const tests = [{ variable: 'attribute1', object: { attribute1: 'value1' }, expected: 'value1' }]

describe('templateVarHandler', () => {
tests.forEach((t) => { it(`should return ${t.expected} when ${t.variable} is passed as key`, () => { expect(templateVarHandler(t.variable, t.object)).to.be.equal(t.expected) }
})

(I may have missed some () but wdyt?

@MatheussBrant MatheussBrant requested a review from a team as a code owner February 9, 2025 21:26
@KevLehman
Copy link
Member

Hey, thanks for contribution!

Seems your linting settings are a bit off, as looks you're reducing the tabspace or you just have set your tab size too low. Wanna use eslint to fix those issues? You can run yarn lint on your local which will lint all the packages

@ggazzo ggazzo closed this Feb 25, 2026
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.

4 participants