Skip to content

Commit

Permalink
feat: types support for teams
Browse files Browse the repository at this point in the history
  • Loading branch information
harshithad0703 committed Nov 7, 2023
1 parent e79409f commit 83c136c
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/organization/teams/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ export function Teams (http, data) {
* .then((response) => console.log(response))
*
*/
this.update = async (updateData, params = {}) => {
this.update = async (updateData) => {
try {
const response = await http.put(this.urlPath, updateData, { params })
const response = await http.put(this.urlPath, updateData)
if (response.data) {
return response.data
}
Expand Down
57 changes: 57 additions & 0 deletions test/typescript/teams.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { expect } from "chai";
import { Organization } from "../../types/organization";

let teamUid = ''
export function testTeams (organization: Organization) {
describe('Contentstack Teams test', () => {
test('should fetch all the teams', done => {
organization.teams().fetchAll()
.then((teams) => {
expect(teams[0].organizationUid).not.to.be.equal(undefined)
expect(teams[0].name).not.to.be.equal(null)
expect(teams[0].created_by).not.to.be.equal(null)
expect(teams[0].updated_by).not.to.be.equal(null)
done()
})
.catch(done)
})
test('should fetch the team when correct organization uid and team uid is passed', done => {
organization.teams(teamUid).fetch()
.then((teams) => {
expect(teams.uid).to.be.equal(teamUid)
expect(teams.organizationUid).not.to.be.equal(undefined)
expect(teams.name).not.to.be.equal(null)
expect(teams.created_by).not.to.be.equal(null)
expect(teams.updated_by).not.to.be.equal(null)
done()
})
.catch(done)
})
test('should create new team when required object is passed', done => {
const createData = {
name: 'test_team',
users: [],
stackRoleMapping: [],
organizationRole: ''
}
organization.teams().create(createData)
.then((teams) => {
expect(teams.uid).not.to.be.equal(null)
expect(teams.name).not.to.be.equal(null)
expect(teams.stackRoleMapping).not.to.be.equal(null)
expect(teams.organizationRole).not.to.be.equal(null)
done()
})
.catch(done)
})
test('should delete team when correct organization uid and team uid is passed', done => {
organization.teams(teamUid).delete()
.then((teams) => {
expect(teams.status).to.be.equal(204)
done()
})
.catch(done)
})
})
}

3 changes: 3 additions & 0 deletions types/organization.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { AnyProperty, SystemFields } from './utility/fields'
import { ContentstackCollection, Response } from './contentstackCollection'
import { App, Apps } from './app'
import { AppRequest } from './app/request'
import { Team, Teams } from './teams'

export interface Organizations {
fetchAll(params?: AnyProperty): Promise<ContentstackCollection<Organization>>
Expand All @@ -25,6 +26,8 @@ export interface Organization extends SystemFields {
app(): Apps
app(uid: string): App
appRequest(): AppRequest
teams(): Teams
teams(uid: string): Team
}

export interface OrganizationInvite {
Expand Down
28 changes: 28 additions & 0 deletions types/teams/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { AnyProperty, SystemFields } from "../utility/fields";
import { ContentstackCollection } from '../contentstackCollection'
import { Creatable, SystemFunction } from "../utility/operations";
import { User, Users } from "./teamUsers";
import { StackRoleMapping, StackRoleMappings } from "./stackRoleMapping";

export interface Team extends SystemFields, SystemFunction<Team> {
update(data?:TeamData, param?: { includeUserDetails?: boolean}): Promise<Team>
user(): User
users(uid: string): Users
stackRoleMappings(): StackRoleMappings
stackRoleMappings(uid: string): StackRoleMapping
}

export interface Teams extends Creatable<Team, TeamData> {
}

export interface Teams {
fetchAll(params?: AnyProperty): Promise<ContentstackCollection<Teams>>
}

export interface TeamData extends AnyProperty {
name: string,
users: any,
stackRoleMapping: any,
organizationRole: string
}

0 comments on commit 83c136c

Please sign in to comment.