keycloak-scim/js/libs/keycloak-admin-client/test/crossRealm.spec.ts
Jon Koops 8cb202eb29
Add JavaScript admin client to repository (#16697)
* Add JavaScript admin client to repository

* Apply review feedback

Co-authored-by: Stian Thorgersen <stian@redhat.com>

---------

Co-authored-by: Stian Thorgersen <stian@redhat.com>
2023-02-03 10:45:11 +00:00

46 lines
1.3 KiB
TypeScript

// 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);
const realmId = faker.internet.userName();
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 () => {
const username = faker.internet.userName().toLowerCase();
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);
});
});