Skip to content

Commit

Permalink
removed reset password and change password tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wojteknowacki committed Nov 20, 2023
1 parent d1b9387 commit 10cac48
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 184 deletions.
12 changes: 10 additions & 2 deletions playwright/pages/loginPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class LoginPage {
page: Page,
path: string,
) {
await page.goto(process.env.BASE_URL!);
await this.goto();
await this.typeEmail(userEmail);
await this.typePassword(userPassword);
await this.clickSignInButton();
Expand All @@ -46,7 +46,7 @@ export class LoginPage {
await page.context().storageState({ path });
}
async basicUiLogin(userEmail: string, userPassword: string) {
await this.page.goto(process.env.BASE_URL!);
await this.goto();
await this.typeEmail(userEmail);
await this.typePassword(userPassword);
await this.clickSignInButton();
Expand All @@ -61,4 +61,12 @@ export class LoginPage {
async clickSignInButton() {
await this.signInButton.click();
}
async goto() {
const BASE_URL = process.env.BASE_URL!;
const loginPageUrl =
BASE_URL === "http://localhost:9000/"
? "http://localhost:9000/"
: "/dashboard";
await this.page.goto(loginPageUrl);
}
}
269 changes: 87 additions & 182 deletions playwright/tests/staffMembers.spec.ts
Original file line number Diff line number Diff line change
@@ -1,194 +1,99 @@
import { BasicApiService } from "@api/basics";
import { USERS } from "@data/e2eTestData";
import { URL_LIST } from "@data/url";
import { AccountSettingsPage } from "@pages/accountSettingsPage";
import { ConfigurationPage } from "@pages/configurationPage";
import { HomePage } from "@pages/homePage";
import { LoginPage } from "@pages/loginPage";
import { MainMenuPage } from "@pages/mainMenuPage";
import { SetUpNewPasswordPage } from "@pages/setUpNewPasswordPage";
import { StaffMembersPage } from "@pages/staffMembersPage";
import { expect, test } from "@playwright/test";

test.describe("Authenticated admin users", () => {
test.use({ storageState: "playwright/.auth/admin.json" });

test("TC: SALEOR_36 User should be able to invite staff member with full access permissions @basic-regression @staff-members", async ({
page,
request,
}) => {
const configurationPage = new ConfigurationPage(page);
const staffMembersPage = new StaffMembersPage(page, request);
const userEmail = `francesca${await staffMembersPage.basePage.getRandomInt(
1000000,
)}@gmail.com`;

await page.goto(URL_LIST.configuration);
await configurationPage.openStaffMembers();

await staffMembersPage.clickInviteStaffMemberButton();
await staffMembersPage.inviteStaffMembersDialog.typeNameLastNameAndEmail(
"Francesca",
"Leek",
userEmail,
);
await staffMembersPage.inviteStaffMembersDialog.clickSendInviteButton();

await staffMembersPage.clickPermissionsGroupSelectButton();
await staffMembersPage.assignUserToPermissionGroup("Full Access");
await staffMembersPage.clickSaveButton();
await staffMembersPage.basePage.expectSuccessBanner();
expect(await staffMembersPage.assignedPermissionGroups.count()).toEqual(1);
expect(staffMembersPage.assignedPermissionGroups).toContainText(
"Full Access",
);

const singleUserEmails =
await staffMembersPage.mailpitService.getEmailsForUser(userEmail);

await expect(singleUserEmails[0].Subject).toContain(
"Set Your Dashboard Password",
);
});

test("TC: SALEOR_37 Admin User should be able to deactivate other user @basic-regression @staff-members", async ({
page,
request,
}) => {
const staffMembersPage = new StaffMembersPage(page, request);
const basicApiService = new BasicApiService(request);

await page.goto(URL_LIST.staffMembers + USERS.userToBeDeactivated.id);
await staffMembersPage.clickIsActiveCheckbox();
await staffMembersPage.clickSaveButton();
await staffMembersPage.basePage.expectSuccessBanner();
await expect(await staffMembersPage.isActiveCheckbox.isChecked()).toEqual(
false,
);

const loginViaApiDeactivatedUserResponse =
await basicApiService.logInUserViaApi({
email: USERS.userToBeDeactivated.email,
password: process.env.E2E_PERMISSIONS_USERS_PASSWORD!,
});
await expect(
loginViaApiDeactivatedUserResponse.data.tokenCreate.errors[0].code,
).toEqual("INACTIVE");
});

test("TC: SALEOR_38 Admin User should be able to activate other user @basic-regression @staff-members", async ({
page,
request,
}) => {
const staffMembersPage = new StaffMembersPage(page, request);
const basicApiService = new BasicApiService(request);

await page.goto(URL_LIST.staffMembers + USERS.userToBeActivated.id);
await staffMembersPage.clickIsActiveCheckbox();
await staffMembersPage.clickSaveButton();
await staffMembersPage.basePage.expectSuccessBanner();
await expect(await staffMembersPage.isActiveCheckbox.isChecked()).toEqual(
true,
);

const loginViaApiDeactivatedUserResponse =
await basicApiService.logInUserViaApi({
email: USERS.userToBeActivated.email,
password: process.env.E2E_PERMISSIONS_USERS_PASSWORD!,
});
await expect(
loginViaApiDeactivatedUserResponse.data.tokenCreate.errors,
).toEqual([]);
await expect(
loginViaApiDeactivatedUserResponse.data.tokenCreate.token,
).not.toEqual(null);
});
test.use({ storageState: "playwright/.auth/admin.json" });

test("TC: SALEOR_36 User should be able to invite staff member with full access permissions @basic-regression @staff-members", async ({
page,
request,
}) => {
const configurationPage = new ConfigurationPage(page);
const staffMembersPage = new StaffMembersPage(page, request);
const userEmail = `francesca${await staffMembersPage.basePage.getRandomInt(
1000000,
)}@gmail.com`;

await page.goto(URL_LIST.configuration);
await configurationPage.openStaffMembers();

await staffMembersPage.clickInviteStaffMemberButton();
await staffMembersPage.inviteStaffMembersDialog.typeNameLastNameAndEmail(
"Francesca",
"Leek",
userEmail,
);
await staffMembersPage.inviteStaffMembersDialog.clickSendInviteButton();

await staffMembersPage.clickPermissionsGroupSelectButton();
await staffMembersPage.assignUserToPermissionGroup("Full Access");
await staffMembersPage.clickSaveButton();
await staffMembersPage.basePage.expectSuccessBanner();
expect(await staffMembersPage.assignedPermissionGroups.count()).toEqual(1);
expect(staffMembersPage.assignedPermissionGroups).toContainText(
"Full Access",
);

const singleUserEmails =
await staffMembersPage.mailpitService.getEmailsForUser(userEmail);

await expect(singleUserEmails[0].Subject).toContain(
"Set Your Dashboard Password",
);
});

test.describe("Unauthenticated admin users", () => {
test.use({ storageState: "playwright/.auth/unauthenticated-user.json" });

test("TC: SALEOR_39 User should be able to reset password @daily @staff-members", async ({
page,
request,
}) => {
const loginPage = new LoginPage(page);
const homePage = new HomePage(page);
const setUpNewPasswordPage = new SetUpNewPasswordPage(page, request);
const basicApiService = new BasicApiService(request);

await page.goto("/");
await loginPage.clickResetPasswordLink();
await loginPage.typeEmail(USERS.userForPasswordReset.email);
await loginPage.clickSendEmailWithResetLinkButton();
await loginPage.clickBackToLoginPageButton();
await loginPage.emailInput.waitFor({ state: "visible" });
await setUpNewPasswordPage.gotoUserResetPasswordPage(
USERS.userForPasswordReset.email,
);
await setUpNewPasswordPage.typePassword(
USERS.userForPasswordReset.newPassword,
);
await setUpNewPasswordPage.typeConfirmedPassword(
USERS.userForPasswordReset.newPassword,
);
await setUpNewPasswordPage.clickSetNewPasswordButton();
await expect(homePage.welcomeMessage).toBeVisible({ timeout: 10000 });
await expect(homePage.welcomeMessage).toContainText(
`${USERS.userForPasswordReset.name} ${USERS.userForPasswordReset.lastName}`,
);

const userWithNewPasswordLoginResponse =
await basicApiService.logInUserViaApi({
email: USERS.userForPasswordReset.email,
password: USERS.userForPasswordReset.newPassword,
});
await expect(
userWithNewPasswordLoginResponse.data.tokenCreate.errors,
).toEqual([]);
await expect(
userWithNewPasswordLoginResponse.data.tokenCreate.token,
).not.toEqual(null);
});
test("TC: SALEOR_37 Admin User should be able to deactivate other user @basic-regression @staff-members", async ({
page,
request,
}) => {
const staffMembersPage = new StaffMembersPage(page, request);
const basicApiService = new BasicApiService(request);

await page.goto(URL_LIST.staffMembers + USERS.userToBeDeactivated.id);
await staffMembersPage.clickIsActiveCheckbox();
await staffMembersPage.clickSaveButton();
await staffMembersPage.basePage.expectSuccessBanner();
await expect(await staffMembersPage.isActiveCheckbox.isChecked()).toEqual(
false,
);

const loginViaApiDeactivatedUserResponse =
await basicApiService.logInUserViaApi({
email: USERS.userToBeDeactivated.email,
password: process.env.E2E_PERMISSIONS_USERS_PASSWORD!,
});
await expect(
loginViaApiDeactivatedUserResponse.data.tokenCreate.errors[0].code,
).toEqual("INACTIVE");
});

test.describe("Admin which log in via UI", () => {
// Reset storage state for this file to avoid being authenticated
test.use({ storageState: { cookies: [], origins: [] } });

test("TC: SALEOR_40 User should be able to change password @daily @staff-members", async ({
page,
request,
}) => {
const loginPage = new LoginPage(page);
const mainMenuPage = new MainMenuPage(page);
const accountSettingsPage = new AccountSettingsPage(page);
const basicApiService = new BasicApiService(request);

await loginPage.basicUiLogin(
USERS.userForPasswordChange.email,
process.env.E2E_PERMISSIONS_USERS_PASSWORD!,
);
await mainMenuPage.gotoAccountSettings();
await accountSettingsPage.clickChangePasswordButton();
await accountSettingsPage.typeOldAndNewPasswords(
process.env.E2E_PERMISSIONS_USERS_PASSWORD!,
USERS.userForPasswordChange.newPassword,
);
await accountSettingsPage.clickSaveChangedPasswordButton();
await accountSettingsPage.clickSaveButton();
await accountSettingsPage.basePage.expectSuccessBanner();

const userWithNewPasswordLoginResponse =
await basicApiService.logInUserViaApi({
email: USERS.userForPasswordChange.email,
password: USERS.userForPasswordChange.newPassword,
});
await expect(
userWithNewPasswordLoginResponse.data.tokenCreate.errors,
).toEqual([]);
await expect(
userWithNewPasswordLoginResponse.data.tokenCreate.token,
).not.toEqual(null);
});
test("TC: SALEOR_38 Admin User should be able to activate other user @basic-regression @staff-members", async ({
page,
request,
}) => {
const staffMembersPage = new StaffMembersPage(page, request);
const basicApiService = new BasicApiService(request);

await page.goto(URL_LIST.staffMembers + USERS.userToBeActivated.id);
await staffMembersPage.clickIsActiveCheckbox();
await staffMembersPage.clickSaveButton();
await staffMembersPage.basePage.expectSuccessBanner();
await expect(await staffMembersPage.isActiveCheckbox.isChecked()).toEqual(
true,
);

const loginViaApiDeactivatedUserResponse =
await basicApiService.logInUserViaApi({
email: USERS.userToBeActivated.email,
password: process.env.E2E_PERMISSIONS_USERS_PASSWORD!,
});
await expect(
loginViaApiDeactivatedUserResponse.data.tokenCreate.errors,
).toEqual([]);
await expect(
loginViaApiDeactivatedUserResponse.data.tokenCreate.token,
).not.toEqual(null);
});

0 comments on commit 10cac48

Please sign in to comment.