Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds tests for Slack Connect APIs #1306

Merged
merged 7 commits into from Aug 12, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
72 changes: 70 additions & 2 deletions prod-server-integration-tests/test/web-api.js
Expand Up @@ -29,7 +29,7 @@ describe('Web APIs', function () {
});
});

describe('cha.scheduleMessage', function () {
describe('chat.scheduleMessage', function () {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch 👍

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)
}
}
});
});
});
});