-
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.
added unit test cases for stack role mapping
- Loading branch information
1 parent
864db84
commit 231711f
Showing
4 changed files
with
105 additions
and
5 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,88 @@ | ||
import Axios from 'axios' | ||
import { expect } from 'chai' | ||
import { describe, it } from 'mocha' | ||
import MockAdapter from 'axios-mock-adapter' | ||
import { StackRoleMappings } from '../../lib/organization/team/stackRoleMapping' | ||
import { stackRoleMappingMock } from './mock/objects' | ||
|
||
describe('Contentstack Team Stack Role Mapping test', () => { | ||
it('should fetch all the roles', done => { | ||
var mock = new MockAdapter(Axios) | ||
mock.onGet(`/organizations/organization_uid/teams/team_uid/stack_role_mappings`).reply(200, stackRoleMappingMock) | ||
makeStackRoleMapping().fetchAll() | ||
.then((roles) => { | ||
console.log('🚀 ~ file: team-stack-role-mapping-test.js:14 ~ .then ~ roles:', roles) | ||
done() | ||
}) | ||
.catch(done) | ||
}) | ||
it('should add roles when correct data is passed', done => { | ||
const addStackRoleMappingMock = { | ||
stackRoleMapping: { | ||
stackApiKey: 'stackApiKey', | ||
roles: [ | ||
'role_uid' | ||
] | ||
} | ||
} | ||
var mock = new MockAdapter(Axios) | ||
mock.onPost(`/organizations/organization_uid/teams/team_uid/stack_role_mappings`).reply(200, addStackRoleMappingMock) | ||
const addRole = { | ||
stackApiKey: 'stackApiKey', | ||
roles: [ | ||
'role_uid' | ||
|
||
] | ||
} | ||
makeStackRoleMapping() | ||
.add(addRole) | ||
.then((response) => { | ||
expect(response.stackRoleMapping).not.to.be.equal(undefined) | ||
expect(response.stackRoleMapping.roles[0]).to.be.equal(addRole.roles[0]) | ||
expect(response.stackRoleMapping.stackApiKey).to.be.equal(addRole.stackApiKey) | ||
done() | ||
}) | ||
.catch(done) | ||
}) | ||
it('should update stack role mapping when stack api key and updateData are passed', done => { | ||
const updateStackRoleMappingMock = { | ||
stackRoleMapping: { | ||
stackApiKey: 'STACKAPIKEY', | ||
roles: [ | ||
'role_uid1', | ||
'role_uid2' | ||
] | ||
} | ||
} | ||
var mock = new MockAdapter(Axios) | ||
mock.onPut(`/organizations/organization_uid/teams/team_uid/stack_role_mappings/STACKAPIKEY`).reply(200, updateStackRoleMappingMock) | ||
const stackRoleMappings = { | ||
roles: [ | ||
'role_uid1', | ||
'role_uid2' | ||
] | ||
} | ||
makeStackRoleMapping({ stackApiKey: 'STACKAPIKEY' }).update(stackRoleMappings) | ||
.then((response) => { | ||
expect(response.stackRoleMapping).not.to.be.equal(undefined) | ||
expect(response.stackRoleMapping.roles[0]).to.be.equal(stackRoleMappings.roles[0]) | ||
expect(response.stackRoleMapping.stackApiKey).to.be.equal('STACKAPIKEY') | ||
done() | ||
}) | ||
.catch(done) | ||
}) | ||
it('should delete stack role mapping when stack api key is passed', done => { | ||
var mock = new MockAdapter(Axios) | ||
mock.onDelete(`/organizations/organization_uid/teams/team_uid/stack_role_mappings/STACKAPIKEY`).reply(200, { status: 204 }) | ||
makeStackRoleMapping({ stackApiKey: 'STACKAPIKEY' }).delete() | ||
.then((response) => { | ||
expect(response.status).to.be.equal(204) | ||
done() | ||
}) | ||
.catch(done) | ||
}) | ||
}) | ||
|
||
function makeStackRoleMapping (data = {}) { | ||
return new StackRoleMappings(Axios, { organizationUid: 'organization_uid', teamUid: 'team_uid', ...data }) | ||
} |
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 |
---|---|---|
|
@@ -5,11 +5,11 @@ import MockAdapter from 'axios-mock-adapter' | |
import { TeamUsers } from '../../lib/organization/team/teamUsers' | ||
import { teamUsersMock, noticeMock } from './mock/objects' | ||
|
||
describe('Contentstack Team test', () => { | ||
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) | ||
makeTeams().query().find() | ||
makeTeamUsers().query().find() | ||
.then((users) => { | ||
users.items.forEach((user) => { | ||
expect(user.uidId).to.be.not.equal(null) | ||
|
@@ -24,7 +24,7 @@ describe('Contentstack Team test', () => { | |
const usersMail = { | ||
emails: ['[email protected]'] | ||
} | ||
makeTeams() | ||
makeTeamUsers() | ||
.add(usersMail) | ||
.then((team) => { | ||
expect(team.userId).to.be.equal('UID') | ||
|
@@ -35,7 +35,7 @@ describe('Contentstack Team test', () => { | |
it('should remove the user when uid is passed', done => { | ||
var mock = new MockAdapter(Axios) | ||
mock.onDelete(`/organizations/organization_uid/teams/team_uid/users/UID`).reply(200, { ...noticeMock }) | ||
makeTeams({ userId: 'UID' }, noticeMock) | ||
makeTeamUsers({ userId: 'UID' }, noticeMock) | ||
.remove() | ||
.then((user) => { | ||
expect(user.notice).to.be.equal(noticeMock.notice) | ||
|
@@ -45,6 +45,6 @@ describe('Contentstack Team test', () => { | |
}) | ||
}) | ||
|
||
function makeTeams (data = {}) { | ||
function makeTeamUsers (data = {}) { | ||
return new TeamUsers(Axios, { organizationUid: 'organization_uid', teamUid: 'team_uid', ...data }) | ||
} |