The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
fix award bounty tests (deleteBountyAndSubmissions)
Steven Tey773bf15cdf2c
diff --git a/apps/web/app/(ee)/api/e2e/bounties/[bountyId]/route.ts b/apps/web/app/(ee)/api/e2e/bounties/[bountyId]/route.tsnew file mode 100644index 0000000000..69088b5378--- /dev/null+++ b/apps/web/app/(ee)/api/e2e/bounties/[bountyId]/route.ts@@ -0,0 +1,38 @@+import { withWorkspace } from "@/lib/auth";+import { prisma } from "@dub/prisma";+import { ACME_PROGRAM_ID } from "@dub/utils";+import { NextResponse } from "next/server";+import { assertE2EWorkspace } from "../../guard";++// special endpoint to delete a bounty and all associated submissions (only for e2e tests)+export const DELETE = withWorkspace(async ({ params, workspace }) => {+ assertE2EWorkspace(workspace);++ const { bountyId } = params;++ await prisma.$transaction(async (tx) => {+ await tx.bountySubmission.deleteMany({+ where: {+ bountyId,+ programId: ACME_PROGRAM_ID,+ },+ });+ const bounty = await tx.bounty.delete({+ where: {+ id: bountyId,+ programId: ACME_PROGRAM_ID,+ },+ });++ if (bounty.workflowId) {+ await tx.workflow.delete({+ where: {+ id: bounty.workflowId,+ programId: ACME_PROGRAM_ID,+ },+ });+ }+ });++ return NextResponse.json({ id: bountyId });+});diff --git a/apps/web/app/(ee)/api/e2e/trigger-workflow/[workflowId]/route.ts b/apps/web/app/(ee)/api/e2e/trigger-workflow/[workflowId]/route.tsindex 99c03f8bb8..bd992e1101 100644--- a/apps/web/app/(ee)/api/e2e/trigger-workflow/[workflowId]/route.ts+++ b/apps/web/app/(ee)/api/e2e/trigger-workflow/[workflowId]/route.ts@@ -4,6 +4,7 @@ import { parseWorkflowConfig } from "@/lib/api/workflows/parse-workflow-config";import { withWorkspace } from "@/lib/auth";import { WORKFLOW_ACTION_TYPES } from "@/lib/zod/schemas/workflows";import { prisma } from "@dub/prisma";+import { ACME_PROGRAM_ID } from "@dub/utils";import { NextResponse } from "next/server";import { assertE2EWorkspace } from "../../guard";@@ -16,7 +17,7 @@ export const POST = withWorkspace(async ({ workspace, params }) => {try {const workflow = await prisma.workflow.findUnique({- where: { id: workflowId },+ where: { id: workflowId, programId: ACME_PROGRAM_ID },});if (!workflow) {diff --git a/apps/web/app/(ee)/api/e2e/workflows/[workflowId]/route.ts b/apps/web/app/(ee)/api/e2e/workflows/[workflowId]/route.tsindex 934d9cd9b4..0728435954 100644--- a/apps/web/app/(ee)/api/e2e/workflows/[workflowId]/route.ts+++ b/apps/web/app/(ee)/api/e2e/workflows/[workflowId]/route.ts@@ -1,5 +1,6 @@import { withWorkspace } from "@/lib/auth";import { prisma } from "@dub/prisma";+import { ACME_PROGRAM_ID } from "@dub/utils";import { NextResponse } from "next/server";import { assertE2EWorkspace } from "../../guard";@@ -12,7 +13,7 @@ export const PATCH = withWorkspace(const body = await req.json();const workflow = await prisma.workflow.update({- where: { id: workflowId },+ where: { id: workflowId, programId: ACME_PROGRAM_ID },data: {disabledAt: body.disabledAt ? new Date(body.disabledAt) : null,},diff --git a/apps/web/tests/workflows/award-bounty-workflow.test.ts b/apps/web/tests/workflows/award-bounty-workflow.test.tsindex 6b07f8e7de..43a31b76f8 100644--- a/apps/web/tests/workflows/award-bounty-workflow.test.ts+++ b/apps/web/tests/workflows/award-bounty-workflow.test.ts@@ -1,8 +1,10 @@import { EnrolledPartnerProps } from "@/lib/types";import { Bounty } from "@dub/prisma/client";+import { E2E_PARTNER_GROUP } from "tests/utils/resource";import { describe, expect, onTestFinished, test } from "vitest";import { randomEmail } from "../utils/helpers";import { IntegrationHarness } from "../utils/integration";+import { deleteBountyAndSubmissions } from "./utils/delete-bounty-and-submissions";import { trackE2ELead } from "./utils/track-e2e-lead";import { verifyBountySubmission } from "./utils/verify-bounty-submission";@@ -24,7 +26,7 @@ describe.sequential("Workflow - AwardBounty", async () => {endsAt: null,rewardAmount: 1000,performanceScope: "new",- groupIds: [],+ groupIds: [E2E_PARTNER_GROUP.id],performanceCondition: {attribute: "totalLeads",operator: "gte",@@ -36,7 +38,10 @@ describe.sequential("Workflow - AwardBounty", async () => {expect(bountyStatus).toEqual(200);onTestFinished(async () => {- await h.deleteBounty(bounty.id);+ await deleteBountyAndSubmissions({+ http,+ bountyId: bounty.id,+ });});const { status: partnerStatus, data: partner } =@@ -81,7 +86,7 @@ describe.sequential("Workflow - AwardBounty", async () => {endsAt: null,rewardAmount: 1000,performanceScope: "new",- groupIds: [],+ groupIds: [E2E_PARTNER_GROUP.id],performanceCondition: {attribute: "totalLeads",operator: "gte",@@ -93,7 +98,10 @@ describe.sequential("Workflow - AwardBounty", async () => {expect(bountyStatus).toEqual(200);onTestFinished(async () => {- await h.deleteBounty(bounty.id);+ await deleteBountyAndSubmissions({+ http,+ bountyId: bounty.id,+ });});const { status: partnerStatus, data: partner } =@@ -138,7 +146,7 @@ describe.sequential("Workflow - AwardBounty", async () => {endsAt: null,rewardAmount: 1000,performanceScope: "new",- groupIds: [],+ groupIds: [E2E_PARTNER_GROUP.id],performanceCondition: {attribute: "totalLeads",operator: "gte",@@ -150,7 +158,10 @@ describe.sequential("Workflow - AwardBounty", async () => {expect(bountyStatus).toEqual(200);onTestFinished(async () => {- await h.deleteBounty(bounty.id);+ await deleteBountyAndSubmissions({+ http,+ bountyId: bounty.id,+ });});// Find workflow via E2E endpoint and disable it@@ -206,7 +217,7 @@ describe.sequential("Workflow - AwardBounty", async () => {endsAt: null,rewardAmount: 1000,performanceScope: "new",- groupIds: [],+ groupIds: [E2E_PARTNER_GROUP.id],performanceCondition: {attribute: "totalLeads",operator: "gte",@@ -218,7 +229,10 @@ describe.sequential("Workflow - AwardBounty", async () => {expect(bountyStatus).toEqual(200);onTestFinished(async () => {- await h.deleteBounty(bounty.id);+ await deleteBountyAndSubmissions({+ http,+ bountyId: bounty.id,+ });});const { status: partnerStatus, data: partner } =diff --git a/apps/web/tests/workflows/utils/delete-bounty-and-submissions.ts b/apps/web/tests/workflows/utils/delete-bounty-and-submissions.tsnew file mode 100644index 0000000000..b943791e0c--- /dev/null+++ b/apps/web/tests/workflows/utils/delete-bounty-and-submissions.ts@@ -0,0 +1,14 @@+import { HttpClient } from "../../utils/http";++// special function to delete a bounty and all associated submissions (only for e2e tests)+export const deleteBountyAndSubmissions = async ({+ http,+ bountyId,+}: {+ http: HttpClient;+ bountyId: string;+}) => {+ await http.delete({+ path: `/e2e/bounties/${bountyId}`,+ });+};