keycloak-scim/js/libs/keycloak-admin-client/test/organizations.spec.ts
Stan Silvert 6b2ba37e9c
Add CRUD for orgainizations to admin client. (#29540)
Signed-off-by: Stan Silvert <ssilvert@redhat.com>
2024-05-15 08:03:41 +02:00

56 lines
1.6 KiB
TypeScript

// tslint:disable:no-unused-expression
import * as chai from "chai";
import { KeycloakAdminClient } from "../src/client.js";
import { credentials } from "./constants.js";
const expect = chai.expect;
describe("Organizations", () => {
let kcAdminClient: KeycloakAdminClient;
before(async () => {
kcAdminClient = new KeycloakAdminClient();
await kcAdminClient.auth(credentials);
});
it("retrieves empty organizations list", async () => {
const organizations = await kcAdminClient.organizations.find();
expect(organizations).to.be.ok;
expect(organizations).to.be.empty;
});
it("creates, updates, and removes an organization", async () => {
const myOrganization = {
name: "orga",
enabled: true,
domains: [
{
name: "orga.com",
},
],
};
const org = await kcAdminClient.organizations.create(myOrganization);
let allOrganizations = await kcAdminClient.organizations.find();
expect(allOrganizations).to.be.ok;
expect(allOrganizations).to.be.not.empty;
myOrganization.enabled = false;
await kcAdminClient.organizations.updateById(
{ id: org.id },
myOrganization,
);
allOrganizations = await kcAdminClient.organizations.find();
expect(allOrganizations).to.be.ok;
expect(allOrganizations.length).to.equal(1);
expect(allOrganizations[0].enabled).to.be.false;
await kcAdminClient.organizations.delById({
id: org.id,
});
allOrganizations = await kcAdminClient.organizations.find();
expect(allOrganizations).to.be.ok;
expect(allOrganizations).to.be.empty;
});
});