mirror of
https://github.com/formbricks/formbricks.git
synced 2026-02-21 00:58:29 -06:00
fix: await stripe setup during org creation
This commit is contained in:
@@ -204,6 +204,41 @@ describe("Organization Service", () => {
|
||||
expect(ensureCloudStripeSetupForOrganization).toHaveBeenCalledWith("org1");
|
||||
});
|
||||
|
||||
test("should still return organization when Stripe setup fails", async () => {
|
||||
const mockOrganization = {
|
||||
id: "org1",
|
||||
name: "Test Org",
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
billing: {
|
||||
billingMode: "stripe" as const,
|
||||
plan: PROJECT_FEATURE_KEYS.FREE,
|
||||
limits: {
|
||||
projects: BILLING_LIMITS.FREE.PROJECTS,
|
||||
monthly: {
|
||||
responses: BILLING_LIMITS.FREE.RESPONSES,
|
||||
miu: BILLING_LIMITS.FREE.MIU,
|
||||
},
|
||||
},
|
||||
stripeCustomerId: null,
|
||||
periodStart: new Date(),
|
||||
period: "monthly" as const,
|
||||
},
|
||||
isAIEnabled: false,
|
||||
whitelabel: false,
|
||||
};
|
||||
|
||||
vi.mocked(prisma.organization.create).mockResolvedValue(mockOrganization);
|
||||
vi.mocked(ensureCloudStripeSetupForOrganization).mockRejectedValueOnce(
|
||||
new Error("stripe temporarily unavailable")
|
||||
);
|
||||
|
||||
const result = await createOrganization({ name: "Test Org" });
|
||||
|
||||
expect(result).toEqual(mockOrganization);
|
||||
expect(ensureCloudStripeSetupForOrganization).toHaveBeenCalledWith("org1");
|
||||
});
|
||||
|
||||
test("should throw DatabaseError on prisma error", async () => {
|
||||
const prismaError = new Prisma.PrismaClientKnownRequestError("Database error", {
|
||||
code: "P2002",
|
||||
|
||||
@@ -145,10 +145,15 @@ export const createOrganization = async (
|
||||
select,
|
||||
});
|
||||
|
||||
// Stripe setup is best-effort and should not block organization creation.
|
||||
void Promise.resolve(ensureCloudStripeSetupForOrganization(organization.id)).catch((error) => {
|
||||
logger.warn({ error, organizationId: organization.id }, "Background Stripe setup failed");
|
||||
});
|
||||
// Stripe setup is best-effort but should be attempted before we return.
|
||||
try {
|
||||
await ensureCloudStripeSetupForOrganization(organization.id);
|
||||
} catch (error) {
|
||||
logger.warn(
|
||||
{ error, organizationId: organization.id },
|
||||
"Stripe setup failed after organization creation"
|
||||
);
|
||||
}
|
||||
|
||||
return organization;
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user