Adds product payload to creation call - #82
Conversation
… logic and tests.
…de detailed response body.
|
Warning Review limit reached
More reviews will be available in 52 minutes and 41 seconds. Learn how PR review limits work. Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file). ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits. 🚦 How do rate limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthrough
ChangesCreateProduct returns created product row
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested labels
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
internal/product/handler_test.go (1)
116-141:⚠️ Potential issue | 🟠 Major | ⚡ Quick winAdd response-body assertions for
CreateProductsuccess.Line 138 validates only status code. The test does not verify that the 201 response actually contains the created product payload (ID + persisted fields), which is the main behavior introduced by this PR.
Suggested assertions for the success case
h.CreateProduct(rr, req) if rr.Code != tt.expectedStatus { t.Errorf("expected status %v, got %v", tt.expectedStatus, rr.Code) } + if tt.name == "Success" { + var got db.Product + if err := json.NewDecoder(rr.Body).Decode(&got); err != nil { + t.Fatalf("failed to decode response body: %v", err) + } + if got.ID == 0 || got.Name != "Test Product" || got.PlatformID != 1 { + t.Errorf("unexpected created product payload: %+v", got) + } + if rr.Header().Get("Content-Type") != "application/json" { + t.Errorf("expected Content-Type application/json, got %v", rr.Header().Get("Content-Type")) + } + }As per coding guidelines, "
**/*_test.go: Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request".🤖 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 `@internal/product/handler_test.go` around lines 116 - 141, The test for CreateProduct handler only validates the HTTP status code at line 138 but does not verify the response body content. Add assertions after the status code check to deserialize the response body from the httptest.ResponseRecorder (rr) for successful cases and verify that it contains the expected created product data including the ID and persisted fields. For each test case in the tests slice, when the expected status is success (201), unmarshal the response body and assert that the returned product matches the expected payload to ensure the main behavior of returning the created product is properly tested.Source: Coding guidelines
🤖 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.
Inline comments:
In `@internal/product/service_test.go`:
- Around line 41-55: The test case for the CreateProduct success scenario in the
postgresService test only asserts that the returned product's Name field is
correct. Expand the assertions after line 52 to verify additional fields of the
returned product contract, including the PlatformID that was passed in the
request and any generated identifier field that should be present in a created
product. This ensures the test adequately covers the full contract of what
CreateProduct returns, not just the name validation.
---
Outside diff comments:
In `@internal/product/handler_test.go`:
- Around line 116-141: The test for CreateProduct handler only validates the
HTTP status code at line 138 but does not verify the response body content. Add
assertions after the status code check to deserialize the response body from the
httptest.ResponseRecorder (rr) for successful cases and verify that it contains
the expected created product data including the ID and persisted fields. For
each test case in the tests slice, when the expected status is success (201),
unmarshal the response body and assert that the returned product matches the
expected payload to ensure the main behavior of returning the created product is
properly tested.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: d805b320-3d63-4288-a8bd-99fc2a7bef7a
📒 Files selected for processing (8)
_bruno/Product/Create Product.ymlinternal/product/db/products.sql.gen.gointernal/product/db/querier.gen.gointernal/product/handler.gointernal/product/handler_test.gointernal/product/products.sqlinternal/product/service.gointernal/product/service_test.go
Description
Code Rabbit Summary
Summary by CodeRabbit
Fixes
Closes #81
Post Deployment Tasks?