Skip to content

Commit 110671a

Browse files
types support for stackRoleMapping and test cases
1 parent 3c526e0 commit 110671a

File tree

4 files changed

+63
-5
lines changed

4 files changed

+63
-5
lines changed

test/typescript/index.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { testTaxonomy } from './taxonomy';
2121
import { testTerm } from './terms';
2222
import { testTeams } from './teams';
2323
import { testTeamUsers } from './teamUsers';
24+
import { testTeamStackRoleMapping } from './teamsStackRoleMappings';
2425
dotenv.config()
2526
jest.setTimeout(10000);
2627

@@ -53,6 +54,8 @@ describe('Typescript API test', () => {
5354
deleteApp(org)
5455
testTeams(org)
5556
testTeamUsers(org)
57+
testTeamStackRoleMapping(org)
58+
5659
const stack = client.stack({api_key: process.env.APIKEY as string})
5760

5861
createBranch(stack)
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { expect } from "chai";
2+
import { Organization } from "../../types/organization";
3+
4+
let teamUid = 'teamUid'
5+
let stackApiKey = 'stackApiKey'
6+
export function testTeamStackRoleMapping (organization: Organization) {
7+
describe('Contentstack Teams Stack Role Mapping test', () => {
8+
it('should fetch all stackRoleMappings', done => {
9+
organization.teams(teamUid).stackRoleMappings().fetchAll().then((response) => {
10+
expect(response).to.be.not.equal(undefined)
11+
done()
12+
})
13+
.catch(done)
14+
})
15+
it('should add roles', done => {
16+
const stackRoleMappings = {
17+
stackApiKey: 'stackApiKey',
18+
roles: [
19+
'role_uid'
20+
]
21+
}
22+
organization.teams(teamUid).stackRoleMappings(stackApiKey).add(stackRoleMappings).then((response) => {
23+
expect(response.stackRoleMapping).not.to.be.equal(undefined)
24+
expect(response.stackRoleMapping.roles[0]).to.be.equal(stackRoleMappings.roles[0])
25+
expect(response.stackRoleMapping.stackApiKey).to.be.equal(stackRoleMappings.stackApiKey)
26+
done()
27+
})
28+
.catch(done)
29+
})
30+
it('should update roles', done => {
31+
const stackRoleMappings = {
32+
roles: [
33+
'role_uid1',
34+
'role_uid2'
35+
]
36+
}
37+
organization.teams(teamUid).stackRoleMappings(stackApiKey).update(stackRoleMappings).then((response) => {
38+
expect(response).not.to.be.equal(undefined)
39+
expect(response.StackRoleMappingData.roles[0]).to.be.equal(stackRoleMappings.roles[0])
40+
expect(response.StackRoleMappingData.stackApiKey).to.be.equal(stackApiKey)
41+
done()
42+
})
43+
.catch(done)
44+
})
45+
it('should delete roles', done => {
46+
organization.teams(teamUid).stackRoleMappings(stackApiKey).delete().then((response) => {
47+
expect(response.status).to.be.equal(204)
48+
done()
49+
})
50+
.catch(done)
51+
})
52+
})
53+
}
54+

types/teams/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export interface Team extends TeamData {
99
users(): TeamUsers
1010
users(uid: string): TeamUser
1111
stackRoleMappings(): StackRoleMappings
12-
stackRoleMappings(uid: string): StackRoleMapping
12+
stackRoleMappings(stackApiKey: string): StackRoleMapping
1313
fetch(): Promise<Team>
1414
delete(): Promise<AnyProperty>
1515
}
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@ import { AnyProperty, SystemFields } from "../../utility/fields";
22
import { ContentstackCollection } from '../../contentstackCollection'
33
import { SystemFunction } from "../../utility/operations";
44

5-
export interface StackRoleMapping extends SystemFields, SystemFunction<StackRoleMapping> {
6-
update(data: { stackRoleMapping: StackRoleMappingData }): Promise<StackRoleMapping>
5+
export interface StackRoleMapping extends StackRoleMappingData {
6+
update(data:StackRoleMappingData): Promise<{StackRoleMappingData: StackRoleMappingData}>
77
}
88

9-
export interface StackRoleMappings {
9+
export interface StackRoleMappings extends StackRoleMappingData {
1010
fetchAll(params?: AnyProperty): Promise<ContentstackCollection<StackRoleMappings>>
11-
add(data: { stackRoleMapping: StackRoleMappingData }): Promise<StackRoleMapping>
11+
add(data: StackRoleMappingData): Promise<StackRoleMappings>
1212
}
1313

1414
export interface StackRoleMappingData extends AnyProperty {
1515
stackApiKey?: string,
1616
roles: string[]
1717
}
18+

0 commit comments

Comments
 (0)