move response in e2e test to common step definitions

This commit is contained in:
mahula 2023-02-02 21:03:14 +01:00
parent cb39f0b505
commit d89fc1ef10
2 changed files with 12 additions and 13 deletions

View File

@ -18,6 +18,18 @@ Given(
Then("the user is logged in with username {string}", (username: string) => {
const overviewPage = new OverviewPage();
cy.intercept("POST", "/graphql", (req) => {
if (
req.body.hasOwnProperty("query") &&
req.body.query.includes("mutation")
) {
req.alias = "login";
}
});
cy.wait("@login").then((interception) => {
expect(interception.response.statusCode).equals(200);
expect(JSON.stringify(interception.response.body)).contains(email);
});
cy.url().should("include", "/overview");
cy.get(overviewPage.navbarName).should("contain", username);
});

View File

@ -16,22 +16,9 @@ When("the user submits no credentials", () => {
When(
"the user submits the credentials {string} {string}",
(email: string, password: string) => {
cy.intercept("POST", "/graphql", (req) => {
if (
req.body.hasOwnProperty("query") &&
req.body.query.includes("mutation")
) {
req.alias = "login";
}
});
loginPage.enterEmail(email);
loginPage.enterPassword(password);
loginPage.submitLogin();
cy.wait("@login").then((interception) => {
expect(interception.response.statusCode).equals(200);
expect(JSON.stringify(interception.response.body)).contains(email);
});
}
);