test(core): Add unit tests for contains-products promotion condition#4881
Conversation
Adds a spec file covering the `contains_products` check() via equivalence partitioning and boundary-value analysis on the total matching quantity vs the minimum threshold. 6 tests, no database required. Relates to vendurehq#4835
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
All contributors have signed the CLA ✍️ ✅ |
📝 WalkthroughWalkthroughAdds a Vitest test suite for Possibly related issues
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
Adds a focused, database-free Vitest unit test suite for the contains_products promotion condition in @vendure/core, improving direct functional coverage of this isolated business rule.
Changes:
- Introduces a new
contains-products-condition.spec.tssuite exercising the condition’s quantity-summing behavior. - Covers key boundary cases (below/at/above minimum), multi-line accumulation, and exclusion of non-eligible variants.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| import { OrderLine } from '../../../entity/order-line/order-line.entity'; | ||
| import { Order } from '../../../entity/order/order.entity'; | ||
| import { ProductVariant } from '../../../entity/product-variant/product-variant.entity'; | ||
| import { createRequestContext } from '../../../testing/order-test-utils'; | ||
|
|
There was a problem hiding this comment.
Dismissed. Same reasoning as the parallel comment on the other PRs: containsProducts.check() does not use the promotion argument, and undefined as any is the intentional pattern shared across all promotion-condition specs in this series. No functional risk.
|
I have read the CLA Document and I hereby sign the CLA |
|
recheck |
grolmus
left a comment
There was a problem hiding this comment.
Excellent, well-structured coverage — boundary-value analysis on the thresholds, clean injector-based mocking (no DB), and assertions that the condition is invoked with the right args. Test-only, no production changes. Approving.
Description
Adds a direct unit test suite for the
contains_productspromotion condition (contains-products-condition.ts), which previously had 0% function coverage.The condition sums
line.quantityfor all order lines whose variant ID is inproductVariantIds, then returnsargs.minimum <= matches.6 tests covering:
All tests are database-free.
Breaking changes
None.
Checklist
Relates to #4835
Need help on this PR? Tag
/codesmithwith what you need. Autofix is disabled.