integration.test.js•4.1 kB
/**
* Integration Tests for Slack MCP Server
*
* IMPORTANT: These tests require a valid Slack OAuth token
* Credentials are loaded from .env file automatically
*
* Run with: npm run test:integration
*/
// Load environment variables from .env file
import dotenv from 'dotenv';
dotenv.config();
import { conversationsHistory, conversationsReplies, conversationsSearchMessages, channelsList } from '../dist/tools.js';
// Load test credentials from .env file
const TEST_TOKEN = process.env.SLACK_TEST_TOKEN;
const TEST_CHANNEL = process.env.SLACK_TEST_CHANNEL || '#testing';
if (!TEST_TOKEN) {
console.error('ERROR: SLACK_TEST_TOKEN environment variable not set');
console.error('Set it with: export SLACK_TEST_TOKEN=xoxp-...');
process.exit(1);
}
describe('Slack MCP Server Integration Tests', () => {
test('conversations_history - retrieves channel messages', async () => {
const result = await conversationsHistory({
accessToken: TEST_TOKEN,
channel_id: TEST_CHANNEL,
limit: 10
});
console.log('conversations_history result:', JSON.stringify(result, null, 2));
expect(result.success).toBe(true);
expect(result.data).toBeDefined();
expect(result.data.messages).toBeInstanceOf(Array);
expect(result.data.channel_id).toBeDefined();
}, 30000);
test('conversations_history - handles invalid channel', async () => {
const result = await conversationsHistory({
accessToken: TEST_TOKEN,
channel_id: 'INVALID_CHANNEL',
limit: 10
});
console.log('Invalid channel result:', JSON.stringify(result, null, 2));
expect(result.success).toBe(false);
expect(result.error).toContain('Channel not found');
}, 30000);
test('conversations_history - handles invalid token', async () => {
const result = await conversationsHistory({
accessToken: 'xoxp-invalid-token',
channel_id: TEST_CHANNEL,
limit: 10
});
console.log('Invalid token result:', JSON.stringify(result, null, 2));
expect(result.success).toBe(false);
expect(result.error).toContain('Invalid or expired');
}, 30000);
test('channels_list - retrieves workspace channels', async () => {
const result = await channelsList({
accessToken: TEST_TOKEN,
channel_types: 'public_channel',
limit: 20
});
console.log('channels_list result:', JSON.stringify(result, null, 2));
expect(result.success).toBe(true);
expect(result.data).toBeDefined();
expect(result.data.channels).toBeInstanceOf(Array);
if (result.data.channels.length > 0) {
expect(result.data.channels[0].id).toBeDefined();
expect(result.data.channels[0].name).toBeDefined();
}
}, 30000);
test('channels_list - sorts by popularity', async () => {
const result = await channelsList({
accessToken: TEST_TOKEN,
channel_types: 'public_channel',
sort: 'popularity',
limit: 10
});
console.log('channels_list with sorting result:', JSON.stringify(result, null, 2));
expect(result.success).toBe(true);
if (result.data.channels.length > 1) {
// Verify sorting by member count
const first = result.data.channels[0].member_count || 0;
const second = result.data.channels[1].member_count || 0;
expect(first).toBeGreaterThanOrEqual(second);
}
}, 30000);
test('Schema validation - missing required field', async () => {
const result = await conversationsHistory({
accessToken: TEST_TOKEN
// Missing channel_id
});
console.log('Validation error result:', JSON.stringify(result, null, 2));
expect(result.success).toBe(false);
expect(result.error).toContain('Validation error');
}, 30000);
});
/**
* TODO: Add these tests after obtaining test data:
*
* 1. conversations_replies - test with actual thread_ts
* 2. conversations_search_messages - test with search queries
* 3. Pagination - test cursor-based pagination
* 4. Channel name resolution - test #channel format
* 5. DM resolution - test @username format
* 6. Date filtering - test time ranges (7d, 1m, etc)
*/