contensis-management-api
Advanced tools
Comparing version 1.0.0-rc.1 to 1.0.0-rc.2
@@ -13,2 +13,3 @@ import { Group } from './Group'; | ||
addUser(groupId: string, userId: string): Promise<void>; | ||
addUsers(groupId: string, userIds: string[]): Promise<void>; | ||
removeUser(groupId: string, userId: string): Promise<void>; | ||
@@ -15,0 +16,0 @@ hasUser(groupId: string, userId: string): Promise<boolean>; |
@@ -14,2 +14,3 @@ import { ContensisClient, Group, GroupListOptions, IGroupOperations, User } from '../../models'; | ||
addUser(groupId: string, userId: string): Promise<void>; | ||
addUsers(groupId: string, userIds: string[]): Promise<void>; | ||
removeUser(groupId: string, userId: string): Promise<void>; | ||
@@ -16,0 +17,0 @@ hasUser(groupId: string, userId: string): Promise<boolean>; |
@@ -107,2 +107,21 @@ import { UrlBuilder } from 'contensis-core-api'; | ||
} | ||
addUsers(groupId, userIds) { | ||
if (!groupId) { | ||
throw new Error('A valid group id needs to be specified.'); | ||
} | ||
if (!userIds || userIds.length === 0) { | ||
throw new Error('At least one valid user id needs to be specified.'); | ||
} | ||
let url = UrlBuilder.create('/api/management/security/groups/:groupId/users', {}) | ||
.addOptions(groupId, 'groupId') | ||
.setParams(this.contensisClient.getParams()) | ||
.toUrl(); | ||
return this.contensisClient.ensureBearerToken().then(() => { | ||
return this.httpClient.request(url, { | ||
headers: this.contensisClient.getHeaders(), | ||
method: 'POST', | ||
body: JSON.stringify(userIds) | ||
}); | ||
}); | ||
} | ||
removeUser(groupId, userId) { | ||
@@ -109,0 +128,0 @@ if (!groupId) { |
@@ -180,2 +180,23 @@ import * as Contensis from '../../index'; | ||
}); | ||
describe('Add users to group', () => { | ||
beforeEach(() => { | ||
setDefaultSpy(global, null); | ||
Zengenti.Contensis.Client.defaultClientConfig = null; | ||
Zengenti.Contensis.Client.configure({ | ||
fetchFn: global.fetch | ||
}); | ||
}); | ||
it('for valid group and users', async () => { | ||
let client = Zengenti.Contensis.Client.create(getDefaultConfig()); | ||
const userIds = [defaultUsers[0].id, defaultUsers[1].id]; | ||
let result = await client.security.groups.addUsers(defaultGroups[0].id, userIds); | ||
expect(global.fetch).toHaveBeenCalledTimes(2); | ||
expect(global.fetch.calls.first().args[0]).toEqual(getDefaultAuthenticateUrl()); | ||
expect(global.fetch.calls.mostRecent().args).toEqual([ | ||
`http://my-website.com/api/management/security/groups/${defaultGroups[0].id}/users`, | ||
getDefaultRequest('POST', false, JSON.stringify(userIds)) | ||
]); | ||
expect(result).toEqual(null); | ||
}); | ||
}); | ||
describe('Remove user from group', () => { | ||
@@ -182,0 +203,0 @@ beforeEach(() => { |
@@ -7,5 +7,10 @@ # Changelog | ||
## [1.0.0-rc.2] - 2020-08-05 | ||
### Added | ||
- groups: added *addUsers* method; | ||
## [1.0.0-rc.1] - 2020-07-24 | ||
### Added | ||
- entries: added search via GET; | ||
### Changed | ||
- entries: added search via GET; | ||
- users and groups: added *security.* namespace for *users* and *groups* methods | ||
@@ -12,0 +17,0 @@ |
@@ -13,2 +13,3 @@ import { Group } from './Group'; | ||
addUser(groupId: string, userId: string): Promise<void>; | ||
addUsers(groupId: string, userIds: string[]): Promise<void>; | ||
removeUser(groupId: string, userId: string): Promise<void>; | ||
@@ -15,0 +16,0 @@ hasUser(groupId: string, userId: string): Promise<boolean>; |
@@ -14,2 +14,3 @@ import { ContensisClient, Group, GroupListOptions, IGroupOperations, User } from '../../models'; | ||
addUser(groupId: string, userId: string): Promise<void>; | ||
addUsers(groupId: string, userIds: string[]): Promise<void>; | ||
removeUser(groupId: string, userId: string): Promise<void>; | ||
@@ -16,0 +17,0 @@ hasUser(groupId: string, userId: string): Promise<boolean>; |
@@ -109,2 +109,21 @@ "use strict"; | ||
} | ||
addUsers(groupId, userIds) { | ||
if (!groupId) { | ||
throw new Error('A valid group id needs to be specified.'); | ||
} | ||
if (!userIds || userIds.length === 0) { | ||
throw new Error('At least one valid user id needs to be specified.'); | ||
} | ||
let url = contensis_core_api_1.UrlBuilder.create('/api/management/security/groups/:groupId/users', {}) | ||
.addOptions(groupId, 'groupId') | ||
.setParams(this.contensisClient.getParams()) | ||
.toUrl(); | ||
return this.contensisClient.ensureBearerToken().then(() => { | ||
return this.httpClient.request(url, { | ||
headers: this.contensisClient.getHeaders(), | ||
method: 'POST', | ||
body: JSON.stringify(userIds) | ||
}); | ||
}); | ||
} | ||
removeUser(groupId, userId) { | ||
@@ -111,0 +130,0 @@ if (!groupId) { |
@@ -182,2 +182,23 @@ "use strict"; | ||
}); | ||
describe('Add users to group', () => { | ||
beforeEach(() => { | ||
specs_utils_spec_1.setDefaultSpy(global, null); | ||
Zengenti.Contensis.Client.defaultClientConfig = null; | ||
Zengenti.Contensis.Client.configure({ | ||
fetchFn: global.fetch | ||
}); | ||
}); | ||
it('for valid group and users', async () => { | ||
let client = Zengenti.Contensis.Client.create(specs_utils_spec_1.getDefaultConfig()); | ||
const userIds = [specs_utils_spec_1.defaultUsers[0].id, specs_utils_spec_1.defaultUsers[1].id]; | ||
let result = await client.security.groups.addUsers(specs_utils_spec_1.defaultGroups[0].id, userIds); | ||
expect(global.fetch).toHaveBeenCalledTimes(2); | ||
expect(global.fetch.calls.first().args[0]).toEqual(specs_utils_spec_1.getDefaultAuthenticateUrl()); | ||
expect(global.fetch.calls.mostRecent().args).toEqual([ | ||
`http://my-website.com/api/management/security/groups/${specs_utils_spec_1.defaultGroups[0].id}/users`, | ||
specs_utils_spec_1.getDefaultRequest('POST', false, JSON.stringify(userIds)) | ||
]); | ||
expect(result).toEqual(null); | ||
}); | ||
}); | ||
describe('Remove user from group', () => { | ||
@@ -184,0 +205,0 @@ beforeEach(() => { |
{ | ||
"name": "contensis-management-api", | ||
"version": "1.0.0-rc.1", | ||
"version": "1.0.0-rc.2", | ||
"description": "Contensis Javascript Management API", | ||
@@ -5,0 +5,0 @@ "engines": { |
@@ -1,2 +0,4 @@ | ||
# contensis-management-api | ||
Contensis JavaScript Management API implementation written in TypeScript | ||
# contensis-management-api [](https://www.npmjs.com/package/contensis-management-api) | ||
Contensis JavaScript Management API implementation written in TypeScript. | ||
The *[contensis-management-api-examples](https://github.com/contensis/contensis-management-api-examples)* repo contains Express and React examples. |
@@ -14,2 +14,3 @@ import { Group } from './Group'; | ||
addUser(groupId: string, userId: string): Promise<void>; | ||
addUsers(groupId: string, userIds: string[]): Promise<void>; | ||
removeUser(groupId: string, userId: string): Promise<void>; | ||
@@ -16,0 +17,0 @@ hasUser(groupId: string, userId: string): Promise<boolean>; |
@@ -249,2 +249,32 @@ import * as Contensis from '../../index'; | ||
describe('Add users to group', () => { | ||
beforeEach(() => { | ||
setDefaultSpy(global, null); | ||
Zengenti.Contensis.Client.defaultClientConfig = null; | ||
Zengenti.Contensis.Client.configure({ | ||
fetchFn: global.fetch | ||
}); | ||
}); | ||
it('for valid group and users', async () => { | ||
let client = Zengenti.Contensis.Client.create(getDefaultConfig()); | ||
const userIds = [defaultUsers[0].id, defaultUsers[1].id]; | ||
let result = await client.security.groups.addUsers(defaultGroups[0].id, userIds); | ||
expect(global.fetch).toHaveBeenCalledTimes(2); | ||
expect((global.fetch as any).calls.first().args[0]).toEqual(getDefaultAuthenticateUrl()); | ||
expect((global.fetch as any).calls.mostRecent().args).toEqual([ | ||
`http://my-website.com/api/management/security/groups/${defaultGroups[0].id}/users`, | ||
getDefaultRequest('POST', false, JSON.stringify(userIds)) | ||
]); | ||
expect(result).toEqual(null); | ||
}); | ||
}); | ||
describe('Remove user from group', () => { | ||
@@ -251,0 +281,0 @@ beforeEach(() => { |
@@ -135,2 +135,26 @@ import { ContensisClient, Group, GroupListOptions, IGroupOperations, User } from '../../models'; | ||
addUsers(groupId: string, userIds: string[]): Promise<void> { | ||
if (!groupId) { | ||
throw new Error('A valid group id needs to be specified.'); | ||
} | ||
if (!userIds || userIds.length === 0) { | ||
throw new Error('At least one valid user id needs to be specified.'); | ||
} | ||
let url = UrlBuilder.create('/api/management/security/groups/:groupId/users', | ||
{}) | ||
.addOptions(groupId, 'groupId') | ||
.setParams(this.contensisClient.getParams()) | ||
.toUrl(); | ||
return this.contensisClient.ensureBearerToken().then(() => { | ||
return this.httpClient.request<void>(url, { | ||
headers: this.contensisClient.getHeaders(), | ||
method: 'POST', | ||
body: JSON.stringify(userIds) | ||
}); | ||
}); | ||
} | ||
removeUser(groupId: string, userId: string): Promise<void> { | ||
@@ -137,0 +161,0 @@ if (!groupId) { |
591472
12834
5