Skip to content

Commit

Permalink
replaced query with fetchAll function
Browse files Browse the repository at this point in the history
  • Loading branch information
harshithad0703 committed Nov 7, 2023
1 parent 57e0dfb commit 9263fde
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 14 deletions.
16 changes: 12 additions & 4 deletions lib/organization/team/stackRoleMapping/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
*/
import cloneDeep from 'lodash/cloneDeep'
import {
deleteEntity,
fetchAll
deleteEntity
} from '../../../entity'
import error from '../../../core/contentstackError'

Expand Down Expand Up @@ -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 })
})
Expand Down
4 changes: 2 additions & 2 deletions lib/organization/team/teamUsers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import cloneDeep from 'lodash/cloneDeep'
import {
create,
deleteEntity,
query
fetchAll
} from '../../../entity'

export function TeamUsers (http, data) {
Expand Down Expand Up @@ -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) {
Expand Down
5 changes: 1 addition & 4 deletions test/api/team-stack-role-mapping-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 2 additions & 3 deletions test/api/team-users-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion test/unit/team-users-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 9263fde

Please sign in to comment.