|
5 | 5 | import { expect } from 'chai'; |
6 | 6 | import { describe, it } from 'mocha'; |
7 | 7 | import Slack from '../../src/services/Slack.js'; |
| 8 | +import dotenv from 'dotenv'; |
8 | 9 |
|
9 | 10 | describe('Slack Services', function () { |
10 | 11 | this.timeout(40000); |
11 | 12 |
|
| 13 | + before(function () { |
| 14 | + console.log("⚠️ Running slack e2e tests with real env vars"); |
| 15 | + dotenv.config(); |
| 16 | + if(!process.env.SLACK_DEFAULT_MESSAGE_CHANNEL_WEBHOOK_URL){ |
| 17 | + console.error("❌ SLACK_DEFAULT_MESSAGE_CHANNEL_WEBHOOK_URL env is not set. Skipping slack e2e tests."); |
| 18 | + this.skip(); |
| 19 | + } |
| 20 | + }); |
| 21 | + |
12 | 22 | describe('sendMessage', function () { |
13 | 23 | // Happy path |
14 | 24 | it('should send a message to the default channel', async function () { |
15 | 25 | const res = await Slack.sendMessage(':mag: <https://github.com/gitcommitshow/rudder-github-app/pull/82|#82: Test message from our GitHub App>\n*Author:* gitcommitshow\n*Created:* Sep 18, 2025 at 10:00 AM\n\n<!channel>', { |
16 | | - webhookUrl: "https://hooks.slack.com/services/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" |
| 26 | + webhookUrl: process.env.SLACK_DEFAULT_MESSAGE_CHANNEL_WEBHOOK_URL |
17 | 27 | }); |
18 | 28 | expect(res).to.not.throw; |
19 | 29 | }); |
20 | 30 |
|
21 | 31 | // Error path 1 - no message |
22 | 32 | it('should throw an error if the message is not set', async function () { |
23 | | - expect(Slack.sendMessage(null, { |
24 | | - webhookUrl: "https://hooks.slack.com/services/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" |
25 | | - })).to.throw; |
26 | | - }); |
27 | | - |
28 | | - // Error path 2 - no webhook url |
29 | | - it('should throw an error if the webhook url is not set', async function () { |
30 | | - expect(Slack.sendMessage("testing error path 2 - no webhook url")).to.throw; |
| 33 | + expect(Slack.sendMessage()).to.throw; |
31 | 34 | }); |
32 | 35 | }); |
33 | 36 |
|
|
0 commit comments