Skip to content
This repository has been archived by the owner on Apr 19, 2023. It is now read-only.

Commit

Permalink
add 'POST /{realm}/groups/{id}/children' api
Browse files Browse the repository at this point in the history
  • Loading branch information
wwwy3y3 committed Apr 25, 2019
1 parent dd8fba8 commit 2b20010
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/resources/groups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,22 @@ export class Groups extends Resource<{realm?: string}> {
urlParamKeys: ['id'],
});

/**
* Set or create child.
* This will just set the parent if it exists. Create it and set the parent if the group doesn’t exist.
*/

public setOrCreateChild = this.makeUpdateRequest<
{id: string},
GroupRepresentation,
{id: string}
>({
method: 'POST',
path: '/{id}/children',
urlParamKeys: ['id'],
returnResourceIdInLocationHeader: {field: 'id'},
});

/**
* Members
*/
Expand Down
20 changes: 20 additions & 0 deletions test/groups.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,26 @@ describe('Groups', function() {
});
});

it('set or create child', async () => {
const groupName = 'child-group';
const groupId = this.currentGroup.id;
const childGroup = await this.kcAdminClient.groups.setOrCreateChild(
{id: groupId},
{name: groupName},
);

expect(childGroup.id).to.be.ok;

const group = await this.kcAdminClient.groups.findOne({
id: groupId,
});
expect(group.subGroups[0]).to.deep.include({
id: childGroup.id,
name: groupName,
path: `/${group.name}/${groupName}`,
});
});

/**
* Role mappings
*/
Expand Down

0 comments on commit 2b20010

Please sign in to comment.