Skip to content

Commit

Permalink
Fix issue #1566 Add admin.conversations.bulk{Archive|Delete|Move} API…
Browse files Browse the repository at this point in the history
… method support
  • Loading branch information
hello-ashleyintech committed Dec 19, 2022
1 parent f428ba0 commit 473e319
Show file tree
Hide file tree
Showing 2 changed files with 123 additions and 0 deletions.
2 changes: 2 additions & 0 deletions prod-server-integration-tests/README.md
Expand Up @@ -17,6 +17,8 @@ export SLACK_SDK_TEST_USER_TOKEN=xoxp-
export SLACK_SDK_TEST_GRID_WORKSPACE_ADMIN_USER_TOKEN=xoxp-
# org-level admin user's token
export SLACK_SDK_TEST_GRID_ORG_ADMIN_USER_TOKEN=xoxp-
# admin user's token for a secondary workspace in an Enterprise Grid org (must be in same org as workspace for SLACK_SDK_TEST_GRID_WORKSPACE_ADMIN_USER_TOKEN, but a different workspace) - required for admin.conversations.bulkMove test
export SLACK_SDK_TEST_GRID_WORKSPACE_TEAM_ID=T0123456789

npm test
```
Expand Down
121 changes: 121 additions & 0 deletions prod-server-integration-tests/test/admin-web-api-conversations-bulk.js
@@ -0,0 +1,121 @@
// npx mocha --timeout 10000 test/admin-web-api-custom-retention.js
// tail -f logs/console.log | jq
require('mocha');
const { assert } = require('chai');
const { WebClient } = require('@slack/web-api');

const winston = require('winston');
const logger = winston.createLogger({
level: 'debug',
transports: [
new winston.transports.File({ filename: 'logs/console.log' }),
],
});

// Note: to run this test, you must have 2 workspaces on your Enterprise Grid and
// you must have the SLACK_SDK_TEST_GRID_WORKSPACE_TEAM_ID environment variable configured.
describe('admin.* Web APIs', function () {
// admin user's token for a workspace in an Enterprise Grid org
const teamAdminClient = new WebClient(process.env.SLACK_SDK_TEST_GRID_WORKSPACE_ADMIN_USER_TOKEN, { logger, });
// admin user's team ID for a secondary workspace in an Enterprise Grid org
// (must be in same org as workspace for teamAdminClient, but a different workspace)
const secondaryTeamId = process.env.SLACK_SDK_TEST_GRID_WORKSPACE_TEAM_ID;
// org-level admin user's token
const orgAdminClient = new WebClient(process.env.SLACK_SDK_TEST_GRID_ORG_ADMIN_USER_TOKEN, { logger, });

describe('admin.conversations.bulk{Archive|Move|Delete}', function () {
// Test bulkArchive
it('should bulk archive conversations using admin.conversations.bulkArchive', async function () {
const testChannel = await teamAdminClient.conversations.create({
name: `test-bulk-archive-${new Date().getTime()}`,
});
const channelId = testChannel.channel.id;
let archiving = null;
let isInProgress = false;

while (archiving === null || isInProgress) {
try {
archiving = await orgAdminClient.admin.conversations.bulkArchive({
channel_ids: [channelId]
}).catch((error) => {
if (error.data.error === 'action_already_in_progress') {
isInProgress = true;
new Promise(r => setTimeout(r, 3000));
} else {
throw error;
}
});

if (archiving && archiving.ok) {
isInProgress = false;
}
} finally {
await orgAdminClient.admin.conversations.delete({
channel_id: channelId,
});
}
}

logger.info(archiving);
assert.isDefined(archiving.bulk_action_id);
assert.isUndefined(archiving.error);
});
it('should bulk delete conversations using admin.conversations.bulkDelete', async function () {
const testChannel = await teamAdminClient.conversations.create({
name: `test-bulk-delete-${new Date().getTime()}`,
});
const channelId = testChannel.channel.id;
let removing = null;
let isInProgress = false;

while (removing === null || isInProgress) {
removing = await orgAdminClient.admin.conversations.bulkDelete({
channel_ids: [channelId]
}).catch((error) => {
if (error.data.error === 'action_already_in_progress') {
isInProgress = true;
new Promise(r => setTimeout(r, 3000));
} else {
throw error;
}
});

if (removing && removing.ok) {
isInProgress = false;
}
}
logger.info(removing);
assert.isDefined(removing.bulk_action_id);
assert.isUndefined(removing.error);
});
it('should bulk move conversations using admin.conversations.bulkMove', async function () {
const testChannel = await teamAdminClient.conversations.create({
name: `test-bulk-move-${new Date().getTime()}`,
});
const channelId = testChannel.channel.id;
let moving = null;
let isInProgress = false;

while (moving === null || isInProgress) {
moving = await orgAdminClient.admin.conversations.bulkMove({
channel_ids: [channelId],
target_team_id: secondaryTeamId,
}).catch((error) => {
if (error.data.error === 'action_already_in_progress') {
isInProgress = true;
new Promise(r => setTimeout(r, 3000));
} else {
throw error;
}
});

if (moving && moving.ok) {
isInProgress = false;
}
}
logger.info(moving);
assert.isDefined(moving.bulk_action_id);
assert.isUndefined(moving.error);
});
});
});

0 comments on commit 473e319

Please sign in to comment.