@@ -66,17 +66,43 @@ describe('slack-utils', () => {
6666 beforeEach ( ( ) => {
6767 log = { error : sinon . spy ( ) } ;
6868 env = {
69- slackBotToken : 'test-bot-token' ,
70- slackSigningSecret : 'test-signing-secret' ,
71- slackTokenWorkspaceInternal : 'test-workspace-token' ,
72- slackOpsChannelWorkspaceInternal : 'test-ops-channel' ,
69+ SLACK_BOT_TOKEN : 'test-bot-token' ,
70+ SLACK_SIGNING_SECRET : 'test-signing-secret' ,
71+ SLACK_TOKEN_WORKSPACE_INTERNAL : 'test-workspace-token' ,
72+ SLACK_OPS_CHANNEL_WORKSPACE_INTERNAL : 'test-ops-channel' ,
7373 } ;
7474 slackContext = {
7575 channelId : 'C12345678' ,
7676 threadTs : '12345.67890' ,
7777 } ;
7878 } ) ;
7979
80+ it ( 'should send a message to Slack when all parameters are valid' , async ( ) => {
81+ mockHasText . returns ( true ) ;
82+
83+ await say ( env , log , slackContext , 'Test message' ) ;
84+
85+ expect ( mockBaseSlackClient . createFrom . calledOnce ) . to . be . true ;
86+ expect ( mockBaseSlackClient . createFrom . calledWith ( {
87+ channelId : 'C12345678' ,
88+ threadTs : '12345.67890' ,
89+ env : {
90+ SLACK_BOT_TOKEN : 'test-bot-token' ,
91+ SLACK_SIGNING_SECRET : 'test-signing-secret' ,
92+ SLACK_TOKEN_WORKSPACE_INTERNAL : 'test-workspace-token' ,
93+ SLACK_OPS_CHANNEL_WORKSPACE_INTERNAL : 'test-ops-channel' ,
94+ } ,
95+ } , 'workspace_internal' ) ) . to . be . true ;
96+
97+ expect ( mockSlackClient . postMessage . calledOnce ) . to . be . true ;
98+ expect ( mockSlackClient . postMessage . calledWith ( {
99+ channel : 'C12345678' ,
100+ thread_ts : '12345.67890' ,
101+ text : 'Test message' ,
102+ unfurl_links : false ,
103+ } ) ) . to . be . true ;
104+ } ) ;
105+
80106 it ( 'should not send message if threadTs is missing or empty' , async ( ) => {
81107 mockHasText . withArgs ( 'C12345678' ) . returns ( true ) ;
82108 mockHasText . withArgs ( '' ) . returns ( false ) ;
@@ -156,6 +182,32 @@ describe('slack-utils', () => {
156182 } ) ) . to . be . true ;
157183 } ) ;
158184
185+ it ( 'should handle error when env is missing required properties' , async ( ) => {
186+ const incompleteEnv = {
187+ SLACK_BOT_TOKEN : 'test-bot-token' ,
188+ // Missing other required properties
189+ } ;
190+
191+ // Make BaseSlackClient.createFrom throw when it receives incomplete env
192+ mockBaseSlackClient . createFrom . withArgs ( sinon . match ( {
193+ env : sinon . match ( {
194+ SLACK_BOT_TOKEN : 'test-bot-token' ,
195+ SLACK_SIGNING_SECRET : undefined ,
196+ SLACK_TOKEN_WORKSPACE_INTERNAL : undefined ,
197+ SLACK_OPS_CHANNEL_WORKSPACE_INTERNAL : undefined ,
198+ } ) ,
199+ } ) ) . throws ( new Error ( 'Missing required environment variables' ) ) ;
200+
201+ await say ( incompleteEnv , log , slackContext , 'Test message' ) ;
202+
203+ expect ( log . error . calledOnce ) . to . be . true ;
204+ expect ( log . error . calledWith ( 'Error sending Slack message:' , {
205+ error : 'Missing required environment variables' ,
206+ stack : sinon . match . string ,
207+ errorType : 'Error' ,
208+ } ) ) . to . be . true ;
209+ } ) ;
210+
159211 it ( 'should handle empty message string' , async ( ) => {
160212 mockHasText . returns ( true ) ;
161213
0 commit comments