package Ġuk . gov . just ice . digital . h mp ps . oauth 2 server . timed Ċ Ċ import Ġcom . microsoft . application insights . Telemetry Client Ċ import Ġorg . assertj . core . api . Assertions . assertThat Ċ import Ġorg . junit . jupiter . api . Test Ċ import Ġorg . junit . jupiter . api . extension . Extend With Ċ import Ġorg . mockito . Argument Captor Ċ import Ġorg . mockito . Argument Matchers Ċ import Ġorg . mockito . Captor Ċ import Ġorg . mockito . junit . jupiter . Mockito Extension Ċ import Ġorg . mockito . kotlin . any Ċ import Ġorg . mockito . kotlin . check Ċ import Ġorg . mockito . kotlin . eq Ċ import Ġorg . mockito . kotlin . isNull Ċ import Ġorg . mockito . kotlin . mock Ċ import Ġorg . mockito . kotlin . times Ċ import Ġorg . mockito . kotlin . verify Ċ import Ġorg . mockito . kotlin . wh enever Ċ import Ġuk . gov . just ice . digital . h mp ps . oauth 2 server . auth . model . User Helper . Companion . create Sample User Ċ import Ġuk . gov . just ice . digital . h mp ps . oauth 2 server . auth . repository . UserRepository Ċ import Ġuk . gov . service . notify . Notification Client Api Ċ Ċ @ Extend With ( Mockito Extension :: class ) Ċ class ĠNotify Pre Disable Auth Users Service Test Ġ{ ĊĠ Ġprivate Ġval Ġuser Repository : ĠUser Repository Ġ= Ġmock () ĊĠ Ġprivate Ġval Ġnotification Client : ĠNotification Client Api Ġ= Ġmock () ĊĠ Ġprivate Ġval Ġtelemetry Client : ĠTe lemetry Client Ġ= Ġmock () ĊĠ Ġprivate Ġval Ġservice : ĠNotify Pre Disable Auth Users Service Ġ= ĊĠĠĠ ĠNotify Pre Disable Auth Users Service ( ĊĠĠĠĠĠ Ġuser Repository , ĊĠĠĠĠĠ Ġnotification Client , ĊĠĠĠĠĠ Ġtelemetry Client , ĊĠĠĠĠĠĠ 1 0 , ĊĠĠĠĠĠ Ġ" template ", ĊĠĠĠĠĠ Ġ" signin - url ", ĊĠĠĠĠĠ Ġ" support - url " ĊĠĠĠ Ġ) ĊĊĠ Ġ@ Captor ĊĠ Ġprivate Ġlateinit Ġvar Ġmap Captor : ĠArgument Captor < Map < String , ĠString >> ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġfind And Warn Pre Disable Inactive Auth Users _ deactivate Warning Sent () Ġ{ ĊĠĠĠ Ġval Ġusers Ġ= ĠlistOf ( create Sample User ( username Ġ= Ġ" user ", Ġemail Ġ= Ġ" bob @ just ice . gov . uk ", Ġverified Ġ= Ġtrue , Ġenabled Ġ= Ġtrue )) ĊĠĠĠ Ġwhenever ( ĊĠĠĠĠĠ Ġuser Repository . find Top 1 0 By Last LoggedIn Before And Enabled IsTrue And Pre Disable Warning IsFalse And Verified IsTrue And Source OrderBy Username ( ĊĠĠĠĠĠĠĠ Ġany (), ĊĠĠĠĠĠĠĠ Ġany () ĊĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ) ĊĠĠĠĠĠ Ġ. thenReturn ( users ) ĊĠĠĠ ĠassertThat ( service . process In B atches ()). isEqualTo ( 1 ) ĊĠĠĠ ĠassertThat ( users ). extract ing < Boolean > Ġ{ Ġit . pre Disable Warning Ġ}. contains Exactly ( true ,) ĊĠĠĠ Ġverify ( notification Client ). send Email ( ĊĠĠĠĠĠ Ġeq (" template "), ĊĠĠĠĠĠ Ġeq (" bob @ just ice . gov . uk "), ĊĠĠĠĠĠ Ġcheck Ġ{ ĊĠĠĠĠĠĠĠ ĠassertThat ( it [" username "]). isEqualTo (" user ") ĊĠĠĠĠĠ Ġ}, ĊĠĠĠĠĠ Ġis Null () ĊĠĠĠ Ġ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġfind And Disable Inactive Auth Users _ email Verified _ Telemetry () Ġ{ ĊĠĠĠ Ġval Ġusers Ġ= ĠlistOf ( ĊĠĠĠĠĠ Ġcreate Sample User ( username Ġ= Ġ" user ", Ġverified Ġ= Ġtrue , Ġenabled Ġ= Ġtrue ), ĊĠĠĠĠĠ Ġcreate Sample User ( username Ġ= Ġ" jo e ", Ġverified Ġ= Ġtrue , Ġenabled Ġ= Ġtrue ), ĊĠĠĠ Ġ) ĊĠĠĠ Ġwhenever ( ĊĠĠĠĠĠ Ġuser Repository . find Top 1 0 By Last LoggedIn Before And Enabled IsTrue And Pre Disable Warning IsFalse And Verified IsTrue And Source OrderBy Username ( ĊĠĠĠĠĠĠĠ Ġany (), Ġany () ĊĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ) ĊĠĠĠĠĠ Ġ. thenReturn ( users ) ĊĠĠĠ Ġservice . process In B atches () ĊĠĠĠ Ġverify ( telemetry Client , Ġtimes ( 2 )). track Event ( ĊĠĠĠĠĠ ĠArgument Matchers . eq (" Auth Notify Pre Disable Inactive Auth Users Processed "), ĊĠĠĠĠĠ Ġmap Captor . capture (), ĊĠĠĠĠĠ ĠArgument Matchers . isNull () ĊĠĠĠ Ġ) ĊĠĠĠ ĠassertThat ( map Captor . all Values . map Ġ{ Ġit [" username "] Ġ}). contains Exactly (" user ", Ġ" jo e ") ĊĠ Ġ} Ċ } Ċ