Skip to content

Commit

Permalink
test first access
Browse files Browse the repository at this point in the history
  • Loading branch information
ElisKina-dev committed Jun 7, 2024
1 parent fcd6fa3 commit dfbbef4
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,32 @@ void testInsert() {
assertEquals(userDTO, result);
}

@Test
void testFirstAccess() {
String userId = "testUserId";
User user = new User();
UserWithProfilesDTO userWithProfilesDTO = new UserWithProfilesDTO();

when(userService.checkFirstAccess(userId)).thenReturn(Uni.createFrom().voidItem());
when(userService.findUser(userId)).thenReturn(Uni.createFrom().item(user));
when(userMapper.toProfilesDTO(user)).thenReturn(userWithProfilesDTO);

UserWithProfilesDTO result = given()
.pathParam("userId", userId)
.when()
.post("/api/v1/model/users/first-access/{userId}")
.then()
.statusCode(200)
.extract()
.as(UserWithProfilesDTO.class);

assertEquals(userWithProfilesDTO, result);
verify(userService, times(1)).checkFirstAccess(userId);
verify(userService, times(1)).findUser(userId);
verify(userMapper, times(1)).toProfilesDTO(user);
}


@Test
void testUpdate() {
User user = new User();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,4 +306,47 @@ void testDeleteOK() {
.assertItem(true);
}

@Test
void testCheckFirstAccessWhenNoUsers() {
String userId = "testUserId";
long userCount = 0;

when(userRepository.count()).thenReturn(Uni.createFrom().item(userCount));
when(userProfilesService.insertUserProfiles(any(UserProfilesInsertionDTO.class)))
.thenReturn(Uni.createFrom().item(new ArrayList<>()));

User mockedUser = new User();
mockedUser.setUserId(userId);
when(userMapper.toEntityInsertion(any(UserInsertionDTO.class))).thenReturn(mockedUser);

when(userRepository.persist(any(User.class))).thenReturn(Uni.createFrom().item(mockedUser));

userServiceImpl.checkFirstAccess(userId)
.subscribe().withSubscriber(UniAssertSubscriber.create())
.assertCompleted()
.assertItem(null);

verify(userRepository, times(1)).count();
verify(userProfilesService, times(1)).insertUserProfiles(any(UserProfilesInsertionDTO.class));
verify(userRepository, times(1)).persist(any(User.class));
}


@Test
void testCheckFirstAccessWhenUsersExist() {
String userId = "testUserId";
long userCount = 5;

when(userRepository.count()).thenReturn(Uni.createFrom().item(userCount));

userServiceImpl.checkFirstAccess(userId)
.subscribe()
.withSubscriber(UniAssertSubscriber.create())
.assertCompleted()
.assertItem(null);

verify(userRepository, times(1)).count();
verify(userProfilesService, never()).insertUserProfiles(any(UserProfilesInsertionDTO.class));
}

}

0 comments on commit dfbbef4

Please sign in to comment.