Skip to content

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

Merged
grolmus merged 3 commits into
vendurehq:masterfrom
GabrielRoc:test/contains-products-condition
Jul 16, 2026
Merged

test(core): Add unit tests for contains-products promotion condition#4881
grolmus merged 3 commits into
vendurehq:masterfrom
GabrielRoc:test/contains-products-condition

Conversation

@GabrielRoc

@GabrielRoc GabrielRoc commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

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 Jul 6, 2026 12:14am

Request Review

@vendure-ci-automation-bot

vendure-ci-automation-bot Bot commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@coderabbitai

coderabbitai Bot commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 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
Description check ✅ Passed The description includes the summary, breaking changes, checklist, and related issue; only screenshots are omitted, which is non-critical.
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.
Title check ✅ Passed The title accurately summarizes the main change: adding unit tests for the contains-products promotion condition.
✨ 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';

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

@GabrielRoc

Copy link
Copy Markdown
Contributor Author

I have read the CLA Document and I hereby sign the CLA

@GabrielRoc

Copy link
Copy Markdown
Contributor Author

recheck

@grolmus grolmus changed the title test(core): add unit tests for contains-products promotion condition test(core): Add unit tests for contains-products promotion condition Jul 16, 2026

@grolmus grolmus left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

@grolmus
grolmus enabled auto-merge (squash) July 16, 2026 11:33
@grolmus
grolmus merged commit 7ded961 into vendurehq:master Jul 16, 2026
19 checks passed
@vendure-ci-automation-bot vendure-ci-automation-bot Bot locked and limited conversation to collaborators Jul 16, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants