Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: logoutByApi tests #1593

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions cypress/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ declare namespace Cypress {
*/
loginByApi(username: string, password?: string): Chainable<Response>;

/**
* Logs-out user by using API request
*/
logoutByApi(): Chainable<Response>;

/**
* Logs-in user by using Google API request
*/
Expand Down
7 changes: 7 additions & 0 deletions cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,13 @@ Cypress.Commands.add("loginByApi", (username, password = Cypress.env("defaultPas
});
});

Cypress.Commands.add("logoutByApi", () => {
return cy.request("POST", `${Cypress.env("apiUrl")}/logout`).then((response) => {
expect(response.status).to.eq(200);
expect(response.body).to.have.property("message", "User logged out successfully");
});
});

Cypress.Commands.add("reactComponent", { prevSubject: "element" }, ($el) => {
if ($el.length !== 1) {
throw new Error(`cy.component() requires element of length 1 but got ${$el.length}`);
Expand Down
14 changes: 14 additions & 0 deletions cypress/tests/api/api-users.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,4 +202,18 @@ describe("Users API", function () {
});
});
});

context("POST /logout", function () {
it("logs out the authenticated user", function () {
// First, log in the user
cy.loginByApi(ctx.authenticatedUser!.username).then(() => {
// Then, log out the user using the custom command
cy.logoutByApi().then((response) => {
// Keep the assertions for status code and message
expect(response.status).to.eq(200);
expect(response.body).to.have.property("message", "User logged out successfully");
});
});
});
});
});