Skip to content

test(core): add unit tests for default shipping line assignment strategy#4926

Open
GabrielRoc wants to merge 1 commit into
vendurehq:masterfrom
GabrielRoc:test/default-shipping-line-assignment-strategy
Open

test(core): add unit tests for default shipping line assignment strategy#4926
GabrielRoc wants to merge 1 commit into
vendurehq:masterfrom
GabrielRoc:test/default-shipping-line-assignment-strategy

Conversation

@GabrielRoc

@GabrielRoc GabrielRoc commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Description

Part of the Phase 3 work tracked in #4835 — adding direct unit tests for uncovered business-logic strategies in @vendure/core.

DefaultShippingLineAssignmentStrategy.assignShippingLineToOrderLines was 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:

  • An order with lines → all lines are returned (assigned to the shipping line).
  • An order with no lines → an empty array is returned.

Coverage of default-shipping-line-assignment-strategy.ts goes to 100% on all metrics.

Breaking changes

None. Test-only change — no production code is modified.

Relates to #4835


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

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
Copilot AI review requested due to automatic review settings July 6, 2026 00:22
@vercel

vercel Bot commented Jul 6, 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:24am

Request Review

@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

This pull request introduces a new unit test file for DefaultShippingLineAssignmentStrategy. It adds two test cases: one verifying that all order lines are assigned to a shipping line, and another confirming an empty array is returned when the order has no lines. No production code or exported entity declarations are modified.

Changes

Area Description
Tests New spec file for DefaultShippingLineAssignmentStrategy with two async test cases covering orders with and without lines

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)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately summarizes the main change: adding unit tests for the default shipping line assignment strategy.
Description check ✅ Passed The description includes a clear summary, breaking changes note, and issue reference; only optional template sections like screenshots/checklist are incomplete.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
packages/core/src/config/shipping-method/default-shipping-line-assignment-strategy.spec.ts (1)

21-36: 📐 Maintainability & Code Quality | 🔵 Trivial

Optional: use toBe to verify reference identity.

Since the implementation returns order.lines directly without copying, toBe(lines) / toBe(order.lines) would more precisely assert the "no-op passthrough" contract than toEqual. 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

📥 Commits

Reviewing files that changed from the base of the PR and between 8dbb6e4 and 15f82ae.

📒 Files selected for processing (1)
  • packages/core/src/config/shipping-method/default-shipping-line-assignment-strategy.spec.ts

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

Comment on lines +17 to +19
const strategy = new DefaultShippingLineAssignmentStrategy();
const ctx = {} as RequestContext;
const shippingLine = {} as ShippingLine;
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