Skip to content

Commit 9d77ae5

Browse files
Merge pull request #95 from contentstack/fix/api-version-bug-fix
added api_version param which is to be passed in headers
2 parents 4723524 + 11b054e commit 9d77ae5

File tree

8 files changed

+37
-26
lines changed

8 files changed

+37
-26
lines changed

lib/entity.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,14 @@ export const create = ({ http, params }) => {
8686
if (response.data) {
8787
return new this.constructor(http, parseData(response, this.stackHeaders, this.content_type_uid, this.taxonomy_uid))
8888
} else {
89-
throw error(response)
89+
if (response.status >= 200 && response.status < 300) {
90+
return {
91+
status: response.status,
92+
statusText: response.statusText
93+
}
94+
} else {
95+
throw error(response)
96+
}
9097
}
9198
} catch (err) {
9299
throw error(err)
@@ -301,4 +308,4 @@ export const move = (http, type, force = false, params = {}) => {
301308
throw error(err)
302309
}
303310
}
304-
}
311+
}

lib/organization/teams/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,11 @@ export function Teams (http, data) {
8686
* @example
8787
* import * as contentstack from '@contentstack/management'
8888
* const client = contentstack.client()
89-
* client.organization('organizationUid').teams('teamUid').users().fetchAll()
89+
* client.organization('organizationUid').teams('teamUid').teamUsers().fetchAll()
9090
* .then((response) => console.log(response))
9191
*
9292
*/
93-
this.users = (userId = null) => {
93+
this.teamUsers = (userId = null) => {
9494
data.organizationUid = this.organizationUid
9595
data.teamUid = this.uid
9696
if (userId) {
@@ -153,11 +153,11 @@ export function Teams (http, data) {
153153
* client.organization('organizationUid').teams().fetchAll()
154154
* .then((response) => console.log(response))
155155
*/
156-
this.fetchAll = fetchAll(http, TeamsCollection)
156+
this.fetchAll = fetchAll(http, TeamsCollection, { api_version: 1.1 })
157157
}
158158
}
159159
export function TeamsCollection (http, teamsData) {
160-
const obj = cloneDeep(teamsData) || []
160+
const obj = cloneDeep(teamsData.teams) || []
161161
const teamsCollection = obj.map((team) => {
162162
return new Teams(http, team)
163163
})

lib/organization/teams/teamUsers/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export function TeamUsers (http, data) {
2121
* import * as contentstack from '@contentstack/management'
2222
* const client = contentstack.client()
2323
*
24-
* client.organization('organizationUid').teams('teamUid').users('userId').remove()
24+
* client.organization('organizationUid').teams('teamUid').teamUsers('userId').remove()
2525
* .then((response) => console.log(response))
2626
*
2727
*/
@@ -40,7 +40,7 @@ export function TeamUsers (http, data) {
4040
* const usersMail = {
4141
* emails: ['emailId1','emailId2' ]
4242
* }
43-
* client.organization('organizationUid').teams('teamUid').users('userId').add(usersMail)
43+
* client.organization('organizationUid').teams('teamUid').teamUsers('userId').add(usersMail)
4444
* .then((response) => console.log(response))
4545
*
4646
*/
@@ -56,15 +56,15 @@ export function TeamUsers (http, data) {
5656
* const client = contentstack.client()
5757
* const usersMail = {
5858
* emails: ['emailId1','emailId2' ]}
59-
* client.organization('organizationUid').teams('teamUid').users('userId').query().find()
59+
* client.organization('organizationUid').teams('teamUid').teamUsers('userId').query().find()
6060
* .then((response) => console.log(response))
6161
*
6262
*/
6363
this.fetchAll = fetchAll(http, UsersCollection)
6464
}
6565
}
6666
export function UsersCollection (http, data) {
67-
const obj = cloneDeep(data.users) || []
67+
const obj = cloneDeep(data.teamUsers) || []
6868
const usersCollection = obj.map((user) => {
6969
return new TeamUsers(http, { userId: user })
7070
})

test/api/team-users-test.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ describe('Teams Users API Test', () => {
1919
emails: ['email@email.com']
2020
}
2121
makeUsers(organizationUid, teamUid).add(usersMail).then((response) => {
22-
expect(response).to.be.equal(null)
22+
expect(response.status).to.be.equal(201)
23+
done()
2324
})
2425
.catch(done)
2526
})
@@ -42,5 +43,5 @@ describe('Teams Users API Test', () => {
4243
})
4344

4445
function makeUsers (organizationUid, teamUid, userId = null) {
45-
return client.organization(organizationUid).teams(teamUid).users(userId)
46+
return client.organization(organizationUid).teams(teamUid).teamUsers(userId)
4647
}

test/typescript/teamUsers.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,23 @@ export function testTeamUsers (organization: Organization) {
88
const usersMail = {
99
emails: ['email@email.com']
1010
}
11-
organization.teams(teamUid).users().add(usersMail).then((response) => {
12-
expect(response).not.to.be.equal(null)
11+
organization.teams(teamUid).teamUsers().add(usersMail).then((response) => {
12+
expect(response.status).to.be.eql(201)
1313
done()
1414
})
1515
.catch(done)
1616
})
1717
test('should remove the user when uid is passed', done => {
1818
const user_id = 'user_id'
19-
organization.teams(teamUid).users(user_id).remove().then((response) => {
19+
organization.teams(teamUid).teamUsers(user_id).remove().then((response) => {
2020
expect(response.status).to.be.equal(204)
2121
done()
2222
})
2323
.catch(done)
2424
})
2525
test('should fetch all users', done => {
26-
organization.teams(teamUid).users()
27-
.fetchAll()
26+
organization.teams(teamUid).teamUsers()
27+
.fetchAll()
2828
.then((response) => {
2929
expect(response.items[0]).not.to.be.equal(undefined)
3030
done()

test/typescript/teams.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ export function testTeams (organization: Organization) {
77
test('should fetch all the teams', done => {
88
organization.teams().fetchAll()
99
.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)
10+
expect(teams.items[0].organizationUid).not.to.be.equal(undefined)
11+
expect(teams.items[0].name).not.to.be.equal(null)
12+
expect(teams.items[0].created_by).not.to.be.equal(null)
13+
expect(teams.items[0].updated_by).not.to.be.equal(null)
1414
done()
1515
})
1616
.catch(done)

test/unit/team-test.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ import { systemUidMock, teamsMock, noticeMock, teamUsersMock, stackRoleMappingMo
88
describe('Contentstack Team test', () => {
99
it('should get all the teams when correct organization uid is passed', done => {
1010
var mock = new MockAdapter(Axios)
11-
mock.onGet(`/organizations/organization_uid/teams`).reply(200, [teamsMock])
11+
mock.onGet(`/organizations/organization_uid/teams`).reply(200, {
12+
count: 17,
13+
teams: [teamsMock]
14+
})
1215
makeTeams().fetchAll()
1316
.then((teams) => {
1417
expect(teams.items[0].uid).to.be.equal('UID')
@@ -73,7 +76,7 @@ describe('Contentstack Team test', () => {
7376
it('should fetch all users', done => {
7477
var mock = new MockAdapter(Axios)
7578
mock.onGet(`/organizations/organization_uid/teams/UID/users`).reply(200, teamUsersMock)
76-
makeTeams({ ...systemUidMock }).users().fetchAll()
79+
makeTeams({ ...systemUidMock }).teamUsers().fetchAll()
7780
.then((users) => {
7881
users.items.forEach((user) => {
7982
expect(user.uidId).to.be.not.equal(null)

types/teams/index.d.ts

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

77
export interface Team extends TeamData {
88
update(data: TeamData, param?: { includeUserDetails?: boolean}): Promise<AnyProperty>
9-
users(): TeamUsers
10-
users(uid: string): TeamUser
9+
teamUsers(): TeamUsers
10+
teamUsers(uid: string): TeamUser
1111
stackRoleMappings(): StackRoleMappings
1212
stackRoleMappings(stackApiKey: string): StackRoleMapping
1313
fetch(): Promise<Team>
1414
delete(): Promise<AnyProperty>
1515
}
1616

1717
export interface Teams extends Creatable<Team, TeamData> {
18-
fetchAll(params?: AnyProperty): Promise<ContentstackCollection<Teams>>
18+
fetchAll(params?: AnyProperty): Promise<ContentstackCollection<Team>>
1919
}
2020

2121
export interface TeamData extends AnyProperty {

0 commit comments

Comments
 (0)