Skip to content

feat: use discount info endpoint for streak discount information (#1763) - #7

Merged
nsprenkle merged 1 commit into
masterfrom
nsprenkle/streak-discount-endpoint
Aug 7, 2025
Merged

feat: use discount info endpoint for streak discount information (#1763)#7
nsprenkle merged 1 commit into
masterfrom
nsprenkle/streak-discount-endpoint

Conversation

@nsprenkle

Copy link
Copy Markdown
Member

Proxied from @NawfalAhmed, selectively merging openedx#1763 from openedx upstream.

  • feat: use discount info endpoint for streak discount information

…nedx#1763)

* feat: use discount info endpoint for streak discount information

* feat: pass course run key to discount code info call

* feat: move changes behind a flag

* fix: use async IIFE inside useEffect

* fix: fix line length

* fix: remove default value in dev

* fix: improve coverage by adding conditional test based on env value

* refactor: move logic inside function

* refactor: move functions to utils

* fix: ignore merge config
Copilot AI review requested due to automatic review settings August 6, 2025 16:53

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces a new discount information endpoint for determining streak discount percentages, providing a fallback mechanism to the existing ecommerce-based discount calculation. The change allows the application to use a dedicated discount code service when available, while maintaining compatibility with the previous ecommerce API approach.

Key changes:

  • Added support for DISCOUNT_CODE_INFO_URL configuration option
  • Implemented new getDiscountCodePercentage function as primary discount calculation method
  • Refactored existing discount logic to use the new endpoint when available, falling back to ecommerce API

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/shared/streak-celebration/utils.jsx Added new discount calculation functions and exports
src/shared/streak-celebration/StreakCelebrationModal.jsx Refactored discount calculation to use new endpoint with fallback logic
src/shared/streak-celebration/StreakCelebrationModal.test.jsx Added test for new discount endpoint functionality
src/index.jsx Added DISCOUNT_CODE_INFO_URL to configuration
.env, .env.development, .env.test Added DISCOUNT_CODE_INFO_URL environment variable
Comments suppressed due to low confidence (1)

src/shared/streak-celebration/StreakCelebrationModal.jsx:169

  • The istanbul ignore comment suggests this configuration code is not covered by tests. Consider adding test coverage for the configuration merging logic to ensure environment variables are properly handled.
        { queryingDiscount && (

const result = await getAuthenticatedHttpClient().get(url);
const { isApplicable, discountPercentage } = camelCaseObject(result).data;

return isApplicable ? +discountPercentage : 0;

Copilot AI Aug 6, 2025

Copy link

Choose a reason for hiding this comment

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

[nitpick] Using the unary plus operator (+) for type conversion is less clear than explicit conversion methods. Consider using Number(discountPercentage) or parseFloat(discountPercentage) for better readability.

Suggested change
return isApplicable ? +discountPercentage : 0;
return isApplicable ? Number(discountPercentage) : 0;

Copilot uses AI. Check for mistakes.
@nsprenkle
nsprenkle merged commit 5e922a1 into master Aug 7, 2025
3 of 4 checks passed
@nsprenkle
nsprenkle deleted the nsprenkle/streak-discount-endpoint branch August 7, 2025 15:27
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.

4 participants