test(core): add unit tests for default shipping line assignment strategy#4926
test(core): add unit tests for default shipping line assignment strategy#4926GabrielRoc wants to merge 1 commit into
Conversation
Adds direct unit tests for the DefaultShippingLineAssignmentStrategy, whose `assignShippingLineToOrderLines` method had no direct unit test (0% function coverage). The strategy assigns every OrderLine of the order to the given ShippingLine; the two cases cover a populated order and an order with no lines, taking function/branch/line coverage to 100%. No production code changes. Relates to vendurehq#4835
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📝 WalkthroughWalkthroughThis pull request introduces a new unit test file for Changes
Sequence Diagram(s)Not applicable — this change adds test coverage only, with no new control flow or interaction paths. Possibly related issues
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 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.
🧹 Nitpick comments (1)
packages/core/src/config/shipping-method/default-shipping-line-assignment-strategy.spec.ts (1)
21-36: 📐 Maintainability & Code Quality | 🔵 TrivialOptional: use
toBeto verify reference identity.Since the implementation returns
order.linesdirectly without copying,toBe(lines)/toBe(order.lines)would more precisely assert the "no-op passthrough" contract thantoEqual. Purely optional given current coverage is already sufficient.
[optional_and_low_reward]♻️ Optional tightening of assertions
const result = await strategy.assignShippingLineToOrderLines(ctx, shippingLine, order); - expect(result).toEqual(lines); + expect(result).toBe(lines); });🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/core/src/config/shipping-method/default-shipping-line-assignment-strategy.spec.ts` around lines 21 - 36, The spec for default-shipping-line-assignment-strategy is asserting value equality with toEqual, but the implementation in assignShippingLineToOrderLines is a direct passthrough of order.lines. Tighten the assertions in this test to use reference identity checks (toBe) for the returned array, especially against the original lines/order.lines, so the contract verifies no copying occurs.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In
`@packages/core/src/config/shipping-method/default-shipping-line-assignment-strategy.spec.ts`:
- Around line 21-36: The spec for default-shipping-line-assignment-strategy is
asserting value equality with toEqual, but the implementation in
assignShippingLineToOrderLines is a direct passthrough of order.lines. Tighten
the assertions in this test to use reference identity checks (toBe) for the
returned array, especially against the original lines/order.lines, so the
contract verifies no copying occurs.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: fc8b8934-7eda-4a76-bfbd-2812ce175c4c
📒 Files selected for processing (1)
packages/core/src/config/shipping-method/default-shipping-line-assignment-strategy.spec.ts
There was a problem hiding this comment.
Pull request overview
Adds direct, database-free Vitest unit coverage for DefaultShippingLineAssignmentStrategy.assignShippingLineToOrderLines in @vendure/core, aligning with the Phase 3 goal of issue #4835 to unit-test previously transitively-covered strategy logic.
Changes:
- Introduces a new unit spec verifying that all order lines are assigned (returned) when an order has lines.
- Adds a unit spec verifying an empty result when the order has no lines.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const strategy = new DefaultShippingLineAssignmentStrategy(); | ||
| const ctx = {} as RequestContext; | ||
| const shippingLine = {} as ShippingLine; |
Description
Part of the Phase 3 work tracked in #4835 — adding direct unit tests for uncovered business-logic strategies in
@vendure/core.DefaultShippingLineAssignmentStrategy.assignShippingLineToOrderLineswas only exercised transitively (0% direct function coverage). This PR adds a small, database-free unit spec covering the two partitions of the order's line set:Coverage of
default-shipping-line-assignment-strategy.tsgoes to 100% on all metrics.Breaking changes
None. Test-only change — no production code is modified.
Relates to #4835
Need help on this PR? Tag
/codesmithwith what you need. Autofix is disabled.