Skip to content

Commit

Permalink
Added Cypress test to check the ACDL place-order event
Browse files Browse the repository at this point in the history
  • Loading branch information
Miquel Angel Coca Piza authored and Miquel Angel Coca Piza committed Dec 12, 2024
1 parent 501aa54 commit 37a01bb
Showing 1 changed file with 70 additions and 0 deletions.
70 changes: 70 additions & 0 deletions cypress/src/tests/e2eTests/events/place-order.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import {
placeOrder,
setGuestEmail,
setGuestShippingAddress,
} from "../../../actions";
import { expectsEventWithContext } from "../../../assertions";
import { customerShippingAddress, products } from "../../../fixtures";

/**
* https://github.com/adobe/commerce-events/blob/main/examples/events/place-order.md
*
* Required Contexts:
* - page -> https://github.com/adobe/commerce-events/blob/main/packages/storefront-events-sdk/src/types/schemas/page.ts,
* - storefront -> https://github.com/adobe/commerce-events/blob/main/packages/storefront-events-sdk/src/types/schemas/storefrontInstance.ts,
* - shoppingCart -> https://github.com/adobe/commerce-events/blob/main/packages/storefront-events-sdk/src/types/schemas/shoppingCart.ts,
* - order -> https://github.com/adobe/commerce-events/blob/main/packages/storefront-events-sdk/src/types/schemas/order.ts
*/

it("is sent on place order button click", () => {
// add item to cart
cy.visit(products.configurable.urlPathWithOptions);
// add to cart
cy.get(".product-details__buttons__add-to-cart button")
.should("be.visible")
.click();
// click the minicart toggle
cy.get('button[data-count="1"]').should("be.visible").click();
// click the checkout button
cy.get('#nav div.cart-mini-cart a[href="/checkout"]')
.should("be.visible")
.click();

// fill in the login form
const apiMethod = "setGuestEmailOnCart";
const urlTest = Cypress.env("graphqlEndPoint");
cy.intercept("POST", urlTest, (req) => {
let data = req.body.query;
if (data && typeof data == "string") {
if (data.includes(apiMethod)) {
req.alias = "setEmailOnCart";
}
}
});
setGuestEmail(customerShippingAddress.email);
cy.wait("@setEmailOnCart");
// fill in the shipping address form
setGuestShippingAddress(customerShippingAddress, true);
cy.wait(2000);
// click the place order button
placeOrder();
// wait until the URL includes '/order-details'
cy.url().should("include", "/order-details");

cy.waitForResource("commerce-events-collector.js").then(() => {
cy.window()
.its("adobeDataLayer")
.then((adobeDataLayer) => {
expectsEventWithContext(
"place-order",
[
"pageContext",
"storefrontInstanceContext",
"shoppingCartContext",
"orderContext",
],
adobeDataLayer
);
});
});
});

0 comments on commit 37a01bb

Please sign in to comment.