-
Notifications
You must be signed in to change notification settings - Fork 0
Add comprehensive tests for medusa-service create/update methods #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
- 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
WalkthroughThe update modifies the internal handling of input data in the Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant MedusaService
participant UnderlyingService
Client->>MedusaService: update(data, context)
MedusaService->>UnderlyingService: update(data, context)
UnderlyingService-->>MedusaService: updatedData
MedusaService->>Client: serialize(updatedData)
This diagram illustrates the revised control flow for the 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (2)
🔇 Additional comments (5)
✨ Finishing Touches
🧪 Generate unit tests
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Summary
This PR adds comprehensive test coverage for the
create
andupdate
methods in the MedusaService factory, addressing the bug where theupdate
method was always returning arrays even when single objects were passed as input.Changes Made
🧪 Test Coverage Added
create
andupdate
method mocks for all container services🐛 Bug Fix
const serviceData = Array.isArray(data) ? data : [data]
toconst serviceData = data
Test Cases Added
Main Model Tests
createMainModelMocks
with single object input → single object outputcreateMainModelMocks
with array input → array outputupdateMainModelMocks
with single object input → single object outputupdateMainModelMocks
with array input → array outputOther Model Tests
createOtherModelMock1s
with single object input → single object outputcreateOtherModelMock1s
with array input → array outputupdateOtherModelMock1s
with single object input → single object outputupdateOtherModelMock1s
with array input → array outputProblem Solved
Before: The
update
method always wrapped input data in an array, causing inconsistent return types:After: The
update
method preserves input type:Validation
These tests ensure that:
create
andupdate
methods are thoroughly testedThe tests would fail with the old buggy code and pass with the fixed implementation, providing robust validation of the fix.
Related to: Original issue where medusa-service generated update functions always return array of data even when only single object is passed
Requested by: @dwene
💻 View my work • About Codegen
Summary by CodeRabbit
Bug Fixes
Tests