Skip to content

Commit 8a96319

Browse files
test: update stackrolemapping implementation and api test cases
1 parent 4f1b1c5 commit 8a96319

File tree

3 files changed

+34
-21
lines changed

3 files changed

+34
-21
lines changed

lib/organization/team/stackRoleMapping/index.js

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,17 @@
33
*/
44
import cloneDeep from 'lodash/cloneDeep'
55
import {
6-
create,
7-
update,
86
deleteEntity,
97
fetchAll
108
} from '../../../entity'
9+
import error from '../../../core/contentstackError'
1110

1211
export function StackRoleMappings (http, data) {
13-
console.log("🚀 ~ file: index.js:13 ~ StackRoleMappings ~ data:", data)
1412
const _urlPath = `/organizations/${data.organizationUid}/teams/${data.teamUid}/stack_role_mappings`
1513
if (data && data.stackApiKey) {
1614
Object.assign(this, cloneDeep(data))
1715

18-
this.urlPath = `${_urlPath}/${this.stackApiKey}`
16+
if (this.organizationUid) this.urlPath = `${_urlPath}/${this.stackApiKey}`
1917
/**
2018
* @description The update stackRoleMappings call is used to update the roles.
2119
* @memberof StackRoleMappings
@@ -33,7 +31,16 @@ export function StackRoleMappings (http, data) {
3331
* client.organization('organizationUid').teams('teamUid').stackRoleMappings('stackApiKey').update(updateRoles)
3432
* .then((response) => console.log(response))
3533
*/
36-
this.update = update(http, 'stackRoleMapping')
34+
this.update = async (updateData, params = {}) => {
35+
try {
36+
const response = await http.put(this.urlPath, updateData, { params })
37+
if (response.data) {
38+
return response.data
39+
}
40+
} catch (err) {
41+
throw error(err)
42+
}
43+
}
3744

3845
/**
3946
* @description The delete stackRoleMappings call is used to delete the roles.
@@ -49,7 +56,6 @@ export function StackRoleMappings (http, data) {
4956
*/
5057
this.delete = deleteEntity(http)
5158
} else {
52-
// const _urlPath = `/organizations/${data.organizationUid}/teams/${data.teamUid}/stack_role_mappings`
5359
this.urlPath = _urlPath
5460
/**
5561
* @description The add stackRoleMappings call is used to add the roles.
@@ -69,7 +75,16 @@ export function StackRoleMappings (http, data) {
6975
* client.organization('organizationUid').teams('teamUid').stackRoleMappings().add(addRole)
7076
* .then((response) => console.log(response))
7177
*/
72-
this.add = create({ http })
78+
this.add = async (updateData, params = {}) => {
79+
try {
80+
const response = await http.post(this.urlPath, updateData, { params })
81+
if (response.data) {
82+
return response.data
83+
}
84+
} catch (err) {
85+
throw error(err)
86+
}
87+
}
7388

7489
/**
7590
* @description The fetchAll stackRoleMappings call is used to fetchAll the roles.
@@ -87,9 +102,9 @@ export function StackRoleMappings (http, data) {
87102
}
88103
}
89104
export function stackRoleMappingsCollection (http, data) {
90-
const obj = cloneDeep(data.stackRoleMappings) || []
105+
const obj = cloneDeep(data) || []
91106
const stackRoleMappingCollection = obj.map((stackRoleMappings) => {
92-
return new StackRoleMappings(http, { stackRoleMappings: stackRoleMappings })
107+
return stackRoleMappings(http, { stackRoleMappings: stackRoleMappings })
93108
})
94-
return stackRoleMappingCollection
109+
return new StackRoleMappings(http, stackRoleMappingCollection)
95110
}

test/api/team-stack-role-mapping-test.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,21 @@ describe('Teams API Test', () => {
1414
const user = jsonReader('loggedinuser.json')
1515
client = contentstackClient(user.authtoken)
1616
})
17-
it('should fetch all stackRoleMappings', (done) => {
18-
makestackRoleMappings(organizationUid, teamUid).fetchAll().then((response) => {
19-
console.log('🚀 ~ file: team-stack-role-mapping-test.js:19 ~ makestackRoleMappings ~ response:', response)
20-
response.items.forEach((stackRoleMapping) => {
21-
console.log(stackRoleMapping)
17+
it('should fetch all stackRoleMappings', async () => {
18+
try {
19+
makestackRoleMappings(organizationUid, teamUid).fetchAll().then((response) => {
20+
console.log('🚀 ~ file: team-stack-role-mapping-test.js:19 ~ makestackRoleMappings ~ response:', response.stackRoleMappings[0].roles)
2221
})
23-
expect(response).to.be.not.equal(null)
24-
done()
25-
})
26-
.catch(done)
22+
} catch (err) {
23+
console.log("🚀 ~ file: team-stack-role-mapping-test.js:21 ~ it.only ~ err:", err)
24+
}
2725
})
2826
it('should add roles', async () => {
2927
try {
3028
const stackRoleMappings = {
3129
stackApiKey: 'stackApiKey',
3230
roles: [
3331
'role_uid'
34-
3532
]
3633
}
3734
await makestackRoleMappings(organizationUid, teamUid).add(stackRoleMappings).then((response) => {
@@ -72,3 +69,5 @@ function makestackRoleMappings (organizationUid, teamUid, stackApiKey = null) {
7269
}
7370

7471
// delete done
72+
// update done
73+
// add done

test/api/team-users-test.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ describe('Teams API Test', () => {
2525
})
2626
it('should remove the user when uid is passed', done => {
2727
makeUsers(organizationUid, teamUid, userId).remove().then((response) => {
28-
expect(response).to.be.equal(null)
2928
expect(response.status).to.be.equal(204)
3029
done()
3130
})

0 commit comments

Comments
 (0)