Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,12 @@ export default function BillingCredits() {
</div>
</div>
<div className="mt-auto">
<Button color="primary" target="_blank" EndIcon="external-link" type="submit">
<Button
color="primary"
target="_blank"
EndIcon="external-link"
type="submit"
data-testid="buy-credits">
{t("buy_credits")}
</Button>
</div>
Expand Down
41 changes: 41 additions & 0 deletions apps/web/playwright/buy-credits.e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { expect } from "@playwright/test";
import type { Page } from "@playwright/test";

import { test } from "./lib/fixtures";

test.describe.configure({ mode: "parallel" });
test.afterEach(({ users }) => users.deleteAll());

test.describe("Buy Credits E2E Tests", () => {
test("should display buy credits option for personal account", async ({ page, users }) => {
const user = await users.create();
await user.apiLogin();

await page.goto("/settings/billing");

await expectBuyCreditsButtonVisibleAndEnabled(page);
});

test("should display buy credits option for team account", async ({ page, users }) => {
const teamOwner = await users.create(
{ username: "team-owner", name: "Team Owner" },
{
hasTeam: true,
teammates: [{ name: "teammate-1" }],
}
);
await teamOwner.apiLogin();

const { team } = await teamOwner.getFirstTeamMembership();

await page.goto(`/settings/teams/${team.id}/billing`);

await expectBuyCreditsButtonVisibleAndEnabled(page);
});
});

async function expectBuyCreditsButtonVisibleAndEnabled(page: Page) {
const buyCreditsButton = page.getByTestId("buy-credits");
await expect(buyCreditsButton).toBeVisible();
await expect(buyCreditsButton).toBeEnabled();
}
3 changes: 2 additions & 1 deletion packages/lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,8 @@ export const IS_DUB_REFERRALS_ENABLED =

export const CAL_VIDEO_MEETING_LINK_FOR_TESTING = process.env.CAL_VIDEO_MEETING_LINK_FOR_TESTING;

export const IS_SMS_CREDITS_ENABLED = !!process.env.NEXT_PUBLIC_STRIPE_CREDITS_PRICE_ID;
export const IS_SMS_CREDITS_ENABLED =
!!process.env.NEXT_PUBLIC_STRIPE_CREDITS_PRICE_ID || !!process.env.NEXT_PUBLIC_IS_E2E;
export const DATABASE_CHUNK_SIZE = parseInt(process.env.DATABASE_CHUNK_SIZE || "25", 10);

export const NEXTJS_CACHE_TTL = 3600; // 1 hour
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const buyCreditsHandler = async ({ ctx, input }: BuyCreditsOptions) => {
// if user id is part of a team, user can't buy credits for themselves
const memberships = await MembershipRepository.findAllAcceptedPublishedTeamMemberships(ctx.user.id);

if (!memberships || memberships.length > 0) {
if (memberships && memberships.length > 0) {
throw new TRPCError({
code: "UNAUTHORIZED",
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const getAllCreditsHandler = async ({ ctx, input }: GetAllCreditsOptions)
//if user is part of team, don't return any credits if teamId is not given
const memberships = await MembershipRepository.findAllAcceptedPublishedTeamMemberships(ctx.user.id);

if (!memberships || memberships.length > 0) {
if (memberships && memberships.length > 0) {
return null;
}
}
Expand Down
Loading