diff --git a/lib/entity.js b/lib/entity.js index b3ed2a4f..7a9246b3 100644 --- a/lib/entity.js +++ b/lib/entity.js @@ -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) @@ -301,4 +308,4 @@ export const move = (http, type, force = false, params = {}) => { throw error(err) } } -} \ No newline at end of file +} diff --git a/lib/organization/teams/index.js b/lib/organization/teams/index.js index 38ab9fbd..1c2fa066 100644 --- a/lib/organization/teams/index.js +++ b/lib/organization/teams/index.js @@ -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) { @@ -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) }) diff --git a/lib/organization/teams/teamUsers/index.js b/lib/organization/teams/teamUsers/index.js index b56b4c21..3f88438d 100644 --- a/lib/organization/teams/teamUsers/index.js +++ b/lib/organization/teams/teamUsers/index.js @@ -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)) * */ @@ -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)) * */ @@ -56,7 +56,7 @@ 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)) * */ @@ -64,7 +64,7 @@ export function TeamUsers (http, data) { } } 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 }) }) diff --git a/test/api/team-users-test.js b/test/api/team-users-test.js index 674cfb57..30c5d41d 100644 --- a/test/api/team-users-test.js +++ b/test/api/team-users-test.js @@ -19,7 +19,8 @@ describe('Teams Users API Test', () => { emails: ['email@email.com'] } makeUsers(organizationUid, teamUid).add(usersMail).then((response) => { - expect(response).to.be.equal(null) + expect(response.status).to.be.equal(201) + done() }) .catch(done) }) @@ -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) } diff --git a/test/typescript/teamUsers.ts b/test/typescript/teamUsers.ts index 45245a3f..1cfad9a9 100644 --- a/test/typescript/teamUsers.ts +++ b/test/typescript/teamUsers.ts @@ -8,23 +8,23 @@ export function testTeamUsers (organization: Organization) { const usersMail = { emails: ['email@email.com'] } - 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() diff --git a/test/typescript/teams.ts b/test/typescript/teams.ts index 158fe4a1..d430df1b 100644 --- a/test/typescript/teams.ts +++ b/test/typescript/teams.ts @@ -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) diff --git a/test/unit/team-test.js b/test/unit/team-test.js index ed8d14a2..8e6e3545 100644 --- a/test/unit/team-test.js +++ b/test/unit/team-test.js @@ -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') @@ -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) diff --git a/types/teams/index.d.ts b/types/teams/index.d.ts index 4d980ea0..b0bb91de 100644 --- a/types/teams/index.d.ts +++ b/types/teams/index.d.ts @@ -6,8 +6,8 @@ import { StackRoleMapping, StackRoleMappings, StackRoleMappingData } from "./sta export interface Team extends TeamData { update(data: TeamData, param?: { includeUserDetails?: boolean}): Promise - users(): TeamUsers - users(uid: string): TeamUser + teamUsers(): TeamUsers + teamUsers(uid: string): TeamUser stackRoleMappings(): StackRoleMappings stackRoleMappings(stackApiKey: string): StackRoleMapping fetch(): Promise @@ -15,7 +15,7 @@ export interface Team extends TeamData { } export interface Teams extends Creatable { - fetchAll(params?: AnyProperty): Promise> + fetchAll(params?: AnyProperty): Promise> } export interface TeamData extends AnyProperty {