Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

Commit

Permalink
fix userService tests
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinSi96 committed Dec 19, 2023
1 parent 869ccc8 commit 6a3b9d3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public void sendUpdateUserNotificationToQueue(String userId, String institutionI
UserToNotify userToNotify = new UserToNotify();
userToNotify.setUserId(userId);
UserNotificationToSend notification = new UserNotificationToSend();
String id = userToNotify.getUserId().concat(notification.getInstitutionId()).concat(notification.getProductId()).concat(userToNotify.getProductRole());
String id = userToNotify.getUserId().concat(institutionId);
notification.setId(id);
notification.setUpdatedAt(OffsetDateTime.now());
notification.setInstitutionId(institutionId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ void sendLegalTokenUserNotification_ok() {
UserBinding userBinding = new UserBinding(institutionId, List.of(onboardedProduct));
onboardedUser.setBindings(List.of(userBinding));
final User userMock = new DummyUser(institutionId);
when(userRegistryConnector.getUserByInternalId(any(), true))
when(userRegistryConnector.getUserByInternalId(any(), anyBoolean()))
.thenReturn(userMock);
when(userConnector.findById(any())).thenReturn(onboardedUser);

Expand All @@ -107,7 +107,7 @@ void sendLegalTokenUserNotification_ok() {
//then
assertDoesNotThrow(executable);
verify(userConnector, times(1)).findById(userId);
verify(userRegistryConnector, times(1)).getUserByInternalId(userId, true);
verify(userRegistryConnector, times(1)).getUserByInternalId(userId, false);
verify(kafkaTemplateUsers, times(1)).send(any(), any());
verifyNoMoreInteractions(userConnector, userRegistryConnector, kafkaTemplateUsers);

Expand Down Expand Up @@ -136,7 +136,7 @@ void sendLegalTokenUsersNotification_onFailure(){
UserBinding userBinding = new UserBinding(institutionId, List.of(onboardedProduct));
onboardedUser.setBindings(List.of(userBinding));
final User userMock = new DummyUser("institutionId");
when(userRegistryConnector.getUserByInternalId(any(), true))
when(userRegistryConnector.getUserByInternalId(any(), anyBoolean()))
.thenReturn(userMock);
when(userConnector.findById(any())).thenReturn(onboardedUser);

Expand All @@ -154,7 +154,7 @@ void sendLegalTokenUsersNotification_onFailure(){
//then
assertDoesNotThrow(executable);
verify(userConnector, times(1)).findById(userId);
verify(userRegistryConnector, times(1)).getUserByInternalId(userId, true);
verify(userRegistryConnector, times(1)).getUserByInternalId(userId, false);
verify(kafkaTemplateUsers, times(1)).send(any(), any());
verifyNoMoreInteractions(userConnector, userRegistryConnector, kafkaTemplateUsers);
}
Expand All @@ -181,7 +181,7 @@ void sendOperatorUserNotification(){
userBinding.setInstitutionId(institutionId);
onboardedUser.setBindings(List.of(userBinding));
final User userMock = new DummyUser(institutionId);
when(userRegistryConnector.getUserByInternalId(any(), true))
when(userRegistryConnector.getUserByInternalId(any(), anyBoolean()))
.thenReturn(userMock);
when(userConnector.findById(any())).thenReturn(onboardedUser);
when(kafkaTemplateUsers.send(any(), any()))
Expand All @@ -196,7 +196,7 @@ void sendOperatorUserNotification(){
//then
assertDoesNotThrow(executable);
verify(userConnector, times(1)).findById(userId);
verify(userRegistryConnector, times(1)).getUserByInternalId(userId, true);
verify(userRegistryConnector, times(1)).getUserByInternalId(userId, false);
verify(kafkaTemplateUsers, times(1)).send(any(), any());
verifyNoMoreInteractions(userConnector, userRegistryConnector, kafkaTemplateUsers);

Expand Down Expand Up @@ -224,7 +224,7 @@ void sendOperatorJsonError() throws JsonProcessingException {
userBinding.setInstitutionId(institutionId);
onboardedUser.setBindings(List.of(userBinding));
final User userMock = new DummyUser(institutionId);
when(userRegistryConnector.getUserByInternalId(any(), true))
when(userRegistryConnector.getUserByInternalId(any(), anyBoolean()))
.thenReturn(userMock);
when(userConnector.findById(any())).thenReturn(onboardedUser);

Expand All @@ -234,7 +234,7 @@ void sendOperatorJsonError() throws JsonProcessingException {
//then
assertDoesNotThrow(executable);
verify(userConnector, times(1)).findById(userId);
verify(userRegistryConnector, times(1)).getUserByInternalId(userId, true);
verify(userRegistryConnector, times(1)).getUserByInternalId(userId, false);
verifyNoMoreInteractions(userConnector, userRegistryConnector);
}
@Test
Expand All @@ -255,7 +255,7 @@ void toUserToNotifyFromToken() {
final User userMock = new DummyUser(institutionId);


when(userRegistryConnector.getUserByInternalId(any(), true))
when(userRegistryConnector.getUserByInternalId(any(), anyBoolean()))
.thenReturn(userMock);
when(userConnector.findById(any())).thenReturn(onboardedUser);

Expand All @@ -265,7 +265,7 @@ void toUserToNotifyFromToken() {
//then
assertEquals(1, usersToNotify.size());
verify(userConnector, times(1)).findById(userId);
verify(userRegistryConnector, times(1)).getUserByInternalId(userId, true);
verify(userRegistryConnector, times(1)).getUserByInternalId(userId, false);
verifyNoMoreInteractions(userConnector, userRegistryConnector);
}

Expand All @@ -285,15 +285,15 @@ void userToNotifyFromRelationship() {
UserBinding userBinding = new UserBinding(institutionId, List.of(onboardedProduct));
onboardedUser.setBindings(List.of(userBinding));
final User userMock = new DummyUser(institutionId);
when(userRegistryConnector.getUserByInternalId(any(), true))
when(userRegistryConnector.getUserByInternalId(any(), anyBoolean()))
.thenReturn(userMock);
when(userConnector.findById(any())).thenReturn(onboardedUser);
//when
List<UserToNotify> usersToNotify = userEventService.toUserToNotify(userId, institutionId, productId, relationshipId, tokenId);
//then
assertEquals(1, usersToNotify.size());
verify(userConnector, times(1)).findById(userId);
verify(userRegistryConnector, times(1)).getUserByInternalId(userId, true);
verify(userRegistryConnector, times(1)).getUserByInternalId(userId, false);
verifyNoMoreInteractions(userConnector, userRegistryConnector);
}

Expand All @@ -313,15 +313,15 @@ void toUserToNotifyNoProduct() {
UserBinding userBinding = new UserBinding(institutionId, List.of(onboardedProduct));
onboardedUser.setBindings(List.of(userBinding));
final User userMock = new DummyUser(institutionId);
when(userRegistryConnector.getUserByInternalId(any(), true))
when(userRegistryConnector.getUserByInternalId(any(), anyBoolean()))
.thenReturn(userMock);
when(userConnector.findById(any())).thenReturn(onboardedUser);
//when
List<UserToNotify> usersToNotify = userEventService.toUserToNotify(userId, institutionId, productId, relationshipId, tokenId);
//then
assertEquals(0, usersToNotify.size());
verify(userConnector, times(1)).findById(userId);
verify(userRegistryConnector, times(1)).getUserByInternalId(userId, true);
verify(userRegistryConnector, times(1)).getUserByInternalId(userId, false);
verifyNoMoreInteractions(userConnector, userRegistryConnector);
}

Expand All @@ -341,15 +341,15 @@ void toUserToNotifyDifferentInstitution() {
UserBinding userBinding = new UserBinding(UUID.randomUUID().toString(), List.of(onboardedProduct));
onboardedUser.setBindings(List.of(userBinding));
final User userMock = new DummyUser(institutionId);
when(userRegistryConnector.getUserByInternalId(any(), true))
when(userRegistryConnector.getUserByInternalId(any(), anyBoolean()))
.thenReturn(userMock);
when(userConnector.findById(any())).thenReturn(onboardedUser);
//when
List<UserToNotify> usersToNotify = userEventService.toUserToNotify(userId, institutionId, productId, relationshipId, tokenId);
//then
assertEquals(0, usersToNotify.size());
verify(userConnector, times(1)).findById(userId);
verify(userRegistryConnector, times(1)).getUserByInternalId(userId, true);
verify(userRegistryConnector, times(1)).getUserByInternalId(userId, false);
verifyNoMoreInteractions(userConnector, userRegistryConnector);
}

Expand Down

0 comments on commit 6a3b9d3

Please sign in to comment.