Skip to content

Handle undefined pricing_model#262

Merged
jnmau merged 2 commits intomainfrom
feat/variable-price-helper
Mar 12, 2026
Merged

Handle undefined pricing_model#262
jnmau merged 2 commits intomainfrom
feat/variable-price-helper

Conversation

@jnmau
Copy link
Member

@jnmau jnmau commented Mar 12, 2026

No description provided.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates variable-price detection to better handle incomplete price data (missing pricing_model) and to explicitly exclude composite prices.

Changes:

  • Update isVariablePrice to early-return false for composite prices and treat undefined pricing_model as per_unit when evaluating variable_price.
  • Refactor external_getag / tiered checks for readability.
  • Extend unit tests to cover undefined pricing_model and 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.

Comment on lines +27 to +28
// We treat undefined pricing_model as perUnit
return pricing_model === PricingModel.perUnit || pricing_model === undefined ? Boolean(variable_price) : false;
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

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

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

Suggested change
// 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;

Copilot uses AI. Check for mistakes.
it('returns false for undefined pricing_model with variable_price false', () => {
expect(isVariablePrice({ variable_price: false } as Price)).toBe(false);
});

Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

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

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

Suggested change
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);
});

Copilot uses AI. Check for mistakes.
@jnmau jnmau force-pushed the feat/variable-price-helper branch from 12c65c4 to 18210ed Compare March 12, 2026 16:12
@jnmau jnmau force-pushed the feat/variable-price-helper branch from 18210ed to b660d1a Compare March 12, 2026 16:18
@jnmau jnmau merged commit 2f7a434 into main Mar 12, 2026
2 checks passed
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