Skip to content

test: add unit tests for achievement-estimators helper functions#2834

Open
yachikadev wants to merge 1 commit into
Priyanshu-byte-coder:mainfrom
yachikadev:test/2749-achievement-estimators
Open

test: add unit tests for achievement-estimators helper functions#2834
yachikadev wants to merge 1 commit into
Priyanshu-byte-coder:mainfrom
yachikadev:test/2749-achievement-estimators

Conversation

@yachikadev

Copy link
Copy Markdown
Contributor

Closes #2794

Summary

Added unit tests for the pure helper functions calculateNextTier and calculatePercentage in src/lib/achievement-estimators.ts.

Changes

  • Created test/achievement-estimators.test.ts with full coverage for both functions

Test Cases Covered

calculateNextTier

  • Returns first tier when current is below all tiers
  • Returns next tier when current is below a tier
  • Returns next tier when current equals a tier
  • Returns null when current exceeds all tiers (maxed out)
  • Returns null for empty tiers array
  • Returns first tier when current is negative

calculatePercentage

  • Returns 100 when nextTier is null (maxed out)
  • Returns 100 when current exceeds nextTier
  • Returns floor of ratio when current is below nextTier
  • Returns 100 when current equals nextTier
  • Handles 0 current gracefully

Notes

Added // @vitest-environment node to the test file since these are pure functions with no DOM dependency, which also fixes a jsdom/undici incompatibility with Node.js v24.

@github-actions github-actions Bot added gssoc26 GSSoC 2026 contribution type:feature GSSoC type bonus: new feature type:testing GSSoC type bonus: tests (+10 pts) labels Jun 26, 2026
@github-actions

Copy link
Copy Markdown

GSSoC Label Checklist 🏷️

@Priyanshu-byte-coder — please apply the appropriate labels before merging:

Difficulty (pick one):

  • level:beginner — 20 pts
  • level:intermediate — 35 pts
  • level:advanced — 55 pts
  • level:critical — 80 pts

Quality (optional):

  • quality:clean — ×1.2 multiplier
  • quality:exceptional — ×1.5 multiplier

Validation (required to score):

  • gssoc:approved — counts for points
  • gssoc:invalid / gssoc:spam / gssoc:ai-slop — does not score

Type labels (type:*) are auto-detected from files and title. Review and adjust if needed.
Points formula: (difficulty × quality_multiplier) + type_bonus

@yachikadev

Copy link
Copy Markdown
Contributor Author

The Playwright smoke test failure is not related to this PR.
It is caused by a pnpm-lock.yaml lockfile mismatch with the current overrides config in package.json — a pre-existing repo issue. All checks relevant to this PR pass successfully.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gssoc26 GSSoC 2026 contribution type:feature GSSoC type bonus: new feature type:testing GSSoC type bonus: tests (+10 pts)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test : add unit tests for achievement-estimators helper functions

1 participant