Skip to content

Commit

Permalink
chore: cover useSubscriptions select fn with bff data
Browse files Browse the repository at this point in the history
  • Loading branch information
adamstankiewicz committed Dec 16, 2024
1 parent b806a0f commit fb9b704
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,13 @@ export const useCourseUpgradeData = ({
const location = useLocation();
const canUpgradeToVerifiedEnrollment = isEnrollmentUpgradeable({ mode, enrollBy });
const { data: enterpriseCustomer } = useEnterpriseCustomer();

// Metadata required to determine if the course run is contained in the customer's content catalog(s)
const { data: customerContainsContent } = useEnterpriseCustomerContainsContent([courseRunKey], {
enabled: canUpgradeToVerifiedEnrollment,
});

// Metadata required to allow upgrade via applicable learner credit subsidy
const { data: learnerCreditMetadata } = useCanUpgradeWithLearnerCredit(courseRunKey, {
enabled: canUpgradeToVerifiedEnrollment,
});
Expand All @@ -162,7 +165,8 @@ export const useCourseUpgradeData = ({
const { data: subscriptionLicense } = useSubscriptions({
select: (data) => {
let license;
if (data.transformed) {
if (data?.transformed) {
// If the data has been transformed, use the transformed data.
license = data.transformed.subscriptionLicense;
} else {
license = data?.subscriptionLicense;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,11 +366,18 @@ describe('useCourseUpgradeData', () => {
}),
);
const useSubscriptionsSelectFn = useSubscriptions.mock.calls[0][0].select;
const selectTransformResult = useSubscriptionsSelectFn({ subscriptionLicense: mockSubscriptionLicense });
const selectTransformResultLegacy = useSubscriptionsSelectFn({ subscriptionLicense: mockSubscriptionLicense });
const transformedSubscriptionsBFFData = {
original: { subscriptionLicense: mockSubscriptionLicense },
transformed: { subscriptionLicense: mockSubscriptionLicense },
};
const selectTransformResultBFF = useSubscriptionsSelectFn(transformedSubscriptionsBFFData);
if (subscriptionLicenseStatus === LICENSE_STATUS.ACTIVATED && isSubscriptionPlanCurrent) {
expect(selectTransformResult).toEqual(mockSubscriptionLicense);
expect(selectTransformResultLegacy).toEqual(mockSubscriptionLicense);
expect(selectTransformResultBFF).toEqual(mockSubscriptionLicense);
} else {
expect(selectTransformResult).toBeNull();
expect(selectTransformResultLegacy).toBeNull();
expect(selectTransformResultBFF).toBeNull();
}

// Assert expected output
Expand Down

0 comments on commit fb9b704

Please sign in to comment.