The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Add getHighestReachedSocialMetricsThreshold helper
Rafi8bff4eabf1db
diff --git a/apps/web/lib/bounty/social-metrics-milestones.ts b/apps/web/lib/bounty/social-metrics-milestones.tsindex 4bb1074361..1095699001 100644--- a/apps/web/lib/bounty/social-metrics-milestones.ts+++ b/apps/web/lib/bounty/social-metrics-milestones.ts@@ -108,6 +108,21 @@ export function hasReachedSocialMetricsEarningCap({return submission.socialMetricCount >= earningCap;}+// Highest milestone threshold at or below the metric count, or null if no milestone is reached+export function getHighestReachedSocialMetricsThreshold({+ bounty,+ socialMetricCount,+}: {+ bounty: BountyInfoInput | undefined | null;+ socialMetricCount: number | null | undefined;+}) {+ const reached = getSocialMetricsMilestones(bounty).filter(+ ({ threshold }) => threshold <= (socialMetricCount ?? 0),+ );++ return reached.length > 0 ? reached[reached.length - 1].threshold : null;+}+// Reached milestones above approvedSocialMetricThreshold, i.e. the ones awaiting approval and payoutexport function getPendingSocialMetricsMilestones({bounty,diff --git a/apps/web/tests/bounties/social-metrics-milestones.test.ts b/apps/web/tests/bounties/social-metrics-milestones.test.tsindex 6c0670866c..9a51ef2700 100644--- a/apps/web/tests/bounties/social-metrics-milestones.test.ts+++ b/apps/web/tests/bounties/social-metrics-milestones.test.ts@@ -1,5 +1,6 @@import {buildMilestonesCommissionDescription,+ getHighestReachedSocialMetricsThreshold,getPendingSocialMetricsMilestones,getSocialMetricsEarningCap,getSocialMetricsMilestoneStatus,@@ -122,6 +123,47 @@ describe("hasReachedSocialMetricsEarningCap", () => {});});+describe("getHighestReachedSocialMetricsThreshold", () => {+ it("returns null before the min count is reached", () => {+ expect(+ getHighestReachedSocialMetricsThreshold({+ bounty: bonusBounty,+ socialMetricCount: 999,+ }),+ ).toBeNull();+ expect(+ getHighestReachedSocialMetricsThreshold({+ bounty: bonusBounty,+ socialMetricCount: null,+ }),+ ).toBeNull();+ });++ it("returns the highest milestone at or below the count", () => {+ expect(+ getHighestReachedSocialMetricsThreshold({+ bounty: bonusBounty,+ socialMetricCount: 2500,+ }),+ ).toBe(2000);+ expect(+ getHighestReachedSocialMetricsThreshold({+ bounty: bonusBounty,+ socialMetricCount: 3000,+ }),+ ).toBe(3000);+ });++ it("stops at the earning cap", () => {+ expect(+ getHighestReachedSocialMetricsThreshold({+ bounty: bonusBounty,+ socialMetricCount: 10_000,+ }),+ ).toBe(6000);+ });+});+describe("getPendingSocialMetricsMilestones", () => {it("returns nothing before the min count is reached", () => {expect(