Skip to content

Commit 17c5970

Browse files
types support for team Users and api test cases
1 parent 85ee13e commit 17c5970

File tree

5 files changed

+53
-13
lines changed

5 files changed

+53
-13
lines changed

test/typescript/index.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import { orgAppRequest } from './app-request';
1919
import { authorization } from './authorization';
2020
import { testTaxonomy } from './taxonomy';
2121
import { testTerm } from './terms';
22+
import { testTeams } from './teams';
23+
import { testTeamUsers } from './teamUsers';
2224
dotenv.config()
2325
jest.setTimeout(10000);
2426

@@ -49,7 +51,8 @@ describe('Typescript API test', () => {
4951
authorization(org.app(process.env.APP_UID as string).authorization())
5052
orgAppRequest(org.appRequest())
5153
deleteApp(org)
52-
54+
testTeams(org)
55+
testTeamUsers(org)
5356
const stack = client.stack({api_key: process.env.APIKEY as string})
5457

5558
createBranch(stack)

test/typescript/teamUsers.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { expect } from "chai";
2+
import { Organization } from "../../types/organization";
3+
4+
let teamUid = 'teamUid'
5+
export function testTeamUsers (organization: Organization) {
6+
describe('Contentstack Team Users test', () => {
7+
test('should add the user when user\'s mail is passed', done => {
8+
const usersMail = {
9+
emails: ['email@email.com']
10+
}
11+
organization.teams(teamUid).users().add(usersMail).then((response) => {
12+
expect(response).not.to.be.equal(null)
13+
done()
14+
})
15+
.catch(done)
16+
})
17+
test('should remove the user when uid is passed', done => {
18+
const user_id = 'user_id'
19+
organization.teams(teamUid).users(user_id).remove().then((response) => {
20+
expect(response.status).to.be.equal(204)
21+
done()
22+
})
23+
.catch(done)
24+
})
25+
test('should fetch all users', done => {
26+
organization.teams(teamUid).users()
27+
.fetchAll()
28+
.then((response) => {
29+
expect(response.items[0]).not.to.be.equal(undefined)
30+
done()
31+
})
32+
.catch(done)
33+
})
34+
})
35+
}
36+

test/typescript/teams.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,13 @@ export function testTeams (organization: Organization) {
6060
email: 'abc@abc.com'
6161
}
6262
],
63-
organizationRole: 'blt09e5dfced326aaea',
63+
organizationRole: '',
6464
stackRoleMapping: []
65-
}
65+
}
6666
organization.teams(teamUid).update(updateData)
6767
.then((team) => {
6868
expect(team.name).to.be.equal(updateData.name)
69+
expect(team.organizationRole).to.be.equal(updateData.organizationRole)
6970
expect(team.createdByUserName).not.to.be.equal(undefined)
7071
expect(team.updatedByUserName).not.to.be.equal(undefined)
7172
done()

types/teams/index.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import { StackRoleMapping, StackRoleMappings, StackRoleMappingData } from "./sta
66

77
export interface Team extends TeamData {
88
update(data: TeamData, param?: { includeUserDetails?: boolean}): Promise<AnyProperty>
9-
users(): User
10-
users(uid: string): Users
9+
users(): Users
10+
users(uid: string): User
1111
stackRoleMappings(): StackRoleMappings
1212
stackRoleMappings(uid: string): StackRoleMapping
1313
fetch(): Promise<Team>

types/teams/teamUsers/index.d.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import { AnyProperty, SystemFields } from "../../utility/fields";
2-
import { Creatable, Queryable, SystemFunction } from "../../utility/operations";
1+
import { AnyProperty } from "../../utility/fields";
32

4-
export interface User extends SystemFields, SystemFunction<User> {
3+
export interface Users extends UserData {
4+
add(data:UserData): Promise<UserData>
5+
fetchAll(params?: { includeUserDetails: boolean, include_count: boolean}): Promise<AnyProperty>
56
}
67

7-
export interface Users extends Creatable<User, {User: UserData}> {
8-
}
9-
10-
export interface Users extends Queryable<User, {User: UserData}> {
8+
export interface User {
9+
remove(): Promise<AnyProperty>
1110
}
1211

1312
export interface UserData extends AnyProperty {
14-
users: string[]
13+
emails?: string[]
14+
users?: string[]
1515
}

0 commit comments

Comments
 (0)