Skip to content

Commit 560c01d

Browse files
feat: types support for teams
1 parent d88ca28 commit 560c01d

File tree

4 files changed

+90
-2
lines changed

4 files changed

+90
-2
lines changed

lib/organization/teams/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ export function Teams (http, data) {
3939
* .then((response) => console.log(response))
4040
*
4141
*/
42-
this.update = async (updateData, params = {}) => {
42+
this.update = async (updateData) => {
4343
try {
44-
const response = await http.put(this.urlPath, updateData, { params })
44+
const response = await http.put(this.urlPath, updateData)
4545
if (response.data) {
4646
return response.data
4747
}

test/typescript/teams.ts

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import { expect } from "chai";
2+
import { Organization } from "../../types/organization";
3+
4+
let teamUid = ''
5+
export function testTeams (organization: Organization) {
6+
describe('Contentstack Teams test', () => {
7+
test('should fetch all the teams', done => {
8+
organization.teams().fetchAll()
9+
.then((teams) => {
10+
expect(teams[0].organizationUid).not.to.be.equal(undefined)
11+
expect(teams[0].name).not.to.be.equal(null)
12+
expect(teams[0].created_by).not.to.be.equal(null)
13+
expect(teams[0].updated_by).not.to.be.equal(null)
14+
done()
15+
})
16+
.catch(done)
17+
})
18+
test('should fetch the team when correct organization uid and team uid is passed', done => {
19+
organization.teams(teamUid).fetch()
20+
.then((teams) => {
21+
expect(teams.uid).to.be.equal(teamUid)
22+
expect(teams.organizationUid).not.to.be.equal(undefined)
23+
expect(teams.name).not.to.be.equal(null)
24+
expect(teams.created_by).not.to.be.equal(null)
25+
expect(teams.updated_by).not.to.be.equal(null)
26+
done()
27+
})
28+
.catch(done)
29+
})
30+
test('should create new team when required object is passed', done => {
31+
const createData = {
32+
name: 'test_team',
33+
users: [],
34+
stackRoleMapping: [],
35+
organizationRole: ''
36+
}
37+
organization.teams().create(createData)
38+
.then((teams) => {
39+
expect(teams.uid).not.to.be.equal(null)
40+
expect(teams.name).not.to.be.equal(null)
41+
expect(teams.stackRoleMapping).not.to.be.equal(null)
42+
expect(teams.organizationRole).not.to.be.equal(null)
43+
done()
44+
})
45+
.catch(done)
46+
})
47+
test('should delete team when correct organization uid and team uid is passed', done => {
48+
organization.teams(teamUid).delete()
49+
.then((teams) => {
50+
expect(teams.status).to.be.equal(204)
51+
done()
52+
})
53+
.catch(done)
54+
})
55+
})
56+
}
57+

types/organization.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { AnyProperty, SystemFields } from './utility/fields'
77
import { ContentstackCollection, Response } from './contentstackCollection'
88
import { App, Apps } from './app'
99
import { AppRequest } from './app/request'
10+
import { Team, Teams } from './teams'
1011

1112
export interface Organizations {
1213
fetchAll(params?: AnyProperty): Promise<ContentstackCollection<Organization>>
@@ -25,6 +26,8 @@ export interface Organization extends SystemFields {
2526
app(): Apps
2627
app(uid: string): App
2728
appRequest(): AppRequest
29+
teams(): Teams
30+
teams(uid: string): Team
2831
}
2932

3033
export interface OrganizationInvite {

types/teams/index.d.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { AnyProperty, SystemFields } from "../utility/fields";
2+
import { ContentstackCollection } from '../contentstackCollection'
3+
import { Creatable, SystemFunction } from "../utility/operations";
4+
import { User, Users } from "./teamUsers";
5+
import { StackRoleMapping, StackRoleMappings } from "./stackRoleMapping";
6+
7+
export interface Team extends SystemFields, SystemFunction<Team> {
8+
update(data?:TeamData, param?: { includeUserDetails?: boolean}): Promise<Team>
9+
user(): User
10+
users(uid: string): Users
11+
stackRoleMappings(): StackRoleMappings
12+
stackRoleMappings(uid: string): StackRoleMapping
13+
}
14+
15+
export interface Teams extends Creatable<Team, TeamData> {
16+
}
17+
18+
export interface Teams {
19+
fetchAll(params?: AnyProperty): Promise<ContentstackCollection<Teams>>
20+
}
21+
22+
export interface TeamData extends AnyProperty {
23+
name: string,
24+
users: any,
25+
stackRoleMapping: any,
26+
organizationRole: string
27+
}
28+

0 commit comments

Comments
 (0)