Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

test improvements

Pedro Ladeiraec29715db3cd
diff --git a/apps/web/lib/actions/partners/create-program-application.ts b/apps/web/lib/actions/partners/create-program-application.ts
index acb8e0b6c3..9668d1e3d7 100644
--- a/apps/web/lib/actions/partners/create-program-application.ts
+++ b/apps/web/lib/actions/partners/create-program-application.ts
@@ -1,7 +1,7 @@
"use server";
import { createId } from "@/lib/api/create-id";
-import { isCI, isLocalDev } from "@/lib/api/environment";
+import { isCI, isLocalDev, shouldApplyRateLimit } from "@/lib/api/environment";
import { detectAndRecordFraudApplication } from "@/lib/api/fraud/detect-record-fraud-application";
import { notifyPartnerApplication } from "@/lib/api/partners/notify-partner-application";
import { queuePartnerSearchSync } from "@/lib/api/partners/queue-partner-search-sync";
@@ -124,12 +124,14 @@ export const createProgramApplicationAction = actionClient
const { programId, groupId, inAppApplication } = parsedInput;
// Limit to 3 requests per minute per program per IP
- const { success } = await ratelimit(3, "1 m").limit(
- `create-program-application:${programId}:${await getIP()}`,
- );
+ if (shouldApplyRateLimit) {
+ const { success } = await ratelimit(3, "1 m").limit(
+ `create-program-application:${programId}:${await getIP()}`,
+ );
- if (!success) {
- throw new Error("Too many requests. Please try again later.");
+ if (!success) {
+ throw new Error("Too many requests. Please try again later.");
+ }
}
const program = await prisma.program.findUniqueOrThrow({
diff --git a/apps/web/playwright/partners/application.spec.ts b/apps/web/playwright/partners/application.spec.ts
index a4d5afcdba..c810f6507a 100644
--- a/apps/web/playwright/partners/application.spec.ts
+++ b/apps/web/playwright/partners/application.spec.ts
@@ -10,11 +10,7 @@ import {
} from "@playwright/test";
import { hashSync } from "bcryptjs";
import { PLAYWRIGHT_API_BASE } from "../api/constants";
-import {
- createApiClient,
- loadApiAuth,
- type ApiClient,
-} from "../api/fixtures";
+import { createApiClient, loadApiAuth } from "../api/fixtures";
import {
TEST_APPLICATION_FIELD_VALUES,
TEST_APPLICATION_FORM,
@@ -160,17 +156,7 @@ test.describe("Marketplace application form", () => {
page.getByRole("link", { name: "Back to marketplace" }),
).toBeVisible();
- const { status, data } = await api.get<PartnerApplicationProps[]>(
- "/api/partners/applications?pageSize=100",
- );
- expect(status).toEqual(200);
- expect(
- data.find(
- (application) =>
- application.partner.email === APPLY_PARTNER.email &&
- application.partner.status === "pending",
- ),
- ).toMatchObject(expectedPendingApplication);
+ await expectPendingApplication(api, partner.id);
} finally {
await cleanupApplication({ partnerId: partner.id });
await api.dispose();
@@ -209,17 +195,7 @@ test.describe("In-app program page application form", () => {
page.getByRole("link", { name: "Back to programs" }),
).toBeVisible();
- const { status, data } = await api.get<PartnerApplicationProps[]>(
- "/api/partners/applications?pageSize=100",
- );
- expect(status).toEqual(200);
- expect(
- data.find(
- (application) =>
- application.partner.email === APPLY_PARTNER.email &&
- application.partner.status === "pending",
- ),
- ).toMatchObject(expectedPendingApplication);
+ await expectPendingApplication(api, partner.id);
} finally {
await cleanupApplication({ partnerId: partner.id });
await api.dispose();
@@ -265,6 +241,19 @@ async function loginAsApplyPartner(page: Page) {
);
}
+async function expectPendingApplication(
+ api: Awaited<ReturnType<typeof createWorkspaceApi>>,
+ partnerId: string,
+) {
+ const { status, data } = await api.get<PartnerApplicationProps[]>(
+ "/api/partners/applications?pageSize=100",
+ );
+ expect(status).toEqual(200);
+ expect(
+ data.find((application) => application.partner.id === partnerId),
+ ).toMatchObject(expectedPendingApplication);
+}
+
async function ensureApprovedApplyPartner() {
const passwordHash = hashSync(APPLY_PARTNER.password, 10);
@@ -330,8 +319,7 @@ async function ensureApprovedApplyPartner() {
data: {
country: "US",
image: `https://api.dicebear.com/9.x/micah/png?seed=${partner.id}`,
- description:
- "Playwright partner used for program application e2e tests.",
+ description: "Playwright partner used for program application e2e tests.",
monthlyTraffic: "ZeroToOneThousand",
networkStatus: "approved",
},
@@ -372,9 +360,7 @@ async function ensureApprovedApplyPartner() {
skipDuplicates: true,
}),
prisma.partnerSalesChannel.createMany({
- data: [
- { partnerId: partner.id, salesChannel: "Blogs" },
- ],
+ data: [{ partnerId: partner.id, salesChannel: "Blogs" }],
skipDuplicates: true,
}),
]);
diff --git a/apps/web/ui/partners/program-application-sheet.tsx b/apps/web/ui/partners/program-application-sheet.tsx
index 6ca06cd861..f1b4ed3a6f 100644
--- a/apps/web/ui/partners/program-application-sheet.tsx
+++ b/apps/web/ui/partners/program-application-sheet.tsx
@@ -102,11 +102,13 @@ function ProgramApplicationSheetForm({
register,
handleSubmit,
setError,
- formState: { errors, isSubmitting, isSubmitSuccessful },
+ formState: { errors, isSubmitting },
} = form;
+ const [isSubmitted, setIsSubmitted] = useState(false);
const { executeAsync } = useAction(createProgramApplicationAction, {
onSuccess: () => {
+ setIsSubmitted(true);
mutate(`/api/partner-profile/programs/${program!.slug}`);
onSuccess?.();
},
@@ -149,10 +151,10 @@ function ProgramApplicationSheetForm({
onSubmit={handleSubmit(onSubmit)}
className={cn(
"flex h-full flex-col transition-opacity duration-200",
- isSubmitSuccessful && "pointer-events-none opacity-0",
+ isSubmitted && "pointer-events-none opacity-0",
)}
{...{
- inert: isSubmitSuccessful,
+ inert: isSubmitted,
}}
>
<div className="sticky top-0 z-10 border-b border-neutral-200 bg-neutral-50">
@@ -260,11 +262,11 @@ function ProgramApplicationSheetForm({
<div
className={cn(
"absolute inset-0 flex items-center justify-center transition-[transform,opacity]",
- isSubmitSuccessful
+ isSubmitted
? "translate-y-0 opacity-100"
: "pointer-events-none translate-y-4 opacity-0",
)}
- inert={!isSubmitSuccessful}
+ inert={!isSubmitted}
>
<Grid
cellSize={60}