test(core): add unit tests for contains-products promotion condition#4881
test(core): add unit tests for contains-products promotion condition#4881GabrielRoc wants to merge 1 commit into
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.
|
|
I have read the CLA Document and I hereby sign the CLA You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 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'; | ||
|
|
| const ctx = createRequestContext({ pricesIncludeTax: false }); | ||
|
|
||
| function check(order: Order, args: ConfigArg[]) { | ||
| return containsProducts.check(ctx, order, args, undefined as any); | ||
| } |
| * Test cases are derived by: | ||
| * - equivalence partitioning over the match count vs minimum | ||
| * - boundary-value analysis at `matches = minimum ± 1` | ||
| * - edge cases for multiple eligible lines and overlapping ID sets | ||
| */ |
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.