Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions lib/entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,14 @@ export const create = ({ http, params }) => {
if (response.data) {
return new this.constructor(http, parseData(response, this.stackHeaders, this.content_type_uid, this.taxonomy_uid))
} else {
throw error(response)
if (response.status >= 200 && response.status < 300) {
return {
status: response.status,
statusText: response.statusText
}
} else {
throw error(response)
}
}
} catch (err) {
throw error(err)
Expand Down Expand Up @@ -301,4 +308,4 @@ export const move = (http, type, force = false, params = {}) => {
throw error(err)
}
}
}
}
8 changes: 4 additions & 4 deletions lib/organization/teams/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ export function Teams (http, data) {
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
* client.organization('organizationUid').teams('teamUid').users().fetchAll()
* client.organization('organizationUid').teams('teamUid').teamUsers().fetchAll()
* .then((response) => console.log(response))
*
*/
this.users = (userId = null) => {
this.teamUsers = (userId = null) => {
data.organizationUid = this.organizationUid
data.teamUid = this.uid
if (userId) {
Expand Down Expand Up @@ -153,11 +153,11 @@ export function Teams (http, data) {
* client.organization('organizationUid').teams().fetchAll()
* .then((response) => console.log(response))
*/
this.fetchAll = fetchAll(http, TeamsCollection)
this.fetchAll = fetchAll(http, TeamsCollection, { api_version: 1.1 })
}
}
export function TeamsCollection (http, teamsData) {
const obj = cloneDeep(teamsData) || []
const obj = cloneDeep(teamsData.teams) || []
const teamsCollection = obj.map((team) => {
return new Teams(http, team)
})
Expand Down
8 changes: 4 additions & 4 deletions lib/organization/teams/teamUsers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export function TeamUsers (http, data) {
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
*
* client.organization('organizationUid').teams('teamUid').users('userId').remove()
* client.organization('organizationUid').teams('teamUid').teamUsers('userId').remove()
* .then((response) => console.log(response))
*
*/
Expand All @@ -40,7 +40,7 @@ export function TeamUsers (http, data) {
* const usersMail = {
* emails: ['emailId1','emailId2' ]
* }
* client.organization('organizationUid').teams('teamUid').users('userId').add(usersMail)
* client.organization('organizationUid').teams('teamUid').teamUsers('userId').add(usersMail)
* .then((response) => console.log(response))
*
*/
Expand All @@ -56,15 +56,15 @@ export function TeamUsers (http, data) {
* const client = contentstack.client()
* const usersMail = {
* emails: ['emailId1','emailId2' ]}
* client.organization('organizationUid').teams('teamUid').users('userId').query().find()
* client.organization('organizationUid').teams('teamUid').teamUsers('userId').query().find()
* .then((response) => console.log(response))
*
*/
this.fetchAll = fetchAll(http, UsersCollection)
}
}
export function UsersCollection (http, data) {
const obj = cloneDeep(data.users) || []
const obj = cloneDeep(data.teamUsers) || []
const usersCollection = obj.map((user) => {
return new TeamUsers(http, { userId: user })
})
Expand Down
5 changes: 3 additions & 2 deletions test/api/team-users-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ describe('Teams Users API Test', () => {
emails: ['[email protected]']
}
makeUsers(organizationUid, teamUid).add(usersMail).then((response) => {
expect(response).to.be.equal(null)
expect(response.status).to.be.equal(201)
done()
})
.catch(done)
})
Expand All @@ -42,5 +43,5 @@ describe('Teams Users API Test', () => {
})

function makeUsers (organizationUid, teamUid, userId = null) {
return client.organization(organizationUid).teams(teamUid).users(userId)
return client.organization(organizationUid).teams(teamUid).teamUsers(userId)
}
10 changes: 5 additions & 5 deletions test/typescript/teamUsers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@ export function testTeamUsers (organization: Organization) {
const usersMail = {
emails: ['[email protected]']
}
organization.teams(teamUid).users().add(usersMail).then((response) => {
expect(response).not.to.be.equal(null)
organization.teams(teamUid).teamUsers().add(usersMail).then((response) => {
expect(response.status).to.be.eql(201)
done()
})
.catch(done)
})
test('should remove the user when uid is passed', done => {
const user_id = 'user_id'
organization.teams(teamUid).users(user_id).remove().then((response) => {
organization.teams(teamUid).teamUsers(user_id).remove().then((response) => {
expect(response.status).to.be.equal(204)
done()
})
.catch(done)
})
test('should fetch all users', done => {
organization.teams(teamUid).users()
.fetchAll()
organization.teams(teamUid).teamUsers()
.fetchAll()
.then((response) => {
expect(response.items[0]).not.to.be.equal(undefined)
done()
Expand Down
8 changes: 4 additions & 4 deletions test/typescript/teams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ export function testTeams (organization: Organization) {
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)
expect(teams.items[0].organizationUid).not.to.be.equal(undefined)
expect(teams.items[0].name).not.to.be.equal(null)
expect(teams.items[0].created_by).not.to.be.equal(null)
expect(teams.items[0].updated_by).not.to.be.equal(null)
done()
})
.catch(done)
Expand Down
7 changes: 5 additions & 2 deletions test/unit/team-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ import { systemUidMock, teamsMock, noticeMock, teamUsersMock, stackRoleMappingMo
describe('Contentstack Team test', () => {
it('should get all the teams when correct organization uid is passed', done => {
var mock = new MockAdapter(Axios)
mock.onGet(`/organizations/organization_uid/teams`).reply(200, [teamsMock])
mock.onGet(`/organizations/organization_uid/teams`).reply(200, {
count: 17,
teams: [teamsMock]
})
makeTeams().fetchAll()
.then((teams) => {
expect(teams.items[0].uid).to.be.equal('UID')
Expand Down Expand Up @@ -73,7 +76,7 @@ describe('Contentstack Team test', () => {
it('should fetch all users', done => {
var mock = new MockAdapter(Axios)
mock.onGet(`/organizations/organization_uid/teams/UID/users`).reply(200, teamUsersMock)
makeTeams({ ...systemUidMock }).users().fetchAll()
makeTeams({ ...systemUidMock }).teamUsers().fetchAll()
.then((users) => {
users.items.forEach((user) => {
expect(user.uidId).to.be.not.equal(null)
Expand Down
6 changes: 3 additions & 3 deletions types/teams/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ import { StackRoleMapping, StackRoleMappings, StackRoleMappingData } from "./sta

export interface Team extends TeamData {
update(data: TeamData, param?: { includeUserDetails?: boolean}): Promise<AnyProperty>
users(): TeamUsers
users(uid: string): TeamUser
teamUsers(): TeamUsers
teamUsers(uid: string): TeamUser
stackRoleMappings(): StackRoleMappings
stackRoleMappings(stackApiKey: string): StackRoleMapping
fetch(): Promise<Team>
delete(): Promise<AnyProperty>
}

export interface Teams extends Creatable<Team, TeamData> {
fetchAll(params?: AnyProperty): Promise<ContentstackCollection<Teams>>
fetchAll(params?: AnyProperty): Promise<ContentstackCollection<Team>>
}

export interface TeamData extends AnyProperty {
Expand Down