keycloak-scim/cypress/integration/users_test.spec.ts

216 lines
6.2 KiB
TypeScript
Raw Normal View History

2021-03-03 19:12:16 +00:00
import SidebarPage from "../support/pages/admin_console/SidebarPage";
import LoginPage from "../support/pages/LoginPage";
2021-03-04 14:26:21 +00:00
import CreateUserPage from "../support/pages/admin_console/manage/users/CreateUserPage";
import Masthead from "../support/pages/admin_console/Masthead";
import ListingPage from "../support/pages/admin_console/ListingPage";
import UserDetailsPage from "../support/pages/admin_console/manage/users/UserDetailsPage";
2021-10-25 14:38:54 +00:00
import AttributesTab from "../support/pages/admin_console/manage/AttributesTab";
import ModalUtils from "../support/util/ModalUtils";
import { keycloakBefore } from "../support/util/keycloak_before";
import GroupModal from "../support/pages/admin_console/manage/groups/GroupModal";
import UserGroupsPage from "../support/pages/admin_console/manage/users/UserGroupsPage";
import AdminClient from "../support/util/AdminClient";
let groupName = "group";
let groupsList: string[] = [];
describe("Group creation", () => {
const loginPage = new LoginPage();
const masthead = new Masthead();
const sidebarPage = new SidebarPage();
const groupModal = new GroupModal();
beforeEach(() => {
keycloakBefore();
loginPage.logIn();
sidebarPage.goToGroups();
});
2021-04-20 12:22:36 +00:00
function createNewGroup() {
groupName += "_" + (Math.random() + 1).toString(36).substring(7);
sidebarPage.waitForPageLoad();
groupModal.open().fillGroupForm(groupName).clickCreate();
groupsList = [...groupsList, groupName];
masthead.checkNotificationMessage("Group created");
sidebarPage.goToGroups();
2021-04-20 12:22:36 +00:00
}
2021-04-20 12:22:36 +00:00
it("Add groups to be joined", () => {
for (let i = 0; i <= 2; i++) {
createNewGroup();
}
});
});
2021-03-03 19:12:16 +00:00
describe("Users test", () => {
const loginPage = new LoginPage();
const sidebarPage = new SidebarPage();
2021-03-04 14:26:21 +00:00
const createUserPage = new CreateUserPage();
const userGroupsPage = new UserGroupsPage();
2021-03-04 14:26:21 +00:00
const masthead = new Masthead();
const modalUtils = new ModalUtils();
2021-03-04 14:26:21 +00:00
const listingPage = new ListingPage();
const userDetailsPage = new UserDetailsPage();
2021-10-25 14:38:54 +00:00
const attributesTab = new AttributesTab();
2021-03-04 14:26:21 +00:00
let itemId = "user_crud";
2021-03-03 19:12:16 +00:00
describe("User creation", () => {
beforeEach(() => {
keycloakBefore();
2021-03-03 19:12:16 +00:00
loginPage.logIn();
cy.intercept(
"/auth/admin/realms/master/components?type=org.keycloak.storage.UserStorageProvider"
).as("brute-force");
2021-03-03 19:12:16 +00:00
sidebarPage.goToUsers();
});
after(async () => {
await new AdminClient().deleteGroups();
});
it("Go to create User page", () => {
2021-03-04 14:26:21 +00:00
createUserPage.goToCreateUser();
2021-03-03 19:12:16 +00:00
cy.url().should("include", "users/add-user");
2021-03-04 14:26:21 +00:00
// Verify Cancel button works
createUserPage.cancel();
2021-03-03 19:12:16 +00:00
cy.url().should("not.include", "/add-user");
});
2021-03-04 14:26:21 +00:00
it("Create user test", () => {
2021-03-04 14:26:21 +00:00
itemId += "_" + (Math.random() + 1).toString(36).substring(7);
2021-03-04 14:26:21 +00:00
// Create
createUserPage.goToCreateUser();
2021-04-20 12:22:36 +00:00
createUserPage.createUser(itemId);
createUserPage.toggleAddGroupModal();
const groupsListCopy = groupsList.slice(0, 1);
groupsListCopy.forEach((element) => {
cy.findByTestId(`${element}-check`).click();
2021-04-20 12:22:36 +00:00
});
createUserPage.joinGroups();
createUserPage.save();
2021-03-04 14:26:21 +00:00
masthead.checkNotificationMessage("The user has been created");
sidebarPage.goToUsers();
});
it("User details test", () => {
cy.wait("@brute-force");
listingPage.searchItem(itemId).itemExist(itemId);
listingPage.goToItemDetails(itemId);
userDetailsPage.fillUserData().save();
masthead.checkNotificationMessage("The user has been saved");
sidebarPage.goToUsers();
cy.wait("@brute-force");
listingPage.searchItem(itemId).itemExist(itemId);
});
2021-10-25 14:38:54 +00:00
it("User attributes test", () => {
cy.wait("@brute-force");
2021-10-25 14:38:54 +00:00
listingPage.searchItem(itemId).itemExist(itemId);
listingPage.goToItemDetails(itemId);
attributesTab
.goToAttributesTab()
.fillLastRow("key", "value")
2021-10-25 14:38:54 +00:00
.saveAttribute();
masthead.checkNotificationMessage("The user has been saved");
});
it("User attributes with multiple values test", () => {
cy.wait("@brute-force");
listingPage.searchItem(itemId).itemExist(itemId);
listingPage.goToItemDetails(itemId);
cy.intercept("PUT", `/auth/admin/realms/master/users/*`).as("save-user");
const attributeKey = "key-multiple";
attributesTab
.goToAttributesTab()
.fillLastRow(attributeKey, "value")
.addRow()
.fillLastRow(attributeKey, "other value")
.saveAttribute();
cy.wait("@save-user").should(({ request, response }) => {
expect(response?.statusCode).to.equal(204);
expect(
request?.body.attributes[attributeKey],
"response body"
).deep.equal(["value", "other value"]);
});
masthead.checkNotificationMessage("The user has been saved");
});
it("Add user to groups test", () => {
cy.wait("@brute-force");
// Go to user groups
2021-03-04 14:26:21 +00:00
listingPage.searchItem(itemId).itemExist(itemId);
listingPage.goToItemDetails(itemId);
userGroupsPage.goToGroupsTab();
userGroupsPage.toggleAddGroupModal();
2021-04-20 12:22:36 +00:00
const groupsListCopy = groupsList.slice(1, 2);
groupsListCopy.forEach((element) => {
cy.findByTestId(`${element}-check`).click();
});
2021-04-20 12:22:36 +00:00
userGroupsPage.joinGroups();
});
it("Leave group test", () => {
cy.wait("@brute-force");
listingPage.searchItem(itemId).itemExist(itemId);
listingPage.goToItemDetails(itemId);
// Go to user groups
userGroupsPage.goToGroupsTab();
cy.findByTestId(`leave-${groupsList[0]}`).click();
cy.findByTestId("modalConfirm").click();
});
it("Go to user consents test", () => {
cy.wait("@brute-force");
listingPage.searchItem(itemId).itemExist(itemId);
listingPage.goToItemDetails(itemId);
cy.findByTestId("user-consents-tab").click();
cy.findByTestId("empty-state").contains("No consents");
});
it("Delete user test", () => {
// Delete
listingPage.deleteItem(itemId);
modalUtils.checkModalTitle("Delete user?").confirmModal();
masthead.checkNotificationMessage("The user has been deleted");
listingPage.itemExist(itemId, false);
2021-03-04 14:26:21 +00:00
});
2021-03-03 19:12:16 +00:00
});
});