Keycloak
46 строк · 1.3 Кб
1// tslint:disable:no-unused-expression
2import { faker } from "@faker-js/faker";3import * as chai from "chai";4import { KeycloakAdminClient } from "../src/client.js";5import { credentials } from "./constants.js";6
7const expect = chai.expect;8
9describe("Realms", () => {10let kcAdminClient: KeycloakAdminClient;11let currentRealmId: string;12
13before(async () => {14kcAdminClient = new KeycloakAdminClient();15await kcAdminClient.auth(credentials);16
17const realmId = faker.internet.userName();18const realm = await kcAdminClient.realms.create({19id: realmId,20realm: realmId,21});22expect(realm.realmName).to.be.ok;23currentRealmId = realmId;24});25
26after(async () => {27await kcAdminClient.realms.del({ realm: currentRealmId });28});29
30it("add a user to another realm", async () => {31const username = faker.internet.userName().toLowerCase();32const user = await kcAdminClient.users.create({33realm: currentRealmId,34username,35email: "test@keycloak.org",36// enabled required to be true in order to send actions email37emailVerified: true,38enabled: true,39});40const foundUser = (await kcAdminClient.users.findOne({41realm: currentRealmId,42id: user.id,43}))!;44expect(foundUser.username).to.be.eql(username);45});46});47