2023-02-03 10:45:11 +00:00
|
|
|
// tslint:disable:no-unused-expression
|
|
|
|
import { faker } from "@faker-js/faker";
|
|
|
|
import * as chai from "chai";
|
|
|
|
import { KeycloakAdminClient } from "../src/client.js";
|
|
|
|
import { credentials } from "./constants.js";
|
|
|
|
|
|
|
|
const expect = chai.expect;
|
|
|
|
|
|
|
|
describe("Realms", () => {
|
|
|
|
let kcAdminClient: KeycloakAdminClient;
|
|
|
|
let currentRealmId: string;
|
|
|
|
|
|
|
|
before(async () => {
|
|
|
|
kcAdminClient = new KeycloakAdminClient();
|
|
|
|
await kcAdminClient.auth(credentials);
|
|
|
|
|
2024-10-30 11:14:02 +00:00
|
|
|
const realmId = faker.internet.username();
|
2023-02-03 10:45:11 +00:00
|
|
|
const realm = await kcAdminClient.realms.create({
|
|
|
|
id: realmId,
|
|
|
|
realm: realmId,
|
|
|
|
});
|
|
|
|
expect(realm.realmName).to.be.ok;
|
|
|
|
currentRealmId = realmId;
|
|
|
|
});
|
|
|
|
|
|
|
|
after(async () => {
|
|
|
|
await kcAdminClient.realms.del({ realm: currentRealmId });
|
|
|
|
});
|
|
|
|
|
|
|
|
it("add a user to another realm", async () => {
|
2024-10-30 11:14:02 +00:00
|
|
|
const username = faker.internet.username().toLowerCase();
|
2023-02-03 10:45:11 +00:00
|
|
|
const user = await kcAdminClient.users.create({
|
|
|
|
realm: currentRealmId,
|
|
|
|
username,
|
|
|
|
email: "test@keycloak.org",
|
|
|
|
// enabled required to be true in order to send actions email
|
|
|
|
emailVerified: true,
|
|
|
|
enabled: true,
|
|
|
|
});
|
|
|
|
const foundUser = (await kcAdminClient.users.findOne({
|
|
|
|
realm: currentRealmId,
|
|
|
|
id: user.id,
|
|
|
|
}))!;
|
|
|
|
expect(foundUser.username).to.be.eql(username);
|
|
|
|
});
|
|
|
|
});
|