diff --git a/lib/organization/team/stackRoleMapping/index.js b/lib/organization/team/stackRoleMapping/index.js index 531167b0..2d34d5f4 100644 --- a/lib/organization/team/stackRoleMapping/index.js +++ b/lib/organization/team/stackRoleMapping/index.js @@ -3,8 +3,7 @@ */ import cloneDeep from 'lodash/cloneDeep' import { - deleteEntity, - fetchAll + deleteEntity } from '../../../entity' import error from '../../../core/contentstackError' @@ -98,11 +97,20 @@ export function StackRoleMappings (http, data) { * client.organization('organizationUid').teams('teamUid').stackRoleMappings().fetchAll * .then((response) => console.log(response)) */ - this.fetchAll = fetchAll(http, stackRoleMappingsCollection) + this.fetchAll = async () => { + try { + const response = await http.get(this.urlPath) + if (response.data) { + return response.data + } + } catch (err) { + throw error(err) + } + } } } export function stackRoleMappingsCollection (http, data) { - const obj = cloneDeep(data) || [] + const obj = cloneDeep(data.stackRoleMappings) || [] const stackRoleMappingCollection = obj.map((stackRoleMappings) => { return stackRoleMappings(http, { stackRoleMappings: stackRoleMappings }) }) diff --git a/lib/organization/team/teamUsers/index.js b/lib/organization/team/teamUsers/index.js index fad5e435..b56b4c21 100644 --- a/lib/organization/team/teamUsers/index.js +++ b/lib/organization/team/teamUsers/index.js @@ -2,7 +2,7 @@ import cloneDeep from 'lodash/cloneDeep' import { create, deleteEntity, - query + fetchAll } from '../../../entity' export function TeamUsers (http, data) { @@ -60,7 +60,7 @@ export function TeamUsers (http, data) { * .then((response) => console.log(response)) * */ - this.query = query({ http: http, wrapperCollection: UsersCollection }) + this.fetchAll = fetchAll(http, UsersCollection) } } export function UsersCollection (http, data) { diff --git a/test/api/team-stack-role-mapping-test.js b/test/api/team-stack-role-mapping-test.js index 092b31eb..c94bc318 100644 --- a/test/api/team-stack-role-mapping-test.js +++ b/test/api/team-stack-role-mapping-test.js @@ -16,10 +16,7 @@ describe('Teams API Test', () => { }) it('should fetch all stackRoleMappings', done => { makestackRoleMappings(organizationUid, teamUid).fetchAll().then((response) => { - response.items.forEach((stackRoleMapping) => { - console.log(stackRoleMapping) - }) - expect(response).to.be.not.equal(null) + expect(response.stackRoleMappings).to.be.not.equal(undefined) done() }) .catch(done) diff --git a/test/api/team-users-test.js b/test/api/team-users-test.js index 861a9045..674cfb57 100644 --- a/test/api/team-users-test.js +++ b/test/api/team-users-test.js @@ -9,7 +9,7 @@ const organizationUid = 'organizationUid' const teamUid = 'teamUid' const userId = 'userId' -describe('Teams API Test', () => { +describe('Teams Users API Test', () => { beforeEach(() => { const user = jsonReader('loggedinuser.json') client = contentstackClient(user.authtoken) @@ -32,8 +32,7 @@ describe('Teams API Test', () => { }) it('should fetch all users', async () => { makeUsers(organizationUid, teamUid) - .query() - .find() + .fetchAll() .then((response) => { response.items.forEach((user) => { expect(user.uidId).to.be.not.equal(null) diff --git a/test/unit/team-users-test.js b/test/unit/team-users-test.js index 14ac8433..63302d9c 100644 --- a/test/unit/team-users-test.js +++ b/test/unit/team-users-test.js @@ -9,7 +9,7 @@ describe('Contentstack Team Users test', () => { it('should query and find all users', done => { var mock = new MockAdapter(Axios) mock.onGet(`/organizations/organization_uid/teams/team_uid/users`).reply(200, teamUsersMock) - makeTeamUsers().query().find() + makeTeamUsers().fetchAll() .then((users) => { users.items.forEach((user) => { expect(user.uidId).to.be.not.equal(null)