test: add unit tests for tier helpers#149
Conversation
surpradhan
left a comment
There was a problem hiding this comment.
Thanks for taking this on, @Ayushmann13479! Solid first contribution. The framework and style match the project well, and the acceptance criteria from issue #114 are covered. Two things to address:
Must fix
parseLimit("0") boundary is untested. The guard in parseLimit is n < 0, so TIER_FREE_EVENT_QUOTA=0 returns 0, not the built-in default. This means an operator who sets the env var to "0" accidentally hard-blocks all event ingest for the free tier. Please add a test that documents this behaviour:
test("zero is returned as-is (not treated as fallback)", () => {
process.env.TIER_FREE_EVENT_QUOTA = "0";
assert.equal(getTierDefinitions().free.event_quota, 0);
});Nits (optional but appreciated)
- Missing trailing newline at end of file. ESLint won't catch it in this project, but editors and
git diffflag it. Just add a newline after the last});. isValidTier(null)andisValidTier(undefined)both safely returnfalsebut are untested. A quick two-liner in the existingisValidTierdescribe block would close that gap.
|
Thanks for the review
Please take another look. |
surpradhan
left a comment
There was a problem hiding this comment.
Thanks for tackling this -- the structure is solid and all the edge cases from the issue are covered. Two things to address before we merge:
1. Indentation in the "zero is returned as-is" test (lines ~85-90)
The body of that test block is 2-space indented while the rest of the file uses 4-space. There is also a trailing space after the closing });. Quick fix -- just re-indent to match the surrounding tests.
2. process.env replacement pattern
Replacing the whole process.env object works, but is fragile (snapshot is taken at module-load time, not test-run time). The project convention is to mutate specific keys and delete them in afterEach. Something like:
const TIER_KEYS = [
"TIER_FREE_EVENT_QUOTA", "TIER_FREE_RETENTION_DAYS",
"TIER_TEAM_EVENT_QUOTA", "TIER_TEAM_RETENTION_DAYS",
"TIER_ENTERPRISE_EVENT_QUOTA", "TIER_ENTERPRISE_RETENTION_DAYS",
];
afterEach(() => { for (const k of TIER_KEYS) delete process.env[k]; });Then each test just sets the vars it needs directly -- no beforeEach needed at all.
Optional but nice-to-have: add isValidTier("") to the "returns false" test -- empty string is a realistic bad input from a malformed project row.
Removed the beforeEach hook for environment isolation and added TIER_KEYS array for managing tier-related environment variables.
|
Thanks for the review! I've addressed the requested changes:
Please let me know if there's anything else you'd like me to adjust. |
surpradhan
left a comment
There was a problem hiding this comment.
Good fixes -- the process.env replacement is gone and isValidTier("") is in. All the functional feedback is addressed.
One remaining nit: the closing }); on the "zero is returned as-is" test is still at column 0 instead of column 2. Also TIER_KEYS and afterEach use 4-space indentation while the describe/test blocks use 2-space -- worth making consistent. Both are cosmetic only.
Happy to merge once those are tidied up.
|
Thanks! I've cleaned up the indentation to match the rest of the file. |
|
Thank you for this contribution, @Ayushmann13479! The tier helper unit tests are a great addition to the test suite — clean coverage of |
🎯 Description
Adds a new unit test file for
src/tiers.jsto improve coverage of subscription tier helper functions and environment-variable override behavior.🤔 Why?
Issue #114 requested unit tests for the pure functions in
src/tiers.js. These functions are a good target for testing because they have no database or network dependencies and contain important tier policy logic.📝 Changes
tests/unit/tiers.test.jsisValidTier()TIER_NAMESandDEFAULT_TIERgetTierDefinitions()"unlimited"value handlinggetTierPolicy()fallback behavior🧪 How to Test?
Install dependencies: