fix: Update Event Type Pricing For Multiple Installed Payment Apps (#12272)

* Prevent two payment apps from being enabled

* Find the enabled payment app to update the event type

* Add string

* Add tests

* Type fix

* Abstract check for multiple payment app logic

* Type check

* Address feedback

* chore: Enable One Payment App Per Event Type (#12414)

Co-authored-by: Morgan <33722304+ThyMinimalDev@users.noreply.github.com>
Co-authored-by: Morgan Vernay <morgan@cal.com>

* Fix bug

* Fix test

* Clean up

* Fix test

* Fix test

---------

Co-authored-by: Morgan <33722304+ThyMinimalDev@users.noreply.github.com>
Co-authored-by: Peer Richelsen <peeroke@gmail.com>
Co-authored-by: Alex van Andel <me@alexvanandel.com>
Co-authored-by: Omar López <zomars@me.com>
Co-authored-by: Morgan Vernay <morgan@cal.com>
Co-authored-by: Keith Williams <keithwillcode@gmail.com>
This commit is contained in:
Joe Au-Yeung
2023-12-20 13:29:23 -05:00
committed by GitHub
co-authored by Morgan Morgan Vernay Peer Richelsen Alex van Andel Omar López Keith Williams
parent 68d40cabbe
commit d07e86e4f3
15 changed files with 273 additions and 53 deletions
+4 -4
View File
@@ -508,8 +508,8 @@ const createUserFixture = (user: UserWithIncludes, page: Page) => {
});
},
getPaymentCredential: async () => getPaymentCredential(store.page),
setupEventWithPrice: async (eventType: Pick<Prisma.EventType, "id">) =>
setupEventWithPrice(eventType, store.page),
setupEventWithPrice: async (eventType: Pick<Prisma.EventType, "id">, slug: string) =>
setupEventWithPrice(eventType, slug, store.page),
bookAndPayEvent: async (eventType: Pick<Prisma.EventType, "slug">) =>
bookAndPayEvent(user, eventType, store.page),
makePaymentUsingStripe: async () => makePaymentUsingStripe(store.page),
@@ -693,9 +693,9 @@ export async function apiLogin(
});
}
export async function setupEventWithPrice(eventType: Pick<Prisma.EventType, "id">, page: Page) {
export async function setupEventWithPrice(eventType: Pick<Prisma.EventType, "id">, slug: string, page: Page) {
await page.goto(`/event-types/${eventType?.id}?tabName=apps`);
await page.locator("[data-testid='app-switch']").first().click();
await page.locator(`[data-testid='${slug}-app-switch']`).first().click();
await page.getByPlaceholder("Price").fill("100");
await page.getByTestId("update-eventtype").click();
}
@@ -46,7 +46,7 @@ test.describe("Stripe integration", () => {
await user.getPaymentCredential();
const eventType = user.eventTypes.find((e) => e.slug === "paid") as Prisma.EventType;
await user.setupEventWithPrice(eventType);
await user.setupEventWithPrice(eventType, "stripe");
// Need to wait for the DB to be updated with the metadata
await page.waitForResponse((res) => res.url().includes("update") && res.status() === 200);
@@ -104,7 +104,7 @@ test.describe("Stripe integration", () => {
page.click('[id="skip-account-app"]'),
]);
await owner.setupEventWithPrice(teamEvent);
await owner.setupEventWithPrice(teamEvent, "stripe");
// Need to wait for the DB to be updated with the metadata
await page.waitForResponse((res) => res.url().includes("update") && res.status() === 200);
@@ -134,7 +134,7 @@ test.describe("Stripe integration", () => {
await page.goto("/apps/installed");
await user.getPaymentCredential();
await user.setupEventWithPrice(eventType);
await user.setupEventWithPrice(eventType, "stripe");
await user.bookAndPayEvent(eventType);
// success
await expect(page.locator("[data-testid=success-page]")).toBeVisible();
@@ -147,7 +147,7 @@ test.describe("Stripe integration", () => {
await page.goto("/apps/installed");
await user.getPaymentCredential();
await user.setupEventWithPrice(eventType);
await user.setupEventWithPrice(eventType, "stripe");
// booking process without payment
await page.goto(`${user.username}/${eventType?.slug}`);
@@ -171,7 +171,7 @@ test.describe("Stripe integration", () => {
await page.goto("/apps/installed");
await user.getPaymentCredential();
await user.setupEventWithPrice(eventType);
await user.setupEventWithPrice(eventType, "stripe");
await user.bookAndPayEvent(eventType);
// Rescheduling the event
@@ -194,7 +194,7 @@ test.describe("Stripe integration", () => {
await page.goto("/apps/installed");
await user.getPaymentCredential();
await user.setupEventWithPrice(eventType);
await user.setupEventWithPrice(eventType, "stripe");
await user.bookAndPayEvent(eventType);
await page.click('[data-testid="cancel"]');
@@ -214,7 +214,7 @@ test.describe("Stripe integration", () => {
await page.goto("/apps/installed");
await user.getPaymentCredential();
await user.setupEventWithPrice(eventType);
await user.setupEventWithPrice(eventType, "stripe");
await user.bookAndPayEvent(eventType);
await user.confirmPendingPayment();
});
@@ -264,7 +264,7 @@ test.describe("Stripe integration", () => {
await page.locator("#event-type-form").getByRole("switch").click();
// Set price
await page.getByTestId("price-input-stripe").fill("200");
await page.getByTestId("stripe-price-input").fill("200");
// Select currency in dropdown
await page.getByTestId("stripe-currency-select").click();
+126 -2
View File
@@ -80,8 +80,8 @@ test.describe("Payment app", () => {
await page.getByTestId("stripe-currency-select").click();
await page.getByTestId("select-option-usd").click();
await page.getByTestId("price-input-stripe").click();
await page.getByTestId("price-input-stripe").fill("350");
await page.getByTestId("stripe-price-input").click();
await page.getByTestId("stripe-price-input").fill("350");
await page.getByTestId("update-eventtype").click();
await page.goto(`${user.username}/${paymentEvent.slug}`);
@@ -234,4 +234,128 @@ test.describe("Payment app", () => {
await page.getByLabel("Tracking ID").fill("demo");
await page.getByTestId("update-eventtype").click();
});
test("Should only be allowed to enable one payment app", async ({ page, users }) => {
const user = await users.create();
await user.apiLogin();
const paymentEvent = user.eventTypes.find((item) => item.slug === "paid");
if (!paymentEvent) {
throw new Error("No payment event found");
}
await prisma.credential.createMany({
data: [
{
type: "paypal_payment",
userId: user.id,
key: {
client_id: "randomString",
secret_key: "randomString",
webhook_id: "randomString",
},
},
{
type: "stripe_payment",
userId: user.id,
key: {
scope: "read_write",
livemode: false,
token_type: "bearer",
access_token: "sk_test_randomString",
refresh_token: "rt_randomString",
stripe_user_id: "acct_randomString",
default_currency: "usd",
stripe_publishable_key: "pk_test_randomString",
},
},
],
});
await page.goto(`event-types/${paymentEvent.id}?tabName=apps`);
await page.locator("[data-testid='paypal-app-switch']").click();
await page.locator("[data-testid='stripe-app-switch']").isDisabled();
});
test("when more than one payment app is installed the price should be updated when changing settings", async ({
page,
users,
}) => {
const user = await users.create();
await user.apiLogin();
const paymentEvent = user.eventTypes.find((item) => item.slug === "paid");
if (!paymentEvent) {
throw new Error("No payment event found");
}
await prisma.credential.createMany({
data: [
{
type: "paypal_payment",
userId: user.id,
key: {
client_id: "randomString",
secret_key: "randomString",
webhook_id: "randomString",
},
},
{
type: "stripe_payment",
userId: user.id,
key: {
scope: "read_write",
livemode: false,
token_type: "bearer",
access_token: "sk_test_randomString",
refresh_token: "rt_randomString",
stripe_user_id: "acct_randomString",
default_currency: "usd",
stripe_publishable_key: "pk_test_randomString",
},
},
],
});
await page.goto(`event-types/${paymentEvent.id}?tabName=apps`);
await page.locator("[data-testid='paypal-app-switch']").click();
await page.locator("[data-testid='paypal-price-input']").fill("100");
await page.locator("[data-testid='paypal-currency-select']").first().click();
await page.locator("#react-select-2-option-13").click();
// await page.locator(".mb-1 > .bg-default > div > div:nth-child(2)").first().click();
// await page.getByText("$MXNCurrencyMexican pesoPayment option").click();
await page.locator("[data-testid='update-eventtype']").click();
// Need to wait for the DB to be updated
await page.waitForResponse((res) => res.url().includes("update") && res.status() === 200);
const paypalPrice = await prisma.eventType.findFirst({
where: {
id: paymentEvent.id,
},
select: {
price: true,
},
});
expect(paypalPrice?.price).toEqual(10000);
await page.locator("[data-testid='paypal-app-switch']").click();
await page.locator("[data-testid='stripe-app-switch']").click();
await page.locator("[data-testid='stripe-price-input']").fill("200");
await page.locator("[data-testid='update-eventtype']").click();
// Need to wait for the DB to be updated
await page.waitForResponse((res) => res.url().includes("update") && res.status() === 200);
const stripePrice = await prisma.eventType.findFirst({
where: {
id: paymentEvent.id,
},
select: {
price: true,
},
});
expect(stripePrice?.price).toEqual(20000);
});
});