Skip to content

Commit cae9bdc

Browse files
test: added test cases to improve coverage report
1 parent 0a814bc commit cae9bdc

File tree

5 files changed

+56
-10
lines changed

5 files changed

+56
-10
lines changed

lib/organization/teams/index.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export function Teams (http, data) {
8787
* import * as contentstack from '@contentstack/management'
8888
* const client = contentstack.client()
8989
* client.organization('organizationUid').teams('teamUid').users().fetchAll()
90-
* .then((response) => console.log(response))
90+
* .then((response) => console.log(response))
9191
*
9292
*/
9393
this.users = (userId = null) => {
@@ -99,6 +99,18 @@ export function Teams (http, data) {
9999
return new TeamUsers(http, data)
100100
}
101101

102+
/**
103+
* @description The stackRoleMappings call on team will get the stack role Mapping.
104+
* @memberof Teams
105+
* @func users
106+
* @returns {Promise<Teams.Teams>} Response Object.
107+
* @example
108+
* import * as contentstack from '@contentstack/management'
109+
* const client = contentstack.client()
110+
* client.organization('organizationUid').teams('teamUid').stackRoleMappings().fetchAll()
111+
* .then((response) => console.log(response))
112+
*
113+
*/
102114
this.stackRoleMappings = (stackApiKey = null) => {
103115
data.organizationUid = this.organizationUid
104116
data.teamUid = this.uid

lib/organization/teams/stackRoleMappings/index.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,3 @@ export function StackRoleMappings (http, data) {
109109
}
110110
}
111111
}
112-
export function stackRoleMappingsCollection (http, data) {
113-
const obj = cloneDeep(data.stackRoleMappings) || []
114-
const stackRoleMappingCollection = obj.map((stackRoleMappings) => {
115-
return stackRoleMappings(http, { stackRoleMappings: stackRoleMappings })
116-
})
117-
return new StackRoleMappings(http, stackRoleMappingCollection)
118-
}

test/unit/organization-test.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,25 @@ describe('Organization Test', () => {
263263
})
264264
.catch(done)
265265
})
266+
it('should get teams', done => {
267+
const mock = new MockAdapter(Axios)
268+
mock.onGet(`/organizations/UID`).reply(200, {
269+
organization: {
270+
...orgMock
271+
}
272+
})
273+
makeOrganization({ organization: {
274+
...systemUidMock
275+
} })
276+
.fetch()
277+
.then((response) => {
278+
const teams = response.teams()
279+
expect(teams).to.not.equal(undefined)
280+
expect(teams.organizationUid).to.be.equal('UID')
281+
done()
282+
})
283+
.catch(done)
284+
})
266285
})
267286

268287
function makeOrganization (params = {}) {

test/unit/team-test.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { expect } from 'chai'
33
import { describe, it } from 'mocha'
44
import MockAdapter from 'axios-mock-adapter'
55
import { Teams } from '../../lib/organization/teams'
6-
import { systemUidMock, teamsMock, noticeMock } from './mock/objects'
6+
import { systemUidMock, teamsMock, noticeMock, teamUsersMock, stackRoleMappingMock } from './mock/objects'
77

88
describe('Contentstack Team test', () => {
99
it('should get all the teams when correct organization uid is passed', done => {
@@ -70,6 +70,28 @@ describe('Contentstack Team test', () => {
7070
})
7171
.catch(done)
7272
})
73+
it('should fetch all users', done => {
74+
var mock = new MockAdapter(Axios)
75+
mock.onGet(`/organizations/organization_uid/teams/UID/users`).reply(200, teamUsersMock)
76+
makeTeams({ ...systemUidMock }).users().fetchAll()
77+
.then((users) => {
78+
users.items.forEach((user) => {
79+
expect(user.uidId).to.be.not.equal(null)
80+
})
81+
done()
82+
})
83+
.catch(done)
84+
})
85+
it('should fetch all the roles', done => {
86+
var mock = new MockAdapter(Axios)
87+
mock.onGet(`/organizations/organization_uid/teams/UID/stack_role_mappings`).reply(200, stackRoleMappingMock)
88+
makeTeams({ ...systemUidMock }).stackRoleMappings().fetchAll()
89+
.then((response) => {
90+
expect(response.stackRoleMappings).to.be.not.equal(undefined)
91+
done()
92+
})
93+
.catch(done)
94+
})
7395
})
7496

7597
function makeTeams (data = {}) {

test/unit/team-users-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { TeamUsers } from '../../lib/organization/teams/teamUsers'
66
import { teamUsersMock, noticeMock } from './mock/objects'
77

88
describe('Contentstack Team Users test', () => {
9-
it('should query and find all users', done => {
9+
it('should fetch all users', done => {
1010
var mock = new MockAdapter(Axios)
1111
mock.onGet(`/organizations/organization_uid/teams/team_uid/users`).reply(200, teamUsersMock)
1212
makeTeamUsers().fetchAll()

0 commit comments

Comments
 (0)