Skip to content

Commit

Permalink
Adds tests for Slack Connect APIs (#1306)
Browse files Browse the repository at this point in the history
* Add Slack Connect api tests
  • Loading branch information
srajiang committed Aug 12, 2021
1 parent 47a1018 commit 7748ca3
Showing 1 changed file with 70 additions and 2 deletions.
72 changes: 70 additions & 2 deletions prod-server-integration-tests/test/web-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('Web APIs', function () {
});
});

describe('cha.scheduleMessage', function () {
describe('chat.scheduleMessage', function () {
it('should accept either an integer or a string value for post_at', async function() {
const channelId = process.env.SLACK_SDK_TEST_WEB_TEST_CHANNEL_ID;
const postAt = Number.parseInt((Date.now() / 1000) + 60 * 15);
Expand All @@ -54,4 +54,72 @@ describe('Web APIs', function () {
}
});
});
});

describe('Slack Connect conversations.* methods', async function (){
/*
To run this test suite, we use two workspace-level bot tokens,
one for the sending workspace(list and send invites) another for the receiving
workspace (accept and approve) sent invites. Before being able to run this test,
we also need to have manually created a slack connect shared channel and added
these two bots as members first.
Required env variables:
export SLACK_SDK_TEST_CONNECT_INVITE_SENDER_BOT_TOKEN=
export SLACK_SDK_TEST_CONNECT_INVITE_RECEIVER_BOT_TOKEN=
export SLACK_SDK_TEST_CONNECT_INVITE_RECEIVER_BOT_USER_ID=
*/
const sender= new WebClient(process.env.SLACK_SDK_TEST_CONNECT_INVITE_SENDER_BOT_TOKEN);
const receiver = new WebClient(process.env.SLACK_SDK_TEST_CONNECT_INVITE_RECEIVER_BOT_TOKEN)

describe('listConnectInvites', function () {
it('should list shared channel invites ', async function () {
const invites = await sender.conversations.listConnectInvites({});
assert.isUndefined(invites.error);
});
});
describe('inviteShared, acceptShared, approveShared', function () {
it('should successfully send an invite and accept it', async function () {
let channelId, inviteId = null;
let channelName = Date.now().toString().concat('-connect-test');
try {
// creates channel to be shared
const newChannel = await sender.conversations.create({
name: channelName,
});
assert.isUndefined(newChannel.error);
channelId = newChannel.channel.id;

// sends invite to reciever bot
const inviteShared = await sender.conversations.inviteShared({
channel: channelId,
user_ids: process.env.SLACK_SDK_TEST_CONNECT_INVITE_RECEIVER_BOT_USER_ID,
});
assert.isUndefined(inviteShared.error);
assert.isDefined(inviteShared.invite_id);
inviteId = inviteShared.invite_id;

// accepts invite
const accepted = await receiver.conversations.acceptSharedInvite({
channel_name: channelName,
invite_id: inviteId
})
assert.isUndefined(accepted.error);

if (!accepted.implicit_approval) {
// attempts to have receiver approve shared invite
await receiver.conversations.approveSharedInvite({
invite_id: inviteId
})
}
} finally {
// cleanup any created channels
if (channelId) {
const cleanup = await sender.conversations.archive({ channel: channelId })
assert.isUndefined(cleanup.error)
}
}
});
});
});
});

0 comments on commit 7748ca3

Please sign in to comment.