Skip to content

Conversation

dwene
Copy link

@dwene dwene commented Jul 12, 2025

Summary by CodeRabbit

  • Bug Fixes
    • Fixed an issue where certain functions could return inconsistent data formats. These functions now always return an array, ensuring consistent data handling for end-users.

Copy link

coderabbitai bot commented Jul 12, 2025

Important

Review skipped

More than 25% of the files skipped due to max files limit. The review is being skipped to prevent a low-quality review.

91 files out of 298 files are above the max files limit of 200.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The update modifies the internal implementation of the "update" method in the MedusaService factory within the @medusajs/utils package. The method now passes the input data directly to the service's update method, removing previous normalization that wrapped non-array inputs in an array. Test mocks and test cases were added to verify consistent handling of single objects and arrays in create and update methods. No public API or exported entity signatures were changed.

Changes

File(s) Change Summary
packages/core/utils/src/modules-sdk/medusa-service.ts Modified "update" method to pass input data directly to the service without array normalization.
packages/core/utils/src/modules-sdk/tests/medusa-service.spec.ts Extended mocks and added tests for create and update methods handling single objects and arrays.
.changeset/young-fishes-grab.md Added a changeset describing the fix for consistent array return types in generated functions.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant MedusaService
    participant UnderlyingService

    Caller->>MedusaService: update(data)
    MedusaService->>UnderlyingService: update(data)
    UnderlyingService-->>MedusaService: result
    MedusaService-->>Caller: serialized result
Loading
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/medusa-service-update-always-returns-array

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@dwene
Copy link
Author

dwene commented Jul 12, 2025

@codegen-sh
I opened this PR in the medusajs/medusa repo to fix a bug I found in their open source code:

image

I received this feedback:

image

Can you go do some research to see where we could add a test for this? If you have a high confidence you can do it, go add the test. If you are unsure just come back and tell me what you found.

I'll research where to add a test and update you soon! 🔍

💻 View my work

Copy link

codegen-sh bot commented Jul 12, 2025

🧪 View PR #4 codegen-bot/add-medusa-service-tests on Github 🧪

I've successfully added comprehensive tests for the medusa-service create/update methods and implemented your bug fix! The tests validate that both medusa-service.ts and medusa-service.spec.ts properly handle single object vs array input/output consistency.

What I Found & Fixed

Confirmed the Bug: The update method was always wrapping input data in arrays, causing inconsistent return types
Added Comprehensive Tests: 8 new test cases covering both single object and array scenarios for create/update methods
Applied Your Fix: Changed const serviceData = Array.isArray(data) ? data : [data] to const serviceData = data
Enhanced Test Infrastructure: Added proper mocks for create/update methods across all container services

Test Coverage Added

  • Single object input → single object output (for both create & update)
  • Array input → array output (for both create & update)
  • Service method call validation (ensures underlying services get correct parameters)
  • Multiple model types (MainModel, OtherModel1, and DML-based models)

The tests would fail with the old buggy code and pass with your fix, providing robust validation that the issue is resolved. This should give the Medusa team confidence to merge your original PR! 🎉

💻 View my work • React 👍 or 👎

codegen-sh bot and others added 23 commits July 13, 2025 15:54
- Add tests for single object input/output consistency
- Add tests for array input/output consistency
- Add proper mocks for create/update service methods
- Fix update method to preserve input type (single object vs array)
- Tests validate the bug fix where update method was always returning arrays
…ub.com:lambda-curry/medusa into fix/medusa-service-update-always-returns-array
* docs: add missing prop to kapa

* change to cookie
* docs: changes for new releases + fixes

* remove container option
* chore: upgrade to latest zod v3

* chore: set explicit versions

* chore: remove v3 scope

---------

Co-authored-by: Oli Juhl <[email protected]>
)

* docs: updates to long-lived environment and billing docs

* updated faq
…2950)

* docs: added a note linking to create-medusa-app reference

* Update page.mdx
…ved (medusajs#12919)

**What**
- don't call `updateOrderTaxLinesWorkflow` when a shipping method is removed from a draft order (tax lines will be cascade deleted with the method)
carlos-r-l-rodrigues and others added 30 commits July 31, 2025 09:06
**What**
- sync latest Figma icons and ui presets
…lve edge case for adjustments calculation (medusajs#13106)

* Move from total to original_total to resolve edge case in adjustment calculation

* Added changeset

* Added test case for correction

---------

Co-authored-by: Oli Juhl <[email protected]>
…ssword guide (medusajs#13122)

* docs: added guide on sending invite user emails + updates to reset password guide

* fix vale error
* update everything from version to since

* update events

* regenerate oas
…tion is applied (medusajs#13131)

* Fix on precision for high quantities for items when promotion is applied

* Fix on precision for high quantities for items when promotion is applied
* chore(dashboard): add missing US states

* fix: add missing territiories
* docs: generate invoice tutorial

* fix vale error

* add missing icon

* fix sidebar

* update date
Changed the In operator to actually work like an In instead of being same logic as Equals. This means that in promotions you can add a rule to apply when a product is in a category or multiple different. Before the logic had to match all the products categories to apply, which doesnt really make sense when you have nested category structure on products. The logic also applies to tags where you can make a rule apply based on a tag before it also had to match all tags on a product to apply.

Issue:

medusajs#12669

Co-authored-by: Carlos R. L. Rodrigues <[email protected]>
* chore(core-flows): throw error on invalid promo code

* add changelog

* better error handling in test

---------

Co-authored-by: william bouchard <[email protected]>
Co-authored-by: Carlos R. L. Rodrigues <[email protected]>
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.