feat: optimize Cypress tests with API mocking
This commit is contained in:
@@ -2,54 +2,69 @@
|
||||
|
||||
describe("Correct Display of Total Fundraising Counter", () => {
|
||||
beforeEach(() => {
|
||||
cy.intercept("GET", "**/v4/project_rewards?project=100", {
|
||||
statusCode: 200,
|
||||
body: [
|
||||
{
|
||||
id: 3827,
|
||||
project: "/v4/projects/100",
|
||||
title: 'CD "Al Paso de los Caracoles" + 2 Camisetas',
|
||||
description: "CD físico del álbum junto con 2 camisetas oficiales",
|
||||
money: { amount: 4000, currency: "EUR" },
|
||||
hasUnits: true,
|
||||
unitsTotal: 5,
|
||||
unitsAvailable: 5,
|
||||
locales: ["es"],
|
||||
},
|
||||
],
|
||||
}).as("projectRewards");
|
||||
|
||||
cy.intercept("GET", "**/v4/projects/100", {
|
||||
statusCode: 200,
|
||||
body: {
|
||||
id: 100,
|
||||
title: "Proyecto de Prueba",
|
||||
amount: 12500,
|
||||
minimal: 5000,
|
||||
optimal: 25000,
|
||||
received: 12500,
|
||||
num_investors: 45,
|
||||
status: "active",
|
||||
currency: "EUR",
|
||||
},
|
||||
}).as("projectData");
|
||||
|
||||
cy.login();
|
||||
cy.url().should("not.include", "/login");
|
||||
});
|
||||
|
||||
const verifyCounterElement = (label: any, shouldContainEuro = false) => {
|
||||
cy.contains("p", label).should("be.visible").and("have.class", "text-[#575757]");
|
||||
|
||||
cy.contains("p", label)
|
||||
.siblings("p")
|
||||
.should(shouldContainEuro ? "be.visible" : "exist")
|
||||
.and("have.class", "text-secondary")
|
||||
.and("have.class", "text-[32px]")
|
||||
.and("have.class", "font-bold")
|
||||
.then(($el) => {
|
||||
if (shouldContainEuro) {
|
||||
expect($el.text()).to.contain("€");
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
it("should display fundraising counter with total raised and remaining amounts", () => {
|
||||
cy.visit("/es/projects/100");
|
||||
|
||||
cy.wait("@projectRewards", { timeout: 3000 });
|
||||
|
||||
cy.get(".flex.h-\\[100\\%\\].flex-col.gap-6.rounded-\\[32px\\]").should("be.visible");
|
||||
|
||||
cy.contains("p", "Obtenido").should("be.visible").and("have.class", "text-[#575757]");
|
||||
|
||||
cy.contains("p", "Obtenido")
|
||||
.siblings("p")
|
||||
.should("exist")
|
||||
.and("have.class", "text-secondary")
|
||||
.and("have.class", "text-[32px]")
|
||||
.and("have.class", "font-bold");
|
||||
|
||||
cy.contains("p", "Donaciones realizadas")
|
||||
.should("be.visible")
|
||||
.and("have.class", "text-[#575757]");
|
||||
|
||||
cy.contains("p", "Donaciones realizadas")
|
||||
.siblings("p")
|
||||
.should("exist")
|
||||
.and("have.class", "text-secondary")
|
||||
.and("have.class", "text-[32px]")
|
||||
.and("have.class", "font-bold");
|
||||
|
||||
cy.contains("p", "Óptimo").should("be.visible").and("have.class", "text-[#575757]");
|
||||
|
||||
cy.contains("p", "Óptimo")
|
||||
.siblings("p")
|
||||
.should("be.visible")
|
||||
.and("contain.text", "€")
|
||||
.and("have.class", "text-secondary")
|
||||
.and("have.class", "text-[32px]")
|
||||
.and("have.class", "font-bold");
|
||||
|
||||
cy.contains("p", "Mínimo").should("be.visible").and("have.class", "text-[#575757]");
|
||||
|
||||
cy.contains("p", "Mínimo")
|
||||
.siblings("p")
|
||||
.should("be.visible")
|
||||
.and("contain.text", "€")
|
||||
.and("have.class", "text-secondary")
|
||||
.and("have.class", "text-[32px]")
|
||||
.and("have.class", "font-bold");
|
||||
verifyCounterElement("Obtenido");
|
||||
verifyCounterElement("Donaciones realizadas");
|
||||
verifyCounterElement("Óptimo", true);
|
||||
verifyCounterElement("Mínimo", true);
|
||||
|
||||
cy.contains("button", "Donar a esta campaña")
|
||||
.should("be.visible")
|
||||
@@ -61,6 +76,8 @@ describe("Correct Display of Total Fundraising Counter", () => {
|
||||
it("should calculate and display remaining amount to reach funding goal", () => {
|
||||
cy.visit("/es/projects/100");
|
||||
|
||||
cy.wait("@projectRewards", { timeout: 3000 });
|
||||
|
||||
cy.contains("p", "Obtenido")
|
||||
.siblings("p")
|
||||
.invoke("text")
|
||||
|
||||
@@ -9,12 +9,8 @@ describe("Project Page - Donation and Reward Verification", () => {
|
||||
id: 3827,
|
||||
project: "/v4/projects/100",
|
||||
title: 'CD "Al Paso de los Caracoles" + 2 Camisetas',
|
||||
description:
|
||||
"CD físico del álbum junto con 2 camisetas oficiales del proyecto musical",
|
||||
money: {
|
||||
amount: 4000,
|
||||
currency: "EUR",
|
||||
},
|
||||
description: "CD físico del álbum junto con 2 camisetas oficiales",
|
||||
money: { amount: 4000, currency: "EUR" },
|
||||
hasUnits: true,
|
||||
unitsTotal: 5,
|
||||
unitsAvailable: 5,
|
||||
@@ -31,16 +27,13 @@ describe("Project Page - Donation and Reward Verification", () => {
|
||||
cy.visit("/es/projects/100");
|
||||
cy.wait("@project100Rewards");
|
||||
|
||||
cy.get("li.flex.flex-col.gap-2.rounded-4xl.border", { timeout: 10000 }).within(() => {
|
||||
cy.get("h3.text-tertiary.text-2xl.font-semibold").should("exist").and("be.visible");
|
||||
cy.get("li.flex.flex-col.gap-2.rounded-4xl.border").within(() => {
|
||||
cy.get("h3.text-tertiary.text-2xl.font-semibold").should("be.visible");
|
||||
|
||||
cy.get("p.mb-2.text-sm.whitespace-pre-line.text-gray-800")
|
||||
.should("exist")
|
||||
.and("be.visible");
|
||||
cy.get("p.mb-2.text-sm.whitespace-pre-line.text-gray-800").should("be.visible");
|
||||
|
||||
cy.get('button[type="button"]')
|
||||
.should("exist")
|
||||
.and("be.visible")
|
||||
.should("be.visible")
|
||||
.and("contain.text", "Dona")
|
||||
.and("contain.text", "40€");
|
||||
});
|
||||
|
||||
@@ -38,7 +38,7 @@ describe("PayPal Payment Flow", () => {
|
||||
|
||||
cy.contains("button", "Continuar").should("be.visible").should("be.enabled").click();
|
||||
|
||||
cy.url({ timeout: 10000 }).should("not.include", "/login");
|
||||
cy.url({ timeout: 3000 }).should("not.include", "/login");
|
||||
cy.url().should("include", "payment");
|
||||
|
||||
cy.get("form#payment", { timeout: 5000 }).should("exist");
|
||||
|
||||
@@ -2,6 +2,38 @@
|
||||
|
||||
describe("Project Donation Button", () => {
|
||||
beforeEach(() => {
|
||||
cy.intercept("GET", "**/v4/project_rewards?project=2", {
|
||||
statusCode: 200,
|
||||
body: [
|
||||
{
|
||||
id: 4001,
|
||||
project: "/v4/projects/2",
|
||||
title: "Recompensa del Proyecto 2",
|
||||
description: "Una recompensa de ejemplo para el proyecto 2",
|
||||
money: { amount: 2000, currency: "EUR" },
|
||||
hasUnits: true,
|
||||
unitsTotal: 10,
|
||||
unitsAvailable: 8,
|
||||
locales: ["es"],
|
||||
},
|
||||
],
|
||||
}).as("project2Rewards");
|
||||
|
||||
cy.intercept("GET", "**/v4/projects/2", {
|
||||
statusCode: 200,
|
||||
body: {
|
||||
id: 2,
|
||||
title: "Proyecto 2 de Prueba",
|
||||
amount: 8500,
|
||||
minimal: 3000,
|
||||
optimal: 15000,
|
||||
received: 8500,
|
||||
num_investors: 25,
|
||||
status: "active",
|
||||
currency: "EUR",
|
||||
},
|
||||
}).as("project2Data");
|
||||
|
||||
cy.login();
|
||||
cy.on("uncaught:exception", () => false);
|
||||
});
|
||||
@@ -9,6 +41,8 @@ describe("Project Donation Button", () => {
|
||||
it("should show the 'Donate to this campaign' button visible and clickable", () => {
|
||||
cy.visit("/es/projects/2");
|
||||
|
||||
cy.wait("@project2Rewards", { timeout: 3000 });
|
||||
|
||||
cy.contains("button", "Donar a esta campaña").should("be.visible").and("be.enabled");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -38,10 +38,10 @@ describe("Stripe Payment Flow", () => {
|
||||
|
||||
cy.contains("button", "Continuar").should("be.visible").should("be.enabled").click();
|
||||
|
||||
cy.url({ timeout: 10000 }).should("not.include", "/login");
|
||||
cy.url({ timeout: 3000 }).should("not.include", "/login");
|
||||
cy.url().should("include", "payment");
|
||||
|
||||
cy.get("form#payment", { timeout: 5000 }).should("exist");
|
||||
cy.get("form#payment", { timeout: 3000 }).should("exist");
|
||||
|
||||
cy.get("label[data-gateway='stripe']").should("be.visible").click();
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ describe("Checkout Flow - Multiple Contributions", () => {
|
||||
|
||||
cy.contains("button", "Continuar").should("be.visible").should("be.enabled").click();
|
||||
|
||||
cy.url({ timeout: 10000 }).should("not.include", "/login");
|
||||
cy.url({ timeout: 3000 }).should("not.include", "/login");
|
||||
cy.url().should("include", "payment");
|
||||
cy.get("form#payment").should("exist");
|
||||
});
|
||||
|
||||
@@ -2,6 +2,42 @@
|
||||
|
||||
describe("Stripe Verification Flow", () => {
|
||||
beforeEach(() => {
|
||||
cy.intercept("GET", "**/v4/payments/verify*", {
|
||||
statusCode: 200,
|
||||
body: {
|
||||
checkoutId: "100",
|
||||
status: "completed",
|
||||
payment_status: "paid",
|
||||
message: "El pago se ha procesado correctamente",
|
||||
transaction_id: "stripe_tx_12345",
|
||||
amount: 4000,
|
||||
currency: "EUR",
|
||||
},
|
||||
}).as("paymentVerify");
|
||||
|
||||
cy.intercept("GET", "**/v4/checkout/*/status", {
|
||||
statusCode: 200,
|
||||
body: {
|
||||
id: "100",
|
||||
status: "completed",
|
||||
payment_method: "stripe",
|
||||
verified: true,
|
||||
message: "pago se ha procesado",
|
||||
},
|
||||
}).as("checkoutStatus");
|
||||
|
||||
cy.intercept("GET", "**/v4/checkout/100", {
|
||||
statusCode: 200,
|
||||
body: {
|
||||
id: "100",
|
||||
status: "completed",
|
||||
amount: 4000,
|
||||
currency: "EUR",
|
||||
payment_method: "stripe",
|
||||
verified_at: new Date().toISOString(),
|
||||
},
|
||||
}).as("checkoutDetails");
|
||||
|
||||
cy.login();
|
||||
cy.url().should("not.include", "/login");
|
||||
});
|
||||
@@ -9,6 +45,6 @@ describe("Stripe Verification Flow", () => {
|
||||
it("should handle successful payment verification with checkoutId", () => {
|
||||
cy.visit("/payment/verify?checkoutId=100");
|
||||
|
||||
cy.contains(/pago se ha procesado/, { timeout: 10000 }).should("be.visible");
|
||||
cy.contains(/pago se ha procesado/, { timeout: 3000 }).should("be.visible");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -36,7 +36,7 @@ describe("Checkout Flow - Stripe Payment Integration", () => {
|
||||
|
||||
cy.contains("button", "Continuar").should("be.visible").click();
|
||||
|
||||
cy.url({ timeout: 10000 }).should("not.include", "/login");
|
||||
cy.url({ timeout: 3000 }).should("not.include", "/login");
|
||||
cy.url().should("include", "payment");
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
/// <reference types="cypress" />
|
||||
|
||||
describe("View Total Raised by One-time Payments", () => {
|
||||
beforeEach(() => {
|
||||
cy.intercept("GET", "**/v4/gateway_charges*", {
|
||||
statusCode: 200,
|
||||
headers: {
|
||||
"content-type": "application/ld+json",
|
||||
},
|
||||
body: {
|
||||
"@context": "/v4/contexts/GatewayCharge",
|
||||
"@id": "/v4/gateway_charges",
|
||||
"@type": "hydra:Collection",
|
||||
"hydra:member": [
|
||||
{
|
||||
"@id": "/v4/gateway_charges/1",
|
||||
"@type": "GatewayCharge",
|
||||
id: 1,
|
||||
amount: 2500,
|
||||
currency: "EUR",
|
||||
status: "completed",
|
||||
gateway: "stripe",
|
||||
created_at: "2025-01-15T10:00:00Z",
|
||||
},
|
||||
{
|
||||
"@id": "/v4/gateway_charges/2",
|
||||
"@type": "GatewayCharge",
|
||||
id: 2,
|
||||
amount: 1500,
|
||||
currency: "EUR",
|
||||
status: "completed",
|
||||
gateway: "paypal",
|
||||
created_at: "2025-01-14T15:30:00Z",
|
||||
},
|
||||
],
|
||||
"hydra:totalItems": 247,
|
||||
"hydra:view": {
|
||||
"@id": "/v4/gateway_charges?page=1&itemsPerPage=10&pagination=true",
|
||||
"@type": "hydra:PartialCollectionView",
|
||||
"hydra:first": "/v4/gateway_charges?page=1&itemsPerPage=10&pagination=true",
|
||||
"hydra:last": "/v4/gateway_charges?page=25&itemsPerPage=10&pagination=true",
|
||||
"hydra:next": "/v4/gateway_charges?page=2&itemsPerPage=10&pagination=true",
|
||||
},
|
||||
"hydra:search": {
|
||||
"@type": "hydra:IriTemplate",
|
||||
},
|
||||
total_amount: "148,750",
|
||||
total_count: 247,
|
||||
currency: "EUR",
|
||||
},
|
||||
}).as("gatewayCharges");
|
||||
|
||||
cy.login();
|
||||
cy.url().should("not.include", "/login");
|
||||
});
|
||||
|
||||
it("should display total contributions amount", () => {
|
||||
cy.visit("/es/admin/aportes");
|
||||
|
||||
cy.wait("@gatewayCharges", { timeout: 3000 });
|
||||
|
||||
cy.contains("Total aportes:")
|
||||
.should("be.visible")
|
||||
.and("have.class", "text-base")
|
||||
.and("have.class", "font-semibold")
|
||||
.and("have.class", "text-[#575757]");
|
||||
|
||||
cy.get(".text-secondary")
|
||||
.should("be.visible")
|
||||
.and("contain.text", "€")
|
||||
.and("have.class", "text-[40px]");
|
||||
});
|
||||
});
|
||||
@@ -1,23 +0,0 @@
|
||||
/// <reference types="cypress" />
|
||||
|
||||
describe("View Total Raised by One-time Payments", () => {
|
||||
beforeEach(() => {
|
||||
cy.login();
|
||||
cy.url().should("not.include", "/login");
|
||||
});
|
||||
|
||||
it("should display total contributions amount", () => {
|
||||
cy.visit("/es/admin/aportes");
|
||||
|
||||
cy.contains("Total aportes:")
|
||||
.should("be.visible")
|
||||
.and("have.class", "text-base")
|
||||
.and("have.class", "font-semibold")
|
||||
.and("have.class", "text-[#575757]");
|
||||
|
||||
cy.get(".text-secondary")
|
||||
.should("be.visible")
|
||||
.and("contain.text", "€")
|
||||
.and("have.class", "text-[40px]");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user