Skip to content

test: add unit tests for all badges and CI workflow on badge changes #546

Open

Description

@jagdish-15

PR #545 introduced the first unit test (tests/badges.test.cjs) covering the SPRINTER badge. We should expand this to cover all 8 badges with positive and negative cases, and gate merges with a CI check.

Badges Needing Tests

  • HOT_STREAK — earned when data.streak.current >= 7, locked otherwise
  • HARD_CARRY — earned when 5+ Hard and 0 Easy solved in most recent 7-day window
  • CENTURION — earned when total solved (easy + medium + hard) ≥ 100
  • BALANCED — earned when each ≥ 5 and max-min within 5% of max
  • UP_LINK — earned when ranks.overall.change >= 5
  • TOP_BRASS — earned when ranks.overall.rank <= 10 (excluding --)
  • SPEEDRUN — earned when ranks.weekly.rank <= 3 and positive weighted score

SPRINTER is already covered by #545.

CI Workflow

Add a GitHub Actions workflow (.github/workflows/badge-tests.yml) that:

  1. Triggers on PRs to main when frontend/js/user/badges.js or tests/badges.test.cjs are changed
  2. Runs node --test tests/badges.test.cjs on ubuntu-latest with Node 20
  3. Also add a "test" script to package.json: "test": "node --test tests/"

Proposed workflow

name: Badge Tests

on:
  pull_request:
    branches: [main]
    paths:
      - "frontend/js/user/badges.js"
      - "tests/badges.test.cjs"

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - uses: actions/setup-node@v4
        with:
          node-version: "20"

      - run: node --test tests/badges.test.cjs

Linked PRs

Follows up on #545

Activity

  1. YashBora21 commented on Oct 14, 2026

    @YashBora21
    Contributor

    @jagdish-15 , I’d like to take this follow-up issue and add tests for the remaining badges plus the CI workflow. Could you assign #546 to me

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

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions