feature/settings-username-update (#2306)
* WIP feature/settings-username-update * WIP username change * WIP downgrade stripe * stripe downgrade and prorate preview * new UI for username premium component * Fix server side props * Remove migration, changed field to metadata user * WIP for update subscriptions * WIP intent username table * WIP saving and updating username via hooks * WIP saving working username sub update * WIP, update html to work with tests * Added stripe test for username update go to stripe * WIP username change test * Working test for username change * Fix timeout for flaky test * Review changes, remove logs * Move input username as a self contained component * Self review changes * Removing unnecesary arrow function * Removed intentUsername table and now using user metadata * Update website * Update turbo.json * Update e2e.yml * Update yarn.lock * Fixes for self host username update * Revert yarn lock from main branch * E2E fixes * Centralizes username check * Improvements * WIP separate logic between premium and save username button * WIP refactor username premium update * Saving WIP * WIP redo of username check * WIP obtain action normal, update or downgrade * Update username change components * Fix test for change-username self host or cal server * Fix user type for premiumTextfield * Using now a global unique const to know if is selfhosted, css fixes * Remove unused import * Using dynamic import for username textfield, prevent submit on enter Co-authored-by: Peer Richelsen <[email protected]> Co-authored-by: zomars <[email protected]> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
30 files changed
+1405
-336
No files matched your search
@@ -0,0 +1,148 @@
|
||||
import { expect } from "@playwright/test";
|
||||
import { UserPlan } from "@prisma/client";
|
||||
import dayjs from "dayjs";
|
||||
|
||||
import { WEBAPP_URL } from "@calcom/lib/constants";
|
||||
import stripe from "@calcom/stripe/server";
|
||||
import { getFreePlanPrice, getProPlanPrice } from "@calcom/stripe/utils";
|
||||
|
||||
import prisma from "@lib/prisma";
|
||||
|
||||
import { test } from "./lib/fixtures";
|
||||
|
||||
test.describe.configure({ mode: "parallel" });
|
||||
|
||||
const IS_STRIPE_ENABLED = !!(
|
||||
process.env.STRIPE_CLIENT_ID &&
|
||||
process.env.NEXT_PUBLIC_STRIPE_PUBLIC_KEY &&
|
||||
process.env.STRIPE_PRIVATE_KEY
|
||||
);
|
||||
|
||||
const IS_SELF_HOSTED = !(
|
||||
new URL(WEBAPP_URL).hostname.endsWith(".cal.dev") || !!new URL(WEBAPP_URL).hostname.endsWith(".cal.com")
|
||||
);
|
||||
|
||||
test.describe("Change username on settings", () => {
|
||||
test.afterEach(async ({ users }) => {
|
||||
await users.deleteAll();
|
||||
});
|
||||
|
||||
test("User can change username", async ({ page, users }) => {
|
||||
const user = await users.create({ plan: UserPlan.TRIAL });
|
||||
|
||||
await user.login();
|
||||
// Try to go homepage
|
||||
await page.goto("/settings/profile");
|
||||
// Change username from normal to normal
|
||||
const usernameInput = page.locator("[data-testid=username-input]");
|
||||
|
||||
await usernameInput.fill("demousernamex");
|
||||
|
||||
// Click on save button
|
||||
await page.click("[data-testid=update-username-btn-desktop]");
|
||||
|
||||
await page.click("[data-testid=save-username]");
|
||||
// eslint-disable-next-line playwright/no-wait-for-timeout
|
||||
await page.waitForTimeout(400);
|
||||
const newUpdatedUser = await prisma.user.findFirst({
|
||||
where: {
|
||||
id: user.id,
|
||||
},
|
||||
});
|
||||
expect(newUpdatedUser?.username).toBe("demousernamex");
|
||||
});
|
||||
|
||||
test("User trial can update to PREMIUM username", async ({ page, users }, testInfo) => {
|
||||
// eslint-disable-next-line playwright/no-skipped-test
|
||||
test.skip(!IS_STRIPE_ENABLED, "It should only run if Stripe is installed");
|
||||
test.skip(IS_SELF_HOSTED, "It shouldn't run on self hosted");
|
||||
|
||||
const user = await users.create({ plan: UserPlan.TRIAL });
|
||||
const customer = await stripe.customers.create({ email: `${user?.username}@example.com` });
|
||||
await stripe.subscriptionSchedules.create({
|
||||
customer: customer.id,
|
||||
start_date: "now",
|
||||
end_behavior: "release",
|
||||
phases: [
|
||||
{
|
||||
items: [{ price: getProPlanPrice() }],
|
||||
trial_end: dayjs().add(14, "day").unix(),
|
||||
end_date: dayjs().add(14, "day").unix(),
|
||||
},
|
||||
{
|
||||
items: [{ price: getFreePlanPrice() }],
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
await user.login();
|
||||
await page.goto("/settings/profile");
|
||||
|
||||
// Change username from normal to premium
|
||||
const usernameInput = page.locator("[data-testid=username-input]");
|
||||
|
||||
await usernameInput.fill(`xx${testInfo.workerIndex}`);
|
||||
|
||||
// Click on save button
|
||||
await page.click("[data-testid=update-username-btn-desktop]");
|
||||
|
||||
// Validate modal text fields
|
||||
const currentUsernameText = page.locator("[data-testid=current-username]").innerText();
|
||||
const newUsernameText = page.locator("[data-testid=new-username]").innerText();
|
||||
|
||||
expect(currentUsernameText).not.toBe(newUsernameText);
|
||||
|
||||
// Click on Go to billing
|
||||
await page.click("[data-testid=go-to-billing]", { timeout: 300 });
|
||||
|
||||
await page.waitForLoadState();
|
||||
|
||||
await expect(page).toHaveURL(/.*checkout.stripe.com/);
|
||||
});
|
||||
|
||||
test("User PRO can update to PREMIUM username", async ({ page, users }, testInfo) => {
|
||||
// eslint-disable-next-line playwright/no-skipped-test
|
||||
test.skip(!IS_STRIPE_ENABLED, "It should only run if Stripe is installed");
|
||||
test.skip(IS_SELF_HOSTED, "It shouldn't run on self hosted");
|
||||
const user = await users.create({ plan: UserPlan.PRO });
|
||||
const customer = await stripe.customers.create({ email: `${user?.username}@example.com` });
|
||||
const paymentMethod = await stripe.paymentMethods.create({
|
||||
type: "card",
|
||||
card: {
|
||||
number: "4242424242424242",
|
||||
cvc: "123",
|
||||
exp_month: 12,
|
||||
exp_year: 2040,
|
||||
},
|
||||
});
|
||||
await stripe.paymentMethods.attach(paymentMethod.id, { customer: customer.id });
|
||||
await stripe.subscriptions.create({
|
||||
customer: customer.id,
|
||||
items: [{ price: getProPlanPrice() }],
|
||||
});
|
||||
|
||||
await user.login();
|
||||
await page.goto("/settings/profile");
|
||||
|
||||
// Change username from normal to premium
|
||||
const usernameInput = page.locator("[data-testid=username-input]");
|
||||
|
||||
await usernameInput.fill(`xx${testInfo.workerIndex}`);
|
||||
|
||||
// Click on save button
|
||||
await page.click("[data-testid=update-username-btn-desktop]");
|
||||
|
||||
// Validate modal text fields
|
||||
const currentUsernameText = page.locator("[data-testid=current-username]").innerText();
|
||||
const newUsernameText = page.locator("[data-testid=new-username]").innerText();
|
||||
|
||||
expect(currentUsernameText).not.toBe(newUsernameText);
|
||||
|
||||
// Click on Go to billing
|
||||
await page.click("[data-testid=go-to-billing]", { timeout: 300 });
|
||||
|
||||
await page.waitForLoadState();
|
||||
|
||||
await expect(page).toHaveURL(/.*billing.stripe.com/);
|
||||
});
|
||||
});
|
||||
@@ -29,7 +29,7 @@ test.describe("Stripe integration", () => {
|
||||
).toContainText("Disconnect");
|
||||
|
||||
// Cleanup
|
||||
await user.delete();
|
||||
await users.deleteAll();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -67,7 +67,7 @@ test.describe("Stripe integration", () => {
|
||||
await expect(page.locator("[data-testid=success-page]")).toBeVisible();
|
||||
|
||||
// Cleanup
|
||||
await user.delete();
|
||||
await users.deleteAll();
|
||||
});
|
||||
|
||||
todo("Pending payment booking should not be confirmed by default");
|
||||
|
||||
Reference in new issue
Block a user