Skip to content

Commit 3746f2a

Browse files
authored
KB-12367 | Email notifications not received by SPV and Content Creator| updated testCases (#213)
* KB-12295|DEV | BE | Content Retirement API implementation * KB-12367 | Email notifications not received by SPV and Content Creator * KB-12367 | Email notifications not received by SPV and Content Creator * KB-12367 | Email notifications not received by SPV and Content Creator: updated testCases * KB-12367 | Email notifications not received by SPV and Content Creator| updated testCases
1 parent e81b8d7 commit 3746f2a

File tree

2 files changed

+71
-56
lines changed

2 files changed

+71
-56
lines changed

src/test/java/com/igot/cb/service/ContentRetirementServiceTest.java

Lines changed: 48 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

src/test/java/com/igot/cb/service/NotificationServiceImplTest.java

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -392,12 +392,19 @@ void sendNotificationForContentRetirementSpv_validInput_shouldSendNotification()
392392
LocalDate date = LocalDate.now();
393393

394394
// Act
395+
List<String> emails = List.of(
396+
"rkspvpublisher@yopmail.com",
397+
"tarento.spv.publisher@yopmail.com"
398+
);
399+
String requestedBy = "91c9351f-803b-44d0-92a1-31f033bf3cc5";
395400
spyService.sendNotificationForContentRetirementSpv(
396401
"do_123",
397402
"Sample Course",
398-
users,
403+
new ArrayList<>(users),
399404
Constants.CONTENT_RETIREMENT_SCHEDULED_NOTIFICATION,
400-
date
405+
LocalDate.now(),
406+
emails,
407+
requestedBy
401408
);
402409

403410
// Assert
@@ -424,12 +431,18 @@ void sendNotificationForContentRetirementSpv_emptyUsers_shouldReturnEarly() {
424431
NotificationServiceImpl spyService = spy(notificationService);
425432

426433
// Act
434+
List<String> emails = List.of(
435+
"rkspvpublisher@yopmail.com",
436+
"tarento.spv.publisher@yopmail.com"
437+
);
438+
String requestedBy = "91c9351f-803b-44d0-92a1-31f033bf3cc5";
427439
spyService.sendNotificationForContentRetirementSpv(
428440
"do_124",
429441
"Course X",
430442
new ArrayList<>(),
431443
Constants.CONTENT_RETIREMENT_SCHEDULED_NOTIFICATION,
432-
LocalDate.now()
444+
LocalDate.now(),
445+
emails, requestedBy
433446
);
434447

435448
// Assert
@@ -446,14 +459,19 @@ void sendNotificationForContentRetirementSpv_exceptionThrown_shouldBeCaught() {
446459
.sendInAppNotification(any(), any(), any(), any());
447460

448461
ArrayList<String> users = new ArrayList<>(List.of("user1"));
449-
462+
List<String> emails = List.of(
463+
"rkspvpublisher@yopmail.com",
464+
"tarento.spv.publisher@yopmail.com"
465+
);
466+
String requestedBy = "91c9351f-803b-44d0-92a1-31f033bf3cc5";
450467
assertDoesNotThrow(() ->
451468
spyService.sendNotificationForContentRetirementSpv(
452469
"do_500",
453470
"Crash Course",
454471
users,
455472
Constants.CONTENT_RETIREMENT_SCHEDULED_NOTIFICATION,
456-
LocalDate.now()
473+
LocalDate.now(),
474+
emails, requestedBy
457475
)
458476
);
459477
}

0 commit comments

Comments
 (0)