Skip to content

Commit

Permalink
types support for stackRoleMapping and test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
harshithad0703 committed Nov 9, 2023
1 parent e85be9f commit 0aa565d
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 5 deletions.
3 changes: 3 additions & 0 deletions test/typescript/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { testTaxonomy } from './taxonomy';
import { testTerm } from './terms';
import { testTeams } from './teams';
import { testTeamUsers } from './teamUsers';
import { testTeamStackRoleMapping } from './teamsStackRoleMappings';
dotenv.config()
jest.setTimeout(10000);

Expand Down Expand Up @@ -53,6 +54,8 @@ describe('Typescript API test', () => {
deleteApp(org)
testTeams(org)
testTeamUsers(org)
testTeamStackRoleMapping(org)

const stack = client.stack({api_key: process.env.APIKEY as string})

createBranch(stack)
Expand Down
54 changes: 54 additions & 0 deletions test/typescript/teamsStackRoleMappings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { expect } from "chai";
import { Organization } from "../../types/organization";

let teamUid = 'teamUid'
let stackApiKey = 'stackApiKey'
export function testTeamStackRoleMapping (organization: Organization) {
describe('Contentstack Teams Stack Role Mapping test', () => {
it('should fetch all stackRoleMappings', done => {
organization.teams(teamUid).stackRoleMappings().fetchAll().then((response) => {
expect(response).to.be.not.equal(undefined)
done()
})
.catch(done)
})
it('should add roles', done => {
const stackRoleMappings = {
stackApiKey: 'stackApiKey',
roles: [
'role_uid'
]
}
organization.teams(teamUid).stackRoleMappings(stackApiKey).add(stackRoleMappings).then((response) => {
expect(response.stackRoleMapping).not.to.be.equal(undefined)
expect(response.stackRoleMapping.roles[0]).to.be.equal(stackRoleMappings.roles[0])
expect(response.stackRoleMapping.stackApiKey).to.be.equal(stackRoleMappings.stackApiKey)
done()
})
.catch(done)
})
it('should update roles', done => {
const stackRoleMappings = {
roles: [
'role_uid1',
'role_uid2'
]
}
organization.teams(teamUid).stackRoleMappings(stackApiKey).update(stackRoleMappings).then((response) => {
expect(response).not.to.be.equal(undefined)
expect(response.StackRoleMappingData.roles[0]).to.be.equal(stackRoleMappings.roles[0])
expect(response.StackRoleMappingData.stackApiKey).to.be.equal(stackApiKey)
done()
})
.catch(done)
})
it('should delete roles', done => {
organization.teams(teamUid).stackRoleMappings(stackApiKey).delete().then((response) => {
expect(response.status).to.be.equal(204)
done()
})
.catch(done)
})
})
}

2 changes: 1 addition & 1 deletion types/teams/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export interface Team extends TeamData {
users(): TeamUsers
users(uid: string): TeamUser
stackRoleMappings(): StackRoleMappings
stackRoleMappings(uid: string): StackRoleMapping
stackRoleMappings(stackApiKey: string): StackRoleMapping
fetch(): Promise<Team>
delete(): Promise<AnyProperty>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@ import { AnyProperty, SystemFields } from "../../utility/fields";
import { ContentstackCollection } from '../../contentstackCollection'
import { SystemFunction } from "../../utility/operations";

export interface StackRoleMapping extends SystemFields, SystemFunction<StackRoleMapping> {
update(data: { stackRoleMapping: StackRoleMappingData }): Promise<StackRoleMapping>
export interface StackRoleMapping extends StackRoleMappingData {
update(data:StackRoleMappingData): Promise<{StackRoleMappingData: StackRoleMappingData}>
}

export interface StackRoleMappings {
export interface StackRoleMappings extends StackRoleMappingData {
fetchAll(params?: AnyProperty): Promise<ContentstackCollection<StackRoleMappings>>
add(data: { stackRoleMapping: StackRoleMappingData }): Promise<StackRoleMapping>
add(data: StackRoleMappingData): Promise<StackRoleMappings>
}

export interface StackRoleMappingData extends AnyProperty {
stackApiKey?: string,
roles: string[]
}

0 comments on commit 0aa565d

Please sign in to comment.