50 lines
1.7 KiB
TypeScript
50 lines
1.7 KiB
TypeScript
import { describe, test } from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import {
|
|
resolveSlackWebhookUrl,
|
|
isReferralSlackAlertType,
|
|
} from '../services/slackService';
|
|
|
|
describe('resolveSlackWebhookUrl', () => {
|
|
test('uses channel-specific URL when set', () => {
|
|
assert.equal(
|
|
resolveSlackWebhookUrl('security', {
|
|
securityWebhookUrl: 'https://hooks.slack.com/security',
|
|
referralWebhookUrl: 'https://hooks.slack.com/referral',
|
|
fallbackWebhookUrl: 'https://hooks.slack.com/fallback',
|
|
}),
|
|
'https://hooks.slack.com/security'
|
|
);
|
|
assert.equal(
|
|
resolveSlackWebhookUrl('referral', {
|
|
securityWebhookUrl: 'https://hooks.slack.com/security',
|
|
referralWebhookUrl: 'https://hooks.slack.com/referral',
|
|
fallbackWebhookUrl: 'https://hooks.slack.com/fallback',
|
|
}),
|
|
'https://hooks.slack.com/referral'
|
|
);
|
|
});
|
|
|
|
test('falls back to SLACK_WEBHOOK_URL when channel URL is missing', () => {
|
|
assert.equal(
|
|
resolveSlackWebhookUrl('referral', {
|
|
securityWebhookUrl: 'https://hooks.slack.com/security',
|
|
fallbackWebhookUrl: 'https://hooks.slack.com/fallback',
|
|
}),
|
|
'https://hooks.slack.com/fallback'
|
|
);
|
|
});
|
|
|
|
test('returns empty string when nothing is configured', () => {
|
|
assert.equal(resolveSlackWebhookUrl('security', {}), '');
|
|
});
|
|
});
|
|
|
|
describe('isReferralSlackAlertType', () => {
|
|
test('matches referral_* alert types', () => {
|
|
assert.equal(isReferralSlackAlertType('referral_commission_review'), true);
|
|
assert.equal(isReferralSlackAlertType('referral_commission_blocked'), true);
|
|
assert.equal(isReferralSlackAlertType('withdrawal_flagged'), false);
|
|
});
|
|
});
|