@@ -370,7 +370,7 @@ void sendContentRetirementNotificationsToSpv_CreatedDateNotToday_ShouldSkip() {
370370
371371 verify (notificationService , never ())
372372 .sendNotificationForContentRetirementSpv (
373- any (), any (), any (), any (), any ());
373+ any (), any (), any (), any (), any (), any (), any () );
374374
375375 verify (contentService , never ())
376376 .readContent (anyString (), anyList ());
@@ -381,129 +381,126 @@ void sendContentRetirementNotificationsToSpv_ValidRequest_ShouldNotify() {
381381 LocalDate today = LocalDate .now ();
382382 Map <String , Object > record = Map .of (
383383 Constants .CONTENT_ID , "do_123" ,
384- Constants .CREATED_AT_FIELD , Instant . now () ,
384+ Constants .CREATED_AT_FIELD , today ,
385385 Constants .USER_ID_RAISED_FIELD , "requester-1" ,
386386 Constants .RETIREMENT_DATE , today .plusDays (5 )
387387 );
388388 when (cassandraOperation .getRecordsByProperties (any (), any (), any (), any (), any ()))
389389 .thenReturn (List .of (record ));
390-
391390 when (contentService .readContent (eq ("do_123" ), any ()))
392391 .thenReturn (Map .of ("name" , "Sample Course" ));
393-
394392 mockSpvUsers (List .of ("spv-1" , "spv-2" ));
395393 contentRetirementService .sendContentRetirementNotificationsToSpv ();
396-
397394 verify (notificationService ).sendNotificationForContentRetirementSpv (
398395 eq ("do_123" ),
399396 eq ("Sample Course" ),
400397 argThat (list ->
401- list .contains ("spv-1" )
402- && list .contains ("spv-2" )
403- && list .contains ("requester-1" )
398+ list .contains ("spv-1" ) &&
399+ list .contains ("spv-2" )
404400 ),
405401 eq (Constants .CONTENT_RETIREMENT_SCHEDULED_NOTIFICATION ),
406- eq (today .plusDays (5 ))
402+ eq (today .plusDays (5 )),
403+ argThat (emails -> emails .contains ("spv-1@test.com" )),
404+ eq ("requester-1" )
407405 );
408406 }
409407
410408 @ Test
411409 void sendContentRetirementNotificationsToSpv_NoRequester_ShouldNotifyOnlySpv () {
410+ LocalDate today = LocalDate .now ();
412411 Map <String , Object > record = Map .of (
413412 Constants .CONTENT_ID , "do_124" ,
414- Constants .CREATED_AT_FIELD , Instant . now () ,
415- Constants .RETIREMENT_DATE , LocalDate . now () .plusDays (7 )
413+ Constants .CREATED_AT_FIELD , today ,
414+ Constants .RETIREMENT_DATE , today .plusDays (7 )
416415 );
417416 when (cassandraOperation .getRecordsByProperties (any (), any (), any (), any (), any ()))
418417 .thenReturn (List .of (record ));
419418 when (contentService .readContent (eq ("do_124" ), any ()))
420419 .thenReturn (Map .of ("name" , "Course X" ));
421420 mockSpvUsers (List .of ("spv-1" ));
422421 contentRetirementService .sendContentRetirementNotificationsToSpv ();
423-
424422 verify (notificationService ).sendNotificationForContentRetirementSpv (
425423 eq ("do_124" ),
426424 eq ("Course X" ),
427- any ( ArrayList . class ),
425+ argThat ( list -> list . contains ( "spv-1" ) ),
428426 any (),
429- any ()
427+ any (),
428+ anyList (),
429+ isNull ()
430430 );
431-
432431 }
433432
434433 @ Test
435- void sendContentRetirementNotificationsToSpv_NoSpvUsers_ShouldNotifyRequesterOnly () {
434+ void sendContentRetirementNotificationsToSpv_NoSpvUsers_ShouldNotNotifyAnyone () {
435+ LocalDate today = LocalDate .now ();
436436 Map <String , Object > record = Map .of (
437437 Constants .CONTENT_ID , "do_125" ,
438- Constants .CREATED_AT_FIELD , Instant . now () ,
438+ Constants .CREATED_AT_FIELD , today ,
439439 Constants .USER_ID_RAISED_FIELD , "requester-2" ,
440- Constants .RETIREMENT_DATE , LocalDate . now () .plusDays (3 )
440+ Constants .RETIREMENT_DATE , today .plusDays (3 )
441441 );
442442 when (cassandraOperation .getRecordsByProperties (any (), any (), any (), any (), any ()))
443443 .thenReturn (List .of (record ));
444- when (contentService .readContent (eq ("do_125" ), any ()))
445- .thenReturn (Map .of ("name" , "Course Y" ));
446-
447- // This now mocks props + outbound call
448444 mockSpvUsers (Collections .emptyList ());
449445 contentRetirementService .sendContentRetirementNotificationsToSpv ();
450- ArgumentCaptor <ArrayList <String >> captor =
451- ArgumentCaptor .forClass (ArrayList .class );
452-
453- verify (notificationService ).sendNotificationForContentRetirementSpv (
454- eq ("do_125" ),
455- eq ("Course Y" ),
456- captor .capture (),
457- eq (Constants .CONTENT_RETIREMENT_SCHEDULED_NOTIFICATION ),
458- any ()
459- );
460-
461- ArrayList <String > recipients = captor .getValue ();
462- assertEquals (1 , recipients .size ());
463- assertEquals ("requester-2" , recipients .get (0 ));
446+ verifyNoInteractions (notificationService );
464447 }
465448
449+
466450 @ Test
467451 void sendContentRetirementNotificationsToSpv_RetirementDateInstant_ShouldConvert () {
468452 Map <String , Object > record = Map .of (
469453 Constants .CONTENT_ID , "do_126" ,
470454 Constants .CREATED_AT_FIELD , Instant .now (),
471455 Constants .USER_ID_RAISED_FIELD , "user-x" ,
472- Constants .RETIREMENT_DATE , Instant .now ().plus (10 , ChronoUnit . DAYS )
456+ Constants .RETIREMENT_DATE , LocalDate .now ().plusDays (10 )
473457 );
474-
475458 when (cassandraOperation .getRecordsByProperties (any (), any (), any (), any (), any ()))
476459 .thenReturn (List .of (record ));
477460 when (contentService .readContent (any (), any ()))
478461 .thenReturn (Map .of ("name" , "Course Z" ));
479-
480462 mockSpvUsers (List .of ("spv" ));
463+ Map <String , Object > spvUser = Map .of (
464+ "userId" , "spv" ,
465+ "email" , "spv@test.com"
466+ );
481467 contentRetirementService .sendContentRetirementNotificationsToSpv ();
482-
483468 verify (notificationService ).sendNotificationForContentRetirementSpv (
484- any (), any (), any (), any (), any (LocalDate .class )
469+ any (), any (), any (), any (), any (LocalDate .class ), anyList (), any ()
485470 );
486471 }
487472
473+
488474 private void mockSpvUsers (List <String > spvUserIds ) {
489475 when (props .getSbUrl ()).thenReturn ("http://test" );
490476 when (props .getUserSearchEndPoint ()).thenReturn ("/search" );
491- Map <String , Object > response = Map .of (
492- Constants .RESPONSE_CODE , "OK" ,
493- Constants .RESULT , Map .of (
494- Constants .RESPONSE , Map .of (
495- Constants .CONTENT ,
496- spvUserIds .stream ()
497- .map (id -> Map .of (Constants .USER_ID , id ))
498- .toList ()
499- )
477+ List <Map <String , Object >> contents = spvUserIds .stream ()
478+ .map (id -> {
479+ Map <String , Object > personalDetails = new HashMap <>();
480+ personalDetails .put (Constants .PRIMARY_EMAIL , id + "@test.com" );
481+
482+ Map <String , Object > profileDetails = new HashMap <>();
483+ profileDetails .put (Constants .PERSONAL_DETAILS , personalDetails );
484+
485+ Map <String , Object > user = new HashMap <>();
486+ user .put (Constants .USER_ID , id );
487+ user .put (Constants .PROFILE_DETAILS , profileDetails );
488+
489+ return user ;
490+ }).toList ();
491+ Map <String , Object > response = new HashMap <>();
492+ response .put (Constants .RESPONSE_CODE , "OK" );
493+ response .put (Constants .RESULT , Map .of (
494+ Constants .RESPONSE , Map .of (
495+ Constants .CONTENT , contents
500496 )
501- );
497+ )) ;
502498 when (outboundRequestHandlerService .fetchResultUsingPost (
503499 eq ("http://test/search" ),
504500 any (),
505501 any ()
506502 )).thenReturn (response );
507503 }
508504
505+
509506}
0 commit comments