Skip to content

test(core): add unit tests for contains-products promotion condition#4881

Open
GabrielRoc wants to merge 1 commit into
vendurehq:masterfrom
GabrielRoc:test/contains-products-condition
Open

test(core): add unit tests for contains-products promotion condition#4881
GabrielRoc wants to merge 1 commit into
vendurehq:masterfrom
GabrielRoc:test/contains-products-condition

Conversation

@GabrielRoc

@GabrielRoc GabrielRoc commented Jun 27, 2026

Copy link
Copy Markdown

Description

Adds a direct unit test suite for the contains_products promotion condition (contains-products-condition.ts), which previously had 0% function coverage.

The condition sums line.quantity for all order lines whose variant ID is in productVariantIds, then returns args.minimum <= matches.

6 tests covering:

  • Equivalence partitioning over the match count: zero matches / below minimum / at minimum / above minimum
  • Quantity accumulation across multiple eligible lines
  • Correct exclusion of non-eligible lines

All tests are database-free.

Breaking changes

None.

Checklist

  • I have set a clear title
  • My PR is small and contains a single feature
  • I have added or updated test cases

Relates to #4835


View with Codesmith Autofix with Codesmith
Need help on this PR? Tag /codesmith with what you need. Autofix is disabled.

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
Copilot AI review requested due to automatic review settings June 27, 2026 04:50
@vercel

vercel Bot commented Jun 27, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
vendure-storybook Ready Ready Preview, Comment Jun 27, 2026 4:52am

Request Review

@vendure-ci-automation-bot

Copy link
Copy Markdown
Contributor


Thank you for your submission, we really appreciate it. Like many open-source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution. You can sign the CLA by just posting a Pull Request Comment same as the below format.


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.

@coderabbitai

coderabbitai Bot commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 27b81613-9978-425b-88ec-72f4e69b8773

📥 Commits

Reviewing files that changed from the base of the PR and between c5a2785 and c8cf060.

📒 Files selected for processing (1)
  • packages/core/src/config/promotion/conditions/contains-products-condition.spec.ts

📝 Walkthrough

Walkthrough

Adds a Vitest test suite for containsProducts.check. The tests build promotion condition args, order lines, and orders, then verify boundary behavior around the minimum eligible quantity. They also cover quantity accumulation across multiple matching lines and confirm that non-eligible variants are ignored.

Possibly related issues

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly states the main change: adding unit tests for the contains-products promotion condition.
Description check ✅ Passed The description covers the change summary, related issue, breaking changes, and checklist, matching the template well.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.ts suite 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.

Comment on lines +5 to +9
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';

Comment on lines +42 to +46
const ctx = createRequestContext({ pricesIncludeTax: false });

function check(order: Order, args: ConfigArg[]) {
return containsProducts.check(ctx, order, args, undefined as any);
}
Comment on lines +18 to +22
* 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
*/
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.

2 participants