Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions js/eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ export default tseslint.config(
"**/dist/",
"**/lib/",
"**/target/",
"**/.wireit/",
"**/src/generated/doc-examples/",
"./apps/keycloak-server/server/",
],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ writeFileSync(
{
extends: "../../../tsconfig.json",
include: ["admin-v2-doc-examples-check.ts"],
exclude: [],
compilerOptions: { noEmit: true },
},
null,
Expand Down
71 changes: 70 additions & 1 deletion js/libs/keycloak-admin-client/test/clientsV2.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,75 @@ describe("Clients V2 API", () => {
);
});

it("should filter and sort clients", async () => {
const clientId1 = faker.internet.username();
const clientId2 = faker.internet.username();

// Create two clients using v2 API

@michalvavrik michalvavrik Jul 15, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You will know this better as I do, but AFAICT it is customary in this js/libs/keycloak-admin-client/test/clientsV2.spec.ts to delete clients you create. I am judging based on:

  • currentClientId before/after -> deleted
  • "should create and delete a client" deleted
  • "should create an OIDC client with full configuration" deleted

It is not too important, but maybe you should delete these clients as well? This seems to be only place that doesn't clean up.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right

await kcAdminClient.clients.v2().post({
clientId: clientId1,
protocol: "openid-connect",
description: "Client 1",
enabled: true,
});

await kcAdminClient.clients.v2().post({
clientId: clientId2,
protocol: "openid-connect",
enabled: true,
});

Comment thread
shawkins marked this conversation as resolved.
// Verify we can get them via v2 API
const clients = await kcAdminClient.clients.v2().get();
expect(clients).to.be.ok;
expect(clients).to.be.an("array");

const client1 = clients!.find((c) => c.clientId === clientId1);
expect(client1).to.be.ok;

const client2 = clients!.find((c) => c.clientId === clientId2);
expect(client2).to.be.ok;

const sortedClients = await kcAdminClient.clients.v2().get({
queryParameters: {
sort: "clientId|desc",
},
});
expect(sortedClients).to.be.ok;
expect(sortedClients).to.be.an("array");
const clientIds = sortedClients!.map((c) => c.clientId!);
expect(
[...clientIds].sort((a, b) =>
b.localeCompare(a, undefined, { sensitivity: "base" }),
),
).to.deep.equal(clientIds);

const sortedClient1 = sortedClients!.find((c) => c.clientId === clientId1);
expect(sortedClient1).to.be.ok;

const sortedClient2 = sortedClients!.find((c) => c.clientId === clientId2);
expect(sortedClient2).to.be.ok;

// Filter by clientId
const filteredClients = await kcAdminClient.clients.v2().get({
queryParameters: {
fields: ["clientId"],
Comment thread
shawkins marked this conversation as resolved.
q: `clientId eq "${clientId1}"`,
},
});
expect(filteredClients).to.be.ok;
expect(filteredClients).to.be.an("array");
expect(filteredClients!.length).to.equal(1);
expect(filteredClients![0].description).to.be.undefined;

const filteredClient1 = filteredClients!.find(
(c) => c.clientId === clientId1,
);
expect(filteredClient1).to.be.ok;
await kcAdminClient.clients.v2().byId(clientId1).delete();
await kcAdminClient.clients.v2().byId(clientId2).delete();
});

it("should create and delete a client", async () => {
const clientId = faker.internet.username();

Expand All @@ -104,7 +173,7 @@ describe("Clients V2 API", () => {

// Verify we can get it via v2 API
const client = await kcAdminClient.clients.v2().byId(clientId).get();
expect((client as OIDCClientRepresentation).clientId).to.equal(clientId);
expect(client?.clientId).to.equal(clientId);

// Delete the client using v2 API
await kcAdminClient.clients.v2().byId(clientId).delete();
Expand Down
8 changes: 8 additions & 0 deletions js/libs/keycloak-admin-client/test/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "../tsconfig.test.json",
"compilerOptions": {
"noEmit": true,
"types": ["mocha", "node"]
},
"include": ["."]
}
1 change: 1 addition & 0 deletions js/libs/keycloak-admin-client/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"extends": "../../tsconfig.json",
"include": ["src"],
"exclude": ["src/generated/doc-examples"],
"compilerOptions": {
"lib": ["ESNext"],
"module": "Node16",
Expand Down
3 changes: 3 additions & 0 deletions js/libs/keycloak-admin-client/tsconfig.test.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"extends": "./tsconfig",
"compilerOptions": {
"types": ["mocha", "node"]
},
"include": ["src", "test"]
}
Loading