@@ -32,4 +32,46 @@ describe('checkAllUsersActive', () => {
3232 expect ( userRepo . remove ) . toHaveBeenCalledTimes ( 1 ) ;
3333 expect ( userRepo . remove ) . toHaveBeenCalledWith ( 'B' ) ;
3434 } ) ;
35+
36+ it ( 'should send a Slack notification when users are removed' , async ( ) => {
37+ const app = buildMockApp ( ) ;
38+ userRepo . listAll = jest . fn ( ) . mockResolvedValue ( [
39+ { id : 'A' , name : 'Alice Smith' , languages : [ ] , lastReviewedDate : 1 } ,
40+ { id : 'B' , name : 'Bob Jones' , languages : [ ] , lastReviewedDate : 2 } ,
41+ { id : 'C' , name : 'Charlie Brown' , languages : [ ] , lastReviewedDate : 3 } ,
42+ ] ) ;
43+ userRepo . remove = jest . fn ( ) ;
44+ // First user active, second and third inactive
45+ userService . isActive = jest
46+ . fn ( )
47+ . mockResolvedValueOnce ( true )
48+ . mockResolvedValueOnce ( false )
49+ . mockResolvedValueOnce ( false ) ;
50+
51+ await checkAllUsersActive ( app ) ;
52+
53+ // Verify users were removed
54+ expect ( userRepo . remove ) . toHaveBeenCalledTimes ( 2 ) ;
55+ expect ( userRepo . remove ) . toHaveBeenCalledWith ( 'B' ) ;
56+ expect ( userRepo . remove ) . toHaveBeenCalledWith ( 'C' ) ;
57+
58+ // Verify Slack notification was sent
59+ expect ( app . client . chat . postMessage ) . toHaveBeenCalledTimes ( 1 ) ;
60+ expect ( app . client . chat . postMessage ) . toHaveBeenCalledWith (
61+ expect . objectContaining ( {
62+ channel : process . env . ERRORS_CHANNEL_ID ,
63+ text : expect . stringContaining ( 'User(s) removed from HackerRank queue' ) ,
64+ } ) ,
65+ ) ;
66+
67+ // Verify the message contains the removed users' names
68+ const callArgs = ( app . client . chat . postMessage as jest . Mock ) . mock . calls [ 0 ] [ 0 ] ;
69+ expect ( callArgs . text ) . toContain ( 'Bob Jones' ) ;
70+ expect ( callArgs . text ) . toContain ( 'Charlie Brown' ) ;
71+
72+ // Verify the message contains the Confluence link
73+ expect ( callArgs . text ) . toContain (
74+ 'https://allies.atlassian.net/wiki/spaces/REI/pages/4852121601/HackerRank+Roles+and+Permissions#Deactivating-a-User' ,
75+ ) ;
76+ } ) ;
3577} ) ;
0 commit comments