Skip to content

Refactor pricing function + fix quantity=0 edge case + add tests #1

@Slackmom

Description

@Slackmom

Context:
The current pricing logic is hard to read and risky to change. There is a known bug: quantity=0 should return a total of 0, but the function currently charges for at least one item.

Goal:
Refactor the pricing logic into small, pure functions and fix the quantity=0 edge case.

Non-goals:

  • No new features
  • No API/signature changes for calcPrice(input)
  • No changes outside /src/pricing/** and /tests/**

Acceptance Criteria:

  1. calcPrice keeps the same input/output shape
  2. Logic is split into small functions (readable + testable)
  3. Tests cover: basic case, quantity=0 edge case, and one regression scenario
  4. npm test passes
  5. PR description includes: Summary, Risk/Notes, How to test

Constraints:

  • Touch only: /src/pricing/** and /tests/**
  • Keep the change reviewable (small steps)

How to test:

  • Run npm test
  • Example inputs:
    • quantity=1, DE, no coupon
    • quantity=0 (edge case)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions