Skip to content

Commit

Permalink
refactor: refactor code according to CR
Browse files Browse the repository at this point in the history
  • Loading branch information
darcyYe committed Aug 8, 2024
1 parent 8e46bc9 commit 0313452
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
20 changes: 8 additions & 12 deletions packages/core/src/libraries/quota.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ const notNumber = (): never => {
throw new Error('Only support usage query for numeric quota');
};

const shouldReportSubscriptionUpdates = (planId: string, key: keyof SubscriptionQuota): boolean =>
EnvSet.values.isDevFeaturesEnabled &&
planId === ReservedPlanId.Pro &&

Check warning on line 28 in packages/core/src/libraries/quota.ts

View check run for this annotation

Codecov / codecov/patch

packages/core/src/libraries/quota.ts#L27-L28

Added lines #L27 - L28 were not covered by tests
isReportSubscriptionUpdatesUsageKey(key);

export const createQuotaLibrary = (
queries: Queries,
cloudConnection: CloudConnectionLibrary,
Expand Down Expand Up @@ -165,11 +170,7 @@ export const createQuotaLibrary = (
} = await getTenantSubscriptionData(cloudConnection);

// Do not block Pro plan from adding add-on resources.
if (
isDevFeaturesEnabled &&
planId === ReservedPlanId.Pro &&
isReportSubscriptionUpdatesUsageKey(key)
) {
if (shouldReportSubscriptionUpdates(planId, key)) {
return;
}

Check warning on line 175 in packages/core/src/libraries/quota.ts

View check run for this annotation

Codecov / codecov/patch

packages/core/src/libraries/quota.ts#L166-L175

Added lines #L166 - L175 were not covered by tests

Expand Down Expand Up @@ -276,7 +277,7 @@ export const createQuotaLibrary = (
};

const reportSubscriptionUpdatesUsage = async (key: keyof SubscriptionQuota) => {
const { isCloud, isIntegrationTest, isDevFeaturesEnabled } = EnvSet.values;
const { isCloud, isIntegrationTest } = EnvSet.values;

// Cloud only feature, skip in non-cloud environments
if (!isCloud) {
Expand All @@ -290,12 +291,7 @@ export const createQuotaLibrary = (

const { planId } = await getTenantSubscriptionData(cloudConnection);

// Do not block Pro plan from adding add-on resources.
if (
isDevFeaturesEnabled &&
planId === ReservedPlanId.Pro &&
isReportSubscriptionUpdatesUsageKey(key)
) {
if (shouldReportSubscriptionUpdates(planId, key)) {
await reportSubscriptionUpdates(cloudConnection, key);
}

Check warning on line 296 in packages/core/src/libraries/quota.ts

View check run for this annotation

Codecov / codecov/patch

packages/core/src/libraries/quota.ts#L287-L296

Added lines #L287 - L296 were not covered by tests
};
Expand Down
6 changes: 5 additions & 1 deletion packages/core/src/utils/subscription/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,12 @@ export const getTenantSubscriptionScopeUsage = async (

export const reportSubscriptionUpdates = async (
cloudConnection: CloudConnectionLibrary,
usageKey: ReportSubscriptionUpdatesUsageKey
usageKey: keyof SubscriptionQuota
): Promise<void> => {
if (!isReportSubscriptionUpdatesUsageKey(usageKey)) {
return;
}

const client = await cloudConnection.getClient();
// We only report to the Cloud to notify the resource usage updates, and do not care the response. We will see error logs on the Cloud side if there is any issue.
await trySafe(
Expand Down

0 comments on commit 0313452

Please sign in to comment.