The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
fix generatePerformanceBountyName
Steven Teyc319d1a13d66
diff --git a/apps/web/app/(ee)/api/bounties/[bountyId]/route.ts b/apps/web/app/(ee)/api/bounties/[bountyId]/route.tsindex c638e07ada..2f1bd68ec4 100644--- a/apps/web/app/(ee)/api/bounties/[bountyId]/route.ts+++ b/apps/web/app/(ee)/api/bounties/[bountyId]/route.ts@@ -1,5 +1,5 @@import { recordAuditLog } from "@/lib/api/audit-logs/record-audit-log";-import { generateBountyName } from "@/lib/api/bounties/generate-bounty-name";+import { generatePerformanceBountyName } from "@/lib/api/bounties/generate-performance-bounty-name";import { getBountyWithDetails } from "@/lib/api/bounties/get-bounty-with-details";import { DubApiError } from "@/lib/api/errors";import { throwIfInvalidGroupIds } from "@/lib/api/groups/throw-if-invalid-group-ids";@@ -118,7 +118,8 @@ export const PATCH = withWorkspace(let bountyName = name;if (bounty.type === "performance" && performanceCondition) {- bountyName = generateBountyName({+ bountyName = generatePerformanceBountyName({+ rewardAmount: rewardAmount ?? 0, // this shouldn't happen since we return early if rewardAmount is nullcondition: performanceCondition,});}diff --git a/apps/web/app/(ee)/api/bounties/route.ts b/apps/web/app/(ee)/api/bounties/route.tsindex 5d58542c77..9474538398 100644--- a/apps/web/app/(ee)/api/bounties/route.ts+++ b/apps/web/app/(ee)/api/bounties/route.ts@@ -1,5 +1,5 @@import { recordAuditLog } from "@/lib/api/audit-logs/record-audit-log";-import { generateBountyName } from "@/lib/api/bounties/generate-bounty-name";+import { generatePerformanceBountyName } from "@/lib/api/bounties/generate-performance-bounty-name";import { createId } from "@/lib/api/create-id";import { DubApiError } from "@/lib/api/errors";import { throwIfInvalidGroupIds } from "@/lib/api/groups/throw-if-invalid-group-ids";@@ -119,7 +119,8 @@ export const POST = withWorkspace(let bountyName = name;if (type === "performance" && performanceCondition) {- bountyName = generateBountyName({+ bountyName = generatePerformanceBountyName({+ rewardAmount: rewardAmount ?? 0, // this shouldn't happen since we return early if rewardAmount is nullcondition: performanceCondition,});}diff --git a/apps/web/lib/api/bounties/generate-bounty-name.ts b/apps/web/lib/api/bounties/generate-performance-bounty-name.tssimilarity index 71%rename from apps/web/lib/api/bounties/generate-bounty-name.tsrename to apps/web/lib/api/bounties/generate-performance-bounty-name.tsindex 7fdaf55b19..254ad45f2d 100644--- a/apps/web/lib/api/bounties/generate-bounty-name.ts+++ b/apps/web/lib/api/bounties/generate-performance-bounty-name.ts@@ -3,9 +3,11 @@ import { WORKFLOW_ATTRIBUTE_LABELS } from "@/lib/zod/schemas/workflows";import { currencyFormatter, nFormatter } from "@dub/utils";import { isCurrencyAttribute } from "../workflows/utils";-export const generateBountyName = ({+export const generatePerformanceBountyName = ({+ rewardAmount,condition,}: {+ rewardAmount: number;condition: WorkflowCondition;}) => {const isCurrency = isCurrencyAttribute(condition.attribute);@@ -14,5 +16,5 @@ export const generateBountyName = ({? `${currencyFormatter(condition.value / 100, { trailingZeroDisplay: "stripIfInteger" })} in`: `${nFormatter(condition.value, { full: true })}`;- return `Generate ${valueFormatted} ${attributeLabel.toLowerCase()}`;+ return `Earn ${currencyFormatter(rewardAmount / 100, { trailingZeroDisplay: "stripIfInteger" })} after generating ${valueFormatted} ${attributeLabel.toLowerCase()}`;};diff --git a/apps/web/tests/bounties/index.test.ts b/apps/web/tests/bounties/index.test.tsindex e19589bf80..6e0c7f1788 100644--- a/apps/web/tests/bounties/index.test.ts+++ b/apps/web/tests/bounties/index.test.ts@@ -13,7 +13,7 @@ const submissionBounty = {};const performanceBounty = {- name: "Performance Bounty",+ name: "Earn $10 after generating 100 leads",description: "some description about the bounty",type: "performance",endsAt: null,@@ -27,7 +27,7 @@ describe.sequential("/bounties/**", async () => {// start 5 mins from now to make sure the bounty is fully deleted so it doesn't trigger email sendsconst startsAt = new Date(Date.now() + 5 * 60 * 1000).toISOString();- let bountyId = "";+ let submissionBountyId = "";test("POST /bounties - performance based", async () => {const { status, data: bounty } = await http.post<Bounty>({@@ -71,7 +71,7 @@ describe.sequential("/bounties/**", async () => {...submissionBounty,});- bountyId = bounty.id;+ submissionBountyId = bounty.id;});test("POST /bounties - submission based with rewardDescription", async () => {@@ -120,7 +120,7 @@ describe.sequential("/bounties/**", async () => {test("GET /bounties/{bountyId}", async () => {const { status, data: bounty } = await http.get<Bounty>({- path: `/bounties/${bountyId}`,+ path: `/bounties/${submissionBountyId}`,});expect(status).toEqual(200);@@ -148,7 +148,7 @@ describe.sequential("/bounties/**", async () => {};const { status, data: bounty } = await http.patch<Bounty>({- path: `/bounties/${bountyId}`,+ path: `/bounties/${submissionBountyId}`,body: {...toUpdate,type: "performance", // should skip the type update@@ -165,12 +165,12 @@ describe.sequential("/bounties/**", async () => {test("DELETE /bounties/{bountyId}", async () => {const { status, data: bounty } = await http.delete<{ id: string }>({- path: `/bounties/${bountyId}`,+ path: `/bounties/${submissionBountyId}`,});expect(status).toEqual(200);expect(bounty).toMatchObject({- id: bountyId,+ id: submissionBountyId,});});});