Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Test] UserServiceTest 작성 #126

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public ResponseDto<MemoResponseDto> write(
}

@GetMapping("/daily/{weatherId}")
@Operation(summary = "하루 치 메모 반환", description = "하루치 메모 리스트를 반환하기 위한 API입니다. weather-controller에 있는 monthly API의 반환 값에 있는 weatherIzzd를 이용해서 조회합니다. ")
@Operation(summary = "하루 치 메모 반환", description = "하루치 메모 리스트를 반환하기 위한 API입니다. weather-controller에 있는 monthly API의 반환 값에 있는 weatherId를 이용해서 조회합니다. ")
public ResponseDto<MemoDailyResponseDto> daily(@PathVariable Long weatherId,
@AuthenticationPrincipal CustomUserDetails userDetails) {

Expand Down
6 changes: 6 additions & 0 deletions src/main/java/com/umc/yourweather/jwt/JwtTokenManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,12 @@ public boolean isRefreshTokenValid(String token) {
public void updateRefreshToken(User user, String refreshToken) {
user.updateRefreshToken(refreshToken);
}

public void setValue(String secretKey, Long accessTokenExpiration, Long refreshTokenExpiration) {
this.secretKey = secretKey;
this.accessTokenExpiration = accessTokenExpiration;
this.refreshTokenExpiration = refreshTokenExpiration;
}
Comment on lines +151 to +155
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 부분은 secretKey, accessTokenExpiration, refreshTokenExpiration을 직접 필드로 넣지 말고 인터페이스와 객체를 추가해 @Value 어노테이션에 대한 JwtTokenManager의 의존성을 제거하면 하면 굳이 프로덕션 코드에 테스트 전용 메서드를 안 써도 될 것 같아요 자세한건 나중에 적어드릴게요..!

}


Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.umc.yourweather.request;

import jakarta.validation.constraints.NotBlank;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

Expand All @@ -13,4 +14,11 @@ public class ChangePasswordRequestDto {

@NotBlank
String newPassword;

@Builder

public ChangePasswordRequestDto(String password, String newPassword) {
this.password = password;
this.newPassword = newPassword;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.umc.yourweather.repository.test;

import com.umc.yourweather.domain.entity.User;
import com.umc.yourweather.repository.UserRepository;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

public class UserTestRepository implements UserRepository {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

생성자를 추가해야할 것 같네요.
이 코드에서는 repository안에 데이터가 없을 겁니다. 비어있는 ArrayList인 것이죠. 생성자에서 필요한 데이터들을 ArrayList에 직접 넣어줘야지 아래의 Override한 메서드들이 제대로 테스트 될 것 같아요


List<User> repository = new ArrayList<>();

@Override
public Optional<User> findByEmail(String email) {
for (User user : repository) {
if (user.getEmail().equals(email)) {
return Optional.of(user);
}
}
return Optional.empty();
}

@Override
public Optional<User> findByRefreshToken(String refreshToken) {
for (User user : repository) {
if (user.getEmail().equals(refreshToken)) {
return Optional.of(user);
}
}
return Optional.empty();
}

@Override
public User save(User user) {
repository.add(user);
return user;
}

@Override
public void deleteExpiredUser() {
for (User user : repository) {
if (!user.isActivate()) {
repository.remove(user);
}
}
return;
}
}
Loading