|
| 1 | +import Axios from 'axios' |
| 2 | +import { expect } from 'chai' |
| 3 | +import { describe, it } from 'mocha' |
| 4 | +import MockAdapter from 'axios-mock-adapter' |
| 5 | +import { StackRoleMappings } from '../../lib/organization/team/stackRoleMapping' |
| 6 | +import { stackRoleMappingMock } from './mock/objects' |
| 7 | + |
| 8 | +describe('Contentstack Team Stack Role Mapping test', () => { |
| 9 | + it('should fetch all the roles', done => { |
| 10 | + var mock = new MockAdapter(Axios) |
| 11 | + mock.onGet(`/organizations/organization_uid/teams/team_uid/stack_role_mappings`).reply(200, stackRoleMappingMock) |
| 12 | + makeStackRoleMapping().fetchAll() |
| 13 | + .then((roles) => { |
| 14 | + console.log('🚀 ~ file: team-stack-role-mapping-test.js:14 ~ .then ~ roles:', roles) |
| 15 | + done() |
| 16 | + }) |
| 17 | + .catch(done) |
| 18 | + }) |
| 19 | + it('should add roles when correct data is passed', done => { |
| 20 | + const addStackRoleMappingMock = { |
| 21 | + stackRoleMapping: { |
| 22 | + stackApiKey: 'stackApiKey', |
| 23 | + roles: [ |
| 24 | + 'role_uid' |
| 25 | + ] |
| 26 | + } |
| 27 | + } |
| 28 | + var mock = new MockAdapter(Axios) |
| 29 | + mock.onPost(`/organizations/organization_uid/teams/team_uid/stack_role_mappings`).reply(200, addStackRoleMappingMock) |
| 30 | + const addRole = { |
| 31 | + stackApiKey: 'stackApiKey', |
| 32 | + roles: [ |
| 33 | + 'role_uid' |
| 34 | + |
| 35 | + ] |
| 36 | + } |
| 37 | + makeStackRoleMapping() |
| 38 | + .add(addRole) |
| 39 | + .then((response) => { |
| 40 | + expect(response.stackRoleMapping).not.to.be.equal(undefined) |
| 41 | + expect(response.stackRoleMapping.roles[0]).to.be.equal(addRole.roles[0]) |
| 42 | + expect(response.stackRoleMapping.stackApiKey).to.be.equal(addRole.stackApiKey) |
| 43 | + done() |
| 44 | + }) |
| 45 | + .catch(done) |
| 46 | + }) |
| 47 | + it('should update stack role mapping when stack api key and updateData are passed', done => { |
| 48 | + const updateStackRoleMappingMock = { |
| 49 | + stackRoleMapping: { |
| 50 | + stackApiKey: 'STACKAPIKEY', |
| 51 | + roles: [ |
| 52 | + 'role_uid1', |
| 53 | + 'role_uid2' |
| 54 | + ] |
| 55 | + } |
| 56 | + } |
| 57 | + var mock = new MockAdapter(Axios) |
| 58 | + mock.onPut(`/organizations/organization_uid/teams/team_uid/stack_role_mappings/STACKAPIKEY`).reply(200, updateStackRoleMappingMock) |
| 59 | + const stackRoleMappings = { |
| 60 | + roles: [ |
| 61 | + 'role_uid1', |
| 62 | + 'role_uid2' |
| 63 | + ] |
| 64 | + } |
| 65 | + makeStackRoleMapping({ stackApiKey: 'STACKAPIKEY' }).update(stackRoleMappings) |
| 66 | + .then((response) => { |
| 67 | + expect(response.stackRoleMapping).not.to.be.equal(undefined) |
| 68 | + expect(response.stackRoleMapping.roles[0]).to.be.equal(stackRoleMappings.roles[0]) |
| 69 | + expect(response.stackRoleMapping.stackApiKey).to.be.equal('STACKAPIKEY') |
| 70 | + done() |
| 71 | + }) |
| 72 | + .catch(done) |
| 73 | + }) |
| 74 | + it('should delete stack role mapping when stack api key is passed', done => { |
| 75 | + var mock = new MockAdapter(Axios) |
| 76 | + mock.onDelete(`/organizations/organization_uid/teams/team_uid/stack_role_mappings/STACKAPIKEY`).reply(200, { status: 204 }) |
| 77 | + makeStackRoleMapping({ stackApiKey: 'STACKAPIKEY' }).delete() |
| 78 | + .then((response) => { |
| 79 | + expect(response.status).to.be.equal(204) |
| 80 | + done() |
| 81 | + }) |
| 82 | + .catch(done) |
| 83 | + }) |
| 84 | +}) |
| 85 | + |
| 86 | +function makeStackRoleMapping (data = {}) { |
| 87 | + return new StackRoleMappings(Axios, { organizationUid: 'organization_uid', teamUid: 'team_uid', ...data }) |
| 88 | +} |
0 commit comments