Skip to content

Commit a1c0daa

Browse files
authored
fix: buy credit option not visible (calcom#22721)
1 parent b155d73 commit a1c0daa

5 files changed

Lines changed: 51 additions & 4 deletions

File tree

apps/web/modules/settings/billing/components/BillingCredits.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,12 @@ export default function BillingCredits() {
192192
</div>
193193
</div>
194194
<div className="mt-auto">
195-
<Button color="primary" target="_blank" EndIcon="external-link" type="submit">
195+
<Button
196+
color="primary"
197+
target="_blank"
198+
EndIcon="external-link"
199+
type="submit"
200+
data-testid="buy-credits">
196201
{t("buy_credits")}
197202
</Button>
198203
</div>
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { expect } from "@playwright/test";
2+
import type { Page } from "@playwright/test";
3+
4+
import { test } from "./lib/fixtures";
5+
6+
test.describe.configure({ mode: "parallel" });
7+
test.afterEach(({ users }) => users.deleteAll());
8+
9+
test.describe("Buy Credits E2E Tests", () => {
10+
test("should display buy credits option for personal account", async ({ page, users }) => {
11+
const user = await users.create();
12+
await user.apiLogin();
13+
14+
await page.goto("/settings/billing");
15+
16+
await expectBuyCreditsButtonVisibleAndEnabled(page);
17+
});
18+
19+
test("should display buy credits option for team account", async ({ page, users }) => {
20+
const teamOwner = await users.create(
21+
{ username: "team-owner", name: "Team Owner" },
22+
{
23+
hasTeam: true,
24+
teammates: [{ name: "teammate-1" }],
25+
}
26+
);
27+
await teamOwner.apiLogin();
28+
29+
const { team } = await teamOwner.getFirstTeamMembership();
30+
31+
await page.goto(`/settings/teams/${team.id}/billing`);
32+
33+
await expectBuyCreditsButtonVisibleAndEnabled(page);
34+
});
35+
});
36+
37+
async function expectBuyCreditsButtonVisibleAndEnabled(page: Page) {
38+
const buyCreditsButton = page.getByTestId("buy-credits");
39+
await expect(buyCreditsButton).toBeVisible();
40+
await expect(buyCreditsButton).toBeEnabled();
41+
}

packages/lib/constants.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,8 @@ export const IS_DUB_REFERRALS_ENABLED =
225225

226226
export const CAL_VIDEO_MEETING_LINK_FOR_TESTING = process.env.CAL_VIDEO_MEETING_LINK_FOR_TESTING;
227227

228-
export const IS_SMS_CREDITS_ENABLED = !!process.env.NEXT_PUBLIC_STRIPE_CREDITS_PRICE_ID;
228+
export const IS_SMS_CREDITS_ENABLED =
229+
!!process.env.NEXT_PUBLIC_STRIPE_CREDITS_PRICE_ID || !!process.env.NEXT_PUBLIC_IS_E2E;
229230
export const DATABASE_CHUNK_SIZE = parseInt(process.env.DATABASE_CHUNK_SIZE || "25", 10);
230231

231232
export const NEXTJS_CACHE_TTL = 3600; // 1 hour

packages/trpc/server/routers/viewer/credits/buyCredits.handler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export const buyCreditsHandler = async ({ ctx, input }: BuyCreditsOptions) => {
3636
// if user id is part of a team, user can't buy credits for themselves
3737
const memberships = await MembershipRepository.findAllAcceptedPublishedTeamMemberships(ctx.user.id);
3838

39-
if (!memberships || memberships.length > 0) {
39+
if (memberships && memberships.length > 0) {
4040
throw new TRPCError({
4141
code: "UNAUTHORIZED",
4242
});

packages/trpc/server/routers/viewer/credits/getAllCredits.handler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export const getAllCreditsHandler = async ({ ctx, input }: GetAllCreditsOptions)
2727
//if user is part of team, don't return any credits if teamId is not given
2828
const memberships = await MembershipRepository.findAllAcceptedPublishedTeamMemberships(ctx.user.id);
2929

30-
if (!memberships || memberships.length > 0) {
30+
if (memberships && memberships.length > 0) {
3131
return null;
3232
}
3333
}

0 commit comments

Comments
 (0)