diff --git a/src/commands/integration-mappings/teams/create.js b/src/commands/integration-mappings/teams/create.js new file mode 100644 index 00000000..a1d4ef2a --- /dev/null +++ b/src/commands/integration-mappings/teams/create.js @@ -0,0 +1,66 @@ +'use strict'; + +const BoxCommand = require('../../../box-command'); +const { Args } = require('@oclif/core'); + +class IntegrationMappingsTeamsCreateCommand extends BoxCommand { + async run() { + const { args } = await this.parse(IntegrationMappingsTeamsCreateCommand); + let body = {}; + body.boxItem = { + type: 'folder', + id: args.boxItemID + }; + body.partnerItem = { + type: args.partnerItemType, + id: args.partnerItemID, + teamId: args.partnerItemTeamID, + tenantId: args.partnerItemTenantID + }; + + let integrationMapping = await this.tsClient.integrationMappings.createTeamsIntegrationMapping(body); + delete integrationMapping.rawData; + await this.output(integrationMapping); + } +} + +IntegrationMappingsTeamsCreateCommand.description = 'Create Teams integration mapping'; +IntegrationMappingsTeamsCreateCommand.examples = [ + 'box integration-mappings:teams:create 123 19%ABCD-Avgfggkggyftdtfgghjhkhkhh%40thread:tacv2 hjgjgjg-bhhj-564a-b643-hghgj685u abcd-defg-1235-7890', +]; +IntegrationMappingsTeamsCreateCommand._endpoint = 'post_integration_mappings_teams'; + +IntegrationMappingsTeamsCreateCommand.args = { + boxItemID: Args.string({ + name: 'boxItemID', + required: true, + hidden: false, + description: 'ID of the mapped folder' + }), + partnerItemID: Args.string({ + name: 'partnerItemID', + required: true, + hidden: false, + description: 'ID of the mapped item' + }), + partnerItemType: Args.string({ + name: 'partnerItemType', + required: true, + hidden: false, + description: 'Type of the mapped item, value is one of: channel, team' + }), + partnerItemTeamID: Args.string({ + name: 'partnerItemTeamID', + required: true, + hidden: false, + description: 'ID of the team that is registered with Microsoft Teams' + }), + partnerItemTenantID: Args.string({ + name: 'partnerItemTenantID', + required: true, + hidden: false, + description: 'ID of the tenant that is registered with Microsoft Teams' + }) +}; + +module.exports = IntegrationMappingsTeamsCreateCommand; diff --git a/src/commands/integration-mappings/teams/delete.js b/src/commands/integration-mappings/teams/delete.js new file mode 100644 index 00000000..3f814b55 --- /dev/null +++ b/src/commands/integration-mappings/teams/delete.js @@ -0,0 +1,32 @@ +'use strict'; + +const { Args } = require('@oclif/core'); +const BoxCommand = require('../../../box-command'); + +class IntegrationMappingsTeamsDeleteCommand extends BoxCommand { + async run() { + const { args } = await this.parse(IntegrationMappingsTeamsDeleteCommand); + + await this.tsClient.integrationMappings.deleteTeamsIntegrationMappingById(args.id); + this.info(`Deleted Teams integration mapping ${args.id}`); + } +} + +IntegrationMappingsTeamsDeleteCommand.description = 'Delete Teams integration mapping'; +IntegrationMappingsTeamsDeleteCommand.examples = ['box integration-mappings:teams:delete 123']; +IntegrationMappingsTeamsDeleteCommand._endpoint = 'delete_integration_mappings_teams_id'; + +IntegrationMappingsTeamsDeleteCommand.flags = { + ...BoxCommand.flags +}; + +IntegrationMappingsTeamsDeleteCommand.args = { + id: Args.string({ + name: 'id', + required: true, + hidden: false, + description: 'ID of the integration mapping', + }), +}; + +module.exports = IntegrationMappingsTeamsDeleteCommand; diff --git a/src/commands/integration-mappings/teams/index.js b/src/commands/integration-mappings/teams/index.js new file mode 100644 index 00000000..58f1765a --- /dev/null +++ b/src/commands/integration-mappings/teams/index.js @@ -0,0 +1,61 @@ +'use strict'; + +const BoxCommand = require('../../../box-command'); +const { Flags } = require('@oclif/core'); +const PaginationUtils = require('../../../pagination-utils'); + +class IntegrationMappingsTeamsListCommand extends BoxCommand { + async run() { + const { flags } = await this.parse(IntegrationMappingsTeamsListCommand); + let options = {}; + + if (flags['partner-item-id']) { + options.partnerItemId = flags['partner-item-id']; + } + if (flags['partner-item-type']) { + options.partnerItemType = flags['partner-item-type']; + } + if (flags['box-item-id']) { + options.boxItemId = flags['box-item-id']; + } + if (flags['box-item-type']) { + options.boxItemType = flags['box-item-type']; + } + + let teamsIntegrationMappings = await this.tsClient.integrationMappings.getTeamsIntegrationMapping(options); + delete teamsIntegrationMappings.rawData; + await this.output(teamsIntegrationMappings); + } +} + +IntegrationMappingsTeamsListCommand.aliases = [ 'integration-mappings:teams:list' ]; + +IntegrationMappingsTeamsListCommand.description = 'List Teams integration mappings'; +IntegrationMappingsTeamsListCommand.examples = [ + 'box integration-mappings:teams --partner-item-id 123 --partner-item-type channel', + 'box integration-mappings:teams --box-item-id 456 --box-item-type folder' +]; +IntegrationMappingsTeamsListCommand._endpoint = 'get_integration_mappings_teams'; + +IntegrationMappingsTeamsListCommand.flags = { + ...BoxCommand.flags, + ...PaginationUtils.flags, + 'partner-item-id': Flags.string({ + hidden: false, + description: 'ID of the mapped item, for which the mapping should be returned', + }), + 'partner-item-type': Flags.string({ + hidden: false, + description: 'Mapped item type, for which the mapping should be returned, value is one of: channel, team', + }), + 'box-item-id': Flags.string({ + hidden: false, + description: 'Box item ID, for which the mappings should be returned', + }), + 'box-item-type': Flags.string({ + hidden: false, + description: 'Box item type, for which the mappings should be returned, value is one of: folder', + }) +}; + +module.exports = IntegrationMappingsTeamsListCommand; diff --git a/src/commands/integration-mappings/teams/update.js b/src/commands/integration-mappings/teams/update.js new file mode 100644 index 00000000..5fc6cae9 --- /dev/null +++ b/src/commands/integration-mappings/teams/update.js @@ -0,0 +1,46 @@ +'use strict'; + +const BoxCommand = require('../../../box-command'); +const { Flags, Args } = require('@oclif/core'); + +class IntegrationMappingsTeamsUpdateCommand extends BoxCommand { + async run() { + const { flags, args } = await this.parse(IntegrationMappingsTeamsUpdateCommand); + let body = {}; + + if (flags['box-item-id']) { + body.boxItem = { + id: flags['box-item-id'], + type: 'folder' + }; + } + + let integrationMapping = await this.tsClient.integrationMappings.updateTeamsIntegrationMappingById(args.id, { + requestBody: body + }); + delete integrationMapping.rawData; + await this.output(integrationMapping); + } +} + +IntegrationMappingsTeamsUpdateCommand.description = 'Update Teams integration mapping'; +IntegrationMappingsTeamsUpdateCommand.examples = ['box integration-mappings:teams:update 123 --box-item-id 789']; +IntegrationMappingsTeamsUpdateCommand._endpoint = 'put_integration_mappings_teams_id'; + +IntegrationMappingsTeamsUpdateCommand.flags = { + ...BoxCommand.flags, + 'box-item-id': Flags.string({ + description: 'ID of the mapped folder', + }), +}; + +IntegrationMappingsTeamsUpdateCommand.args = { + id: Args.string({ + name: 'id', + required: true, + hidden: false, + description: 'ID of an integration mapping', + }), +}; + +module.exports = IntegrationMappingsTeamsUpdateCommand; diff --git a/test/commands/integration-mappings.test.js b/test/commands/integration-mappings.test.js index 044a3356..cc986aef 100644 --- a/test/commands/integration-mappings.test.js +++ b/test/commands/integration-mappings.test.js @@ -8,19 +8,32 @@ const os = require('os'); describe('Integration Mappings', () => { describe('integration-mappings:slack:list', () => { let partnerItemId = '1234', - fixture = getFixture('integration-mappings/get_integration_mappings_slack_page_1'), - fixture2 = getFixture('integration-mappings/get_integration_mappings_slack_page_2'), + fixture = getFixture( + 'integration-mappings/get_integration_mappings_slack_page_1', + ), + fixture2 = getFixture( + 'integration-mappings/get_integration_mappings_slack_page_2', + ), jsonOutput = getFixture('output/integration_mappings_slack_get_json.txt'); test - .nock(TEST_API_ROOT, api => + .nock(TEST_API_ROOT, (api) => api .get('/2.0/integration_mappings/slack') - .query({partner_item_id: partnerItemId, is_manually_created: true, limit: 1000 }) + .query({ + partner_item_id: partnerItemId, + is_manually_created: true, + limit: 1000, + }) .reply(200, fixture) .get('/2.0/integration_mappings/slack') - .query({partner_item_id: partnerItemId, is_manually_created: true, limit: 1000, marker: 'ZDFARAFD' }) - .reply(200, fixture2) + .query({ + partner_item_id: partnerItemId, + is_manually_created: true, + limit: 1000, + marker: 'ZDFARAFD', + }) + .reply(200, fixture2), ) .stdout() .command([ @@ -28,9 +41,9 @@ describe('Integration Mappings', () => { `--partner-item-id=${partnerItemId}`, '--manually-created', '--json', - '--token=test' + '--token=test', ]) - .it('should list Slack integration mappings', ctx => { + .it('should list Slack integration mappings', (ctx) => { assert.equal(ctx.stdout, jsonOutput); }); }); @@ -39,25 +52,28 @@ describe('Integration Mappings', () => { let boxItemId = '23456', channelId = 'C12378991223', slackOrgId = 'E1234567', - fixture = getFixture('integration-mappings/post_integration_mappings_slack'); + fixture = getFixture( + 'integration-mappings/post_integration_mappings_slack', + ); test - .nock(TEST_API_ROOT, api => api - .post('/2.0/integration_mappings/slack', { - box_item: { - id: boxItemId, - type: 'folder' - }, - partner_item: { - type: 'channel', - id: channelId, - slack_org_id: slackOrgId - }, - options: { - is_access_management_disabled: true, - } - }) - .reply(200, fixture) + .nock(TEST_API_ROOT, (api) => + api + .post('/2.0/integration_mappings/slack', { + box_item: { + id: boxItemId, + type: 'folder', + }, + partner_item: { + type: 'channel', + id: channelId, + slack_org_id: slackOrgId, + }, + options: { + is_access_management_disabled: true, + }, + }) + .reply(200, fixture), ) .stdout() .command([ @@ -69,28 +85,31 @@ describe('Integration Mappings', () => { '--json', '--token=test', ]) - .it('should create a Slack integration mapping', ctx => { + .it('should create a Slack integration mapping', (ctx) => { assert.equal(ctx.stdout, fixture); }); }); describe('integration-mappings:slack:update', () => { let integrationMappingId = '12345', - boxItemId = '7890', - fixture = getFixture('integration-mappings/put_integration_mappings_slack_id'); + boxItemId = '7890', + fixture = getFixture( + 'integration-mappings/put_integration_mappings_slack_id', + ); test - .nock(TEST_API_ROOT, api => api - .put(`/2.0/integration_mappings/slack/${integrationMappingId}`, { - box_item: { - id: boxItemId, - type: 'folder' - }, - options: { - is_access_management_disabled: false, - } - }) - .reply(200, fixture) + .nock(TEST_API_ROOT, (api) => + api + .put(`/2.0/integration_mappings/slack/${integrationMappingId}`, { + box_item: { + id: boxItemId, + type: 'folder', + }, + options: { + is_access_management_disabled: false, + }, + }) + .reply(200, fixture), ) .stdout() .command([ @@ -101,7 +120,7 @@ describe('Integration Mappings', () => { '--json', '--token=test', ]) - .it('should update a Slack integration mapping', ctx => { + .it('should update a Slack integration mapping', (ctx) => { assert.equal(ctx.stdout, fixture); }); }); @@ -110,18 +129,234 @@ describe('Integration Mappings', () => { let integrationMappingId = '12345'; test - .nock(TEST_API_ROOT, api => api - .delete(`/2.0/integration_mappings/slack/${integrationMappingId}`) - .reply(204) + .nock(TEST_API_ROOT, (api) => + api + .delete(`/2.0/integration_mappings/slack/${integrationMappingId}`) + .reply(204), ) .stderr() .command([ 'integration-mappings:slack:delete', integrationMappingId, - '--token=test' + '--token=test', + ]) + .it('should delete a Slack integration mapping', (ctx) => { + assert.equal( + ctx.stderr, + `Deleted Slack integration mapping ${integrationMappingId}${os.EOL}`, + ); + }); + }); + + describe('integration-mappings:teams:list', () => { + let partnerItemId = '1234', + partnerItemType = 'channel', + boxItemId = '1234', + boxItemType = 'folder', + fixture = getFixture( + 'integration-mappings/get_integration_mappings_teams', + ), + expectedResult = { + entries: [ + { + id: '12345', + type: 'integration_mapping', + boxItem: { + id: '42037322', + type: 'folder', + }, + createdAt: { + value: '2012-12-12T18:53:43.000Z', + }, + integrationType: 'teams', + isOverriddenByManualMapping: true, + modifiedAt: { + value: '2012-12-12T18:53:43.000Z', + }, + partnerItem: { + id: '19%3ABCD-Avgfggkggyftdtfgghjhkhkhh%40thread:tacv2', + tenantId: 'E1234567', + type: 'channel', + }, + }, + ], + }; + + test + .nock(TEST_API_ROOT, (api) => + api + .get('/2.0/integration_mappings/teams') + .query({ + partner_item_id: partnerItemId, + partner_item_type: partnerItemType, + box_item_id: boxItemId, + box_item_type: boxItemType, + }) + .reply(200, fixture, { + 'Content-Type': 'application/json', + }), + ) + .stderr() + .stdout() + .command([ + 'integration-mappings:teams:list', + `--partner-item-id=${partnerItemId}`, + `--partner-item-type=${partnerItemType}`, + `--box-item-id=${boxItemId}`, + `--box-item-type=${boxItemType}`, + '--json', + '--token=test', + ]) + .it('should list Teams integration mappings', (ctx) => { + assert.equal(ctx.stderr, ''); + assert.deepEqual(JSON.parse(ctx.stdout), expectedResult); + }); + }); + + describe('integration-mappings:teams:create', () => { + let partnerItemId = '1234', + partnerItemType = 'channel', + boxItemId = '1234', + partnerItemTeamId = 'hjgjgjg-bhhj-564a-b643-hghgj685u', + partnerItemTenantId = 'E1234567', + fixture = getFixture( + 'integration-mappings/post_integration_mappings_teams', + ), + expectedResult = { + id: '12345', + type: 'integration_mapping', + boxItem: { + id: '42037322', + type: 'folder', + }, + createdAt: { + value: '2012-12-12T18:53:43.000Z', + }, + integrationType: 'teams', + isOverriddenByManualMapping: true, + modifiedAt: { + value: '2012-12-12T18:53:43.000Z', + }, + partnerItem: { + id: '19%3ABCD-Avgfggkggyftdtfgghjhkhkhh%40thread:tacv2', + tenantId: 'E1234567', + type: 'channel', + }, + }; + + test + .nock(TEST_API_ROOT, (api) => + api + .post('/2.0/integration_mappings/teams', { + partner_item: { + type: 'channel', + id: partnerItemId, + tenant_id: 'E1234567', + team_id: partnerItemTeamId, + }, + box_item: { + type: 'folder', + id: boxItemId, + }, + }) + .reply(200, fixture, { + 'Content-Type': 'application/json', + }), + ) + .stderr() + .stdout() + .command([ + 'integration-mappings:teams:create', + boxItemId, + partnerItemId, + partnerItemType, + partnerItemTeamId, + partnerItemTenantId, + '--json', + '--token=test', + ]) + .it('should create a Teams integration mapping', (ctx) => { + assert.equal(ctx.stderr, ''); + assert.deepEqual(JSON.parse(ctx.stdout), expectedResult); + }); + }); + + describe('integration-mappings:teams:update', () => { + let integrationMappingId = '12345', + boxItemId = '7890', + fixture = getFixture( + 'integration-mappings/put_integration_mappings_teams_id', + ), + expectedResult = { + id: '12345', + type: 'integration_mapping', + boxItem: { + id: '7890', + type: 'folder', + }, + createdAt: { + value: '2012-12-12T18:53:43.000Z', + }, + integrationType: 'teams', + isOverriddenByManualMapping: true, + modifiedAt: { + value: '2012-12-12T18:53:43.000Z', + }, + partnerItem: { + id: '19%3ABCD-Avgfggkggyftdtfgghjhkhkhh%40thread:tacv2', + tenantId: 'E1234567', + type: 'channel', + }, + }; + + test + .nock(TEST_API_ROOT, (api) => + api + .put(`/2.0/integration_mappings/teams/${integrationMappingId}`, { + box_item: { + id: boxItemId, + type: 'folder', + }, + }) + .reply(200, fixture, { + 'Content-Type': 'application/json', + }), + ) + .stderr() + .stdout() + .command([ + 'integration-mappings:teams:update', + integrationMappingId, + `--box-item-id=${boxItemId}`, + '--json', + '--token=test', + ]) + .it('should update a Teams integration mapping', (ctx) => { + assert.equal(ctx.stderr, ''); + assert.deepEqual(JSON.parse(ctx.stdout), expectedResult); + }); + }); + + describe('integration-mappings:teams:delete', () => { + let integrationMappingId = '12345'; + + test + .nock(TEST_API_ROOT, (api) => + api + .delete(`/2.0/integration_mappings/teams/${integrationMappingId}`) + .reply(204), + ) + .stderr() + .command([ + 'integration-mappings:teams:delete', + integrationMappingId, + '--token=test', ]) - .it('should delete a Slack integration mapping', ctx => { - assert.equal(ctx.stderr, `Deleted Slack integration mapping ${integrationMappingId}${os.EOL}`); + .it('should delete a Teams integration mapping', (ctx) => { + assert.equal( + ctx.stderr, + `Deleted Teams integration mapping ${integrationMappingId}${os.EOL}`, + ); }); }); }); diff --git a/test/fixtures/integration-mappings/get_integration_mappings_teams.json b/test/fixtures/integration-mappings/get_integration_mappings_teams.json new file mode 100644 index 00000000..cdeda01b --- /dev/null +++ b/test/fixtures/integration-mappings/get_integration_mappings_teams.json @@ -0,0 +1,22 @@ +{ + "entries": [ + { + "id": "12345", + "type": "integration_mapping", + "box_item": { + "id": "42037322", + "type": "folder" + }, + "created_at": "2012-12-12T10:53:43-08:00", + "integration_type": "teams", + "is_overridden_by_manual_mapping": true, + "modified_at": "2012-12-12T10:53:43-08:00", + "partner_item": { + "id": "19%3ABCD-Avgfggkggyftdtfgghjhkhkhh%40thread:tacv2", + "team_id": "hjgjgjg-bhhj-564a-b643-hghgj685u", + "tenant_id": "E1234567", + "type": "channel" + } + } + ] +} diff --git a/test/fixtures/integration-mappings/post_integration_mappings_teams.json b/test/fixtures/integration-mappings/post_integration_mappings_teams.json new file mode 100644 index 00000000..7992b877 --- /dev/null +++ b/test/fixtures/integration-mappings/post_integration_mappings_teams.json @@ -0,0 +1,18 @@ +{ + "id": "12345", + "type": "integration_mapping", + "box_item": { + "id": "42037322", + "type": "folder" + }, + "created_at": "2012-12-12T10:53:43-08:00", + "integration_type": "teams", + "is_overridden_by_manual_mapping": true, + "modified_at": "2012-12-12T10:53:43-08:00", + "partner_item": { + "id": "19%3ABCD-Avgfggkggyftdtfgghjhkhkhh%40thread:tacv2", + "type": "channel", + "team_id": "hjgjgjg-bhhj-564a-b643-hghgj685u", + "tenant_id": "E1234567" + } + } \ No newline at end of file diff --git a/test/fixtures/integration-mappings/put_integration_mappings_teams_id.json b/test/fixtures/integration-mappings/put_integration_mappings_teams_id.json new file mode 100644 index 00000000..d0ee2029 --- /dev/null +++ b/test/fixtures/integration-mappings/put_integration_mappings_teams_id.json @@ -0,0 +1,18 @@ +{ + "id": "12345", + "type": "integration_mapping", + "box_item": { + "id": "7890", + "type": "folder" + }, + "created_at": "2012-12-12T10:53:43-08:00", + "integration_type": "teams", + "is_overridden_by_manual_mapping": true, + "modified_at": "2012-12-12T10:53:43-08:00", + "partner_item": { + "id": "19%3ABCD-Avgfggkggyftdtfgghjhkhkhh%40thread:tacv2", + "type": "channel", + "team_id": "hjgjgjg-bhhj-564a-b643-hghgj685u", + "tenant_id": "E1234567" + } + } \ No newline at end of file