Skip to content

test: cover product pricing, discounts and the buyers count display - #35

Merged
Huerte merged 1 commit into
nemsu-dev-org:mainfrom
am-official:test/product-pricing
Oct 25, 2026
Merged

Huerte merged 1 commit into
nemsu-dev-org:mainfrom
am-official:test/product-pricing

Conversation

@am-official

Copy link
Copy Markdown
Contributor

Closes #24

Adds src/store/tests/test_product_pricing.py with tests for the computed properties of Product:

  • Peso conversion (1 USD = 59.41 PHP): price_in_peso_value and the formatted price_in_peso, including the thousands separator (₱5,941.00).
  • Rounding to two decimals, half up: one case that rounds down (0.5941 -> 0.59) and one that rounds up (32.6755 -> 32.68), and a discounted price that rounds up (50.4985 -> 50.50).
  • Discounts: no discount (is_on_sale is false and the discounted price equals the peso price), 20% off, and 100% off.
  • buyers_count_display: plain counts (0, 1, 999), thousands (1.0K, 1.5K, 25.3K) and millions (1.0M, 2.5M).

Every expected value is worked out from the rate and the rounding rule, not copied from the output.

How I tested it

  • python manage.py test from src/, with the same dummy keys as the CI workflow: 19 tests pass (the 10 new ones plus the existing 9).
  • To check that the tests catch real mistakes, I changed models.py temporarily (and restored it): a rate of 59.40 fails 4 tests, and rounding down instead of half up fails a test for the peso price and another for the discounted price.

Only the test file is added; no application code changes.

Product's computed properties had no tests. The new store/tests/test_product_pricing.py covers
the peso conversion (1 USD = 59.41 PHP) with its thousands separator, rounding to two decimals
half up for both the peso price and the discounted price, products with no discount, a 20% and a
100% discount, and the plain, K and M forms of buyers_count_display.

Closes nemsu-dev-org#24
@Huerte
Huerte merged commit 078943c into nemsu-dev-org:main Oct 25, 2026
1 check passed
@Huerte

Huerte commented Oct 25, 2026

Copy link
Copy Markdown
Member

@am-official

image

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.

Add tests for product pricing (peso conversion, discounts, buyers count)

2 participants