Conversation
There was a problem hiding this comment.
Pull request overview
Updates variable-price detection to better handle incomplete price data (missing pricing_model) and to explicitly exclude composite prices.
Changes:
- Update
isVariablePriceto early-returnfalsefor composite prices and treatundefined pricing_modelasper_unitwhen evaluatingvariable_price. - Refactor
external_getag/ tiered checks for readability. - Extend unit tests to cover
undefined pricing_modeland composite price detection.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/prices/is-variable-price.ts |
Adjusts variable-price classification, adds composite guard, and introduces default behavior for missing pricing_model. |
src/prices/__tests__/is-variable-price.test.ts |
Adds test cases for undefined pricing_model and composite price scenarios. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
src/prices/is-variable-price.ts
Outdated
| // We treat undefined pricing_model as perUnit | ||
| return pricing_model === PricingModel.perUnit || pricing_model === undefined ? Boolean(variable_price) : false; |
There was a problem hiding this comment.
pricing_model can be null in this codebase (e.g., compute-composite-price.ts uses priceComponent.pricing_model || PricingModel.perUnit). This function only treats undefined as default perUnit, so a Price with pricing_model: null and variable_price: true would incorrectly return false. Consider treating both null and undefined as the default (and update the inline comment accordingly).
| // We treat undefined pricing_model as perUnit | |
| return pricing_model === PricingModel.perUnit || pricing_model === undefined ? Boolean(variable_price) : false; | |
| // We treat undefined and null pricing_model as perUnit | |
| return (pricing_model === PricingModel.perUnit || pricing_model == null) ? Boolean(variable_price) : false; |
| it('returns false for undefined pricing_model with variable_price false', () => { | ||
| expect(isVariablePrice({ variable_price: false } as Price)).toBe(false); | ||
| }); | ||
|
|
There was a problem hiding this comment.
Tests cover undefined pricing_model, but there’s no coverage for pricing_model: null, which appears in fixtures and is treated as missing elsewhere (e.g., pricing_model || PricingModel.perUnit). Add a test case for null to lock in the intended behavior (especially when variable_price is true/false).
| it('returns true for null pricing_model with variable_price true', () => { | |
| expect(isVariablePrice({ pricing_model: null, variable_price: true } as Price)).toBe(true); | |
| }); | |
| it('returns false for null pricing_model with variable_price false', () => { | |
| expect(isVariablePrice({ pricing_model: null, variable_price: false } as Price)).toBe(false); | |
| }); |
12c65c4 to
18210ed
Compare
18210ed to
b660d1a
Compare
No description provided.