-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ✨ stackrolemapping implementation and api test cases
- Loading branch information
1 parent
fec3852
commit 99fc8c1
Showing
6 changed files
with
183 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/** | ||
* @namespace StackRoleMappings | ||
*/ | ||
import cloneDeep from 'lodash/cloneDeep' | ||
import { | ||
create, | ||
update, | ||
deleteEntity, | ||
fetchAll | ||
} from '../../../entity' | ||
|
||
export function StackRoleMappings (http, data) { | ||
console.log("🚀 ~ file: index.js:13 ~ StackRoleMappings ~ data:", data) | ||
const _urlPath = `/organizations/${data.organizationUid}/teams/${data.teamUid}/stack_role_mappings` | ||
if (data && data.stackApiKey) { | ||
Object.assign(this, cloneDeep(data)) | ||
|
||
this.urlPath = `${_urlPath}/${this.stackApiKey}` | ||
/** | ||
* @description The update stackRoleMappings call is used to update the roles. | ||
* @memberof StackRoleMappings | ||
* @func update | ||
* @returns {Promise<StackRoleMappings.StackRoleMappings>} Response Object. | ||
* @example | ||
* import * as contentstack from '@contentstack/management' | ||
* const client = contentstack.client() | ||
* const updateRoles = { | ||
* roles: [ | ||
* 'roles_uid1', | ||
* 'roles_uid2' | ||
* ] | ||
* } | ||
* client.organization('organizationUid').teams('teamUid').stackRoleMappings('stackApiKey').update(updateRoles) | ||
* .then((response) => console.log(response)) | ||
*/ | ||
this.update = update(http, 'stackRoleMapping') | ||
|
||
/** | ||
* @description The delete stackRoleMappings call is used to delete the roles. | ||
* @memberof StackRoleMappings | ||
* @func delete | ||
* @returns {Promise<StackRoleMappings.StackRoleMappings>} Response Object. | ||
* @example | ||
* import * as contentstack from '@contentstack/management' | ||
* const client = contentstack.client() | ||
* | ||
* client.organization('organizationUid').teams('teamUid').stackRoleMappings('stackApiKey').delete() | ||
* .then((response) => console.log(response)) | ||
*/ | ||
this.delete = deleteEntity(http) | ||
} else { | ||
// const _urlPath = `/organizations/${data.organizationUid}/teams/${data.teamUid}/stack_role_mappings` | ||
this.urlPath = _urlPath | ||
/** | ||
* @description The add stackRoleMappings call is used to add the roles. | ||
* @memberof StackRoleMappings | ||
* @func add | ||
* @returns {Promise<StackRoleMappings.StackRoleMappings>} Response Object. | ||
* @example | ||
* import * as contentstack from '@contentstack/management' | ||
* const client = contentstack.client() | ||
* | ||
* const addRole = { | ||
* 'stackApiKey: 'stackApiKey', | ||
* 'roles': [ | ||
* 'role_uid' | ||
* ] | ||
* } | ||
* client.organization('organizationUid').teams('teamUid').stackRoleMappings().add(addRole) | ||
* .then((response) => console.log(response)) | ||
*/ | ||
this.add = create({ http }) | ||
|
||
/** | ||
* @description The fetchAll stackRoleMappings call is used to fetchAll the roles. | ||
* @memberof StackRoleMappings | ||
* @func fetchAll | ||
* @returns {Promise<StackRoleMappings.StackRoleMappings>} Response Object. | ||
* @example | ||
* import * as contentstack from '@contentstack/management' | ||
* const client = contentstack.client() | ||
* | ||
* client.organization('organizationUid').teams('teamUid').stackRoleMappings().fetchAll | ||
* .then((response) => console.log(response)) | ||
*/ | ||
this.fetchAll = fetchAll(http, stackRoleMappingsCollection) | ||
} | ||
} | ||
export function stackRoleMappingsCollection (http, data) { | ||
const obj = cloneDeep(data.stackRoleMappings) || [] | ||
const stackRoleMappingCollection = obj.map((stackRoleMappings) => { | ||
return new StackRoleMappings(http, { stackRoleMappings: stackRoleMappings }) | ||
}) | ||
return stackRoleMappingCollection | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { describe, it, beforeEach } from 'mocha' | ||
import { expect } from 'chai' | ||
import { jsonReader } from '../utility/fileOperations/readwrite' | ||
import { contentstackClient } from '../utility/ContentstackClient.js' | ||
|
||
let client = {} | ||
|
||
const stackApiKey = 'stackApiKey' | ||
const organizationUid = 'organizationUid' | ||
const teamUid = 'teamUid' | ||
|
||
describe('Teams API Test', () => { | ||
beforeEach(() => { | ||
const user = jsonReader('loggedinuser.json') | ||
client = contentstackClient(user.authtoken) | ||
}) | ||
it('should fetch all stackRoleMappings', (done) => { | ||
makestackRoleMappings(organizationUid, teamUid).fetchAll().then((response) => { | ||
console.log('🚀 ~ file: team-stack-role-mapping-test.js:19 ~ makestackRoleMappings ~ response:', response) | ||
response.items.forEach((stackRoleMapping) => { | ||
console.log(stackRoleMapping) | ||
}) | ||
expect(response).to.be.not.equal(null) | ||
done() | ||
}) | ||
.catch(done) | ||
}) | ||
it('should add roles', async () => { | ||
try { | ||
const stackRoleMappings = { | ||
stackApiKey: 'stackApiKey', | ||
roles: [ | ||
'role_uid' | ||
|
||
] | ||
} | ||
await makestackRoleMappings(organizationUid, teamUid).add(stackRoleMappings).then((response) => { | ||
console.log('🚀 ~ file: team-stack-role-mapping-test.js:36 ~ awaitmakestackRoleMappings ~ response:', response) | ||
}) | ||
} catch (err) { | ||
console.log(err) | ||
} | ||
}) | ||
it('should update roles', async () => { | ||
try { | ||
const stackRoleMappings = { | ||
roles: [ | ||
'role_uid1', | ||
'role_uid2' | ||
] | ||
} | ||
await makestackRoleMappings(organizationUid, teamUid, stackApiKey).update(stackRoleMappings).then((response) => { | ||
console.log('🚀 ~ file: team-stack-role-mapping-test.js:31 ~ makestackRoleMappings ~ response:', response) | ||
}) | ||
} catch (err) { | ||
console.log(err.errors) | ||
} | ||
}) | ||
it('should delete roles', async () => { | ||
try { | ||
await makestackRoleMappings(organizationUid, teamUid, stackApiKey).delete().then((response) => { | ||
console.log('🚀 ~ file: team-stack-role-mapping-test.js:31 ~ makestackRoleMappings ~ response:', response) | ||
}) | ||
} catch (err) { | ||
console.log(err.errors) | ||
} | ||
}) | ||
}) | ||
|
||
function makestackRoleMappings (organizationUid, teamUid, stackApiKey = null) { | ||
return client.organization(organizationUid).teams(teamUid).stackRoleMappings(stackApiKey) | ||
} | ||
|
||
// delete done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ describe('Teams API Test', () => { | |
const user = jsonReader('loggedinuser.json') | ||
client = contentstackClient(user.authtoken) | ||
}) | ||
it.only('should add the user when user\'s mail is passed', done => { | ||
it('should add the user when user\'s mail is passed', done => { | ||
const usersMail = { | ||
emails: ['[email protected]'] | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters