Skip to content

Commit

Permalink
Refactor: 카카오 메시지 필드 개편, 입금 계좌 정보 gitignore, 프론트 구분용 uri gitignore화 (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
GitJIHO authored Nov 7, 2024
1 parent 9295e8b commit 6cfe171
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ public class KakaoApiService {
private static final String KAKAO_AUTH_BASE_URL = "https://kauth.kakao.com/oauth";
private static final String KAKAO_API_BASE_URL = "https://kapi.kakao.com/v2/user";
private static final String LOCALHOST_URL = "localhost:5173";
private static final String FRONT_URL = "dc9u22hnkwb24.cloudfront.net";

private final RestTemplate restTemplate;
private final KakaoProperties kakaoProperties;
Expand All @@ -39,7 +38,7 @@ public String getAuthorizationUrl(HttpServletRequest httpServletRequest) {

if (requestUrl.contains(LOCALHOST_URL)) {
redirectUri = kakaoProperties.devRedirectUri();
} else if (requestUrl.contains(FRONT_URL)) {
} else if (requestUrl.contains(kakaoProperties.frontUriWithoutHttps())) {
redirectUri = kakaoProperties.redirectUri();
} else {
throw new BadRequestException("해당 도메인에서는 카카오 로그인이 불가합니다. requestUrl : " + requestUrl);
Expand All @@ -62,7 +61,7 @@ public KakaoTokenResponse getAccessToken(String authorizationCode, HttpServletRe

if (requestUrl.contains(LOCALHOST_URL)) {
redirectUri = kakaoProperties.devRedirectUri();
} else if (requestUrl.contains(FRONT_URL)) {
} else if (requestUrl.contains(kakaoProperties.frontUriWithoutHttps())) {
redirectUri = kakaoProperties.redirectUri();
} else {
throw new BadRequestException("해당 도메인에서는 카카오 로그인이 불가합니다. requestUrl : " + requestUrl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ public record KakaoProperties(
String clientId,
String redirectUri,
String devRedirectUri,
String frontUri
String frontUri,
String bankName,
String accountNumber,
String name,
String frontUriWithoutHttps
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public KakaoMessageService(KakaoTokenService kakaoTokenService, RestTemplate res
this.kakaoProperties = kakaoProperties;
}

public void sendPointChargeRequestReceivedMessage(String email, int point, String name) {
public void sendPointChargeRequestReceivedMessage(String email, int point, String name, String depositMessage) {
String accessToken = kakaoTokenService.getValidAccessTokenInServer(email);

if (accessToken == null) {
Expand All @@ -45,7 +45,7 @@ public void sendPointChargeRequestReceivedMessage(String email, int point, Strin
"\"object_type\": \"feed\"," +
"\"content\": {" +
"\"title\": \"%s님의 포인트 충전 요청 접수\"," +
"\"description\": \"입금 금액을 입금해주시기 바랍니다.\"," +
"\"description\": \"입금자명 변경하여 입금해주시기 바랍니다.\"," +
"\"image_url\": \"%s\"," +
"\"image_width\": 640," +
"\"image_height\": 640," +
Expand All @@ -58,9 +58,10 @@ public void sendPointChargeRequestReceivedMessage(String email, int point, Strin
"\"items\": [" +
"{\"item\": \"충전 요청\", \"item_op\": \"%d points\"}," +
"{\"item\": \"입금 금액\", \"item_op\": \"%d 원\"}," +
"{\"item\": \"은행\", \"item_op\": \"시니또 은행\"}," +
"{\"item\": \"계좌번호\", \"item_op\": \"3333-11-225533\"}," +
"{\"item\": \"성명\", \"item_op\": \"시니또 매니저\"}" +
"{\"item\": \"입금자명\", \"item_op\": \"%s\"}," +
"{\"item\": \"은행\", \"item_op\": \"%s\"}," +
"{\"item\": \"계좌번호\", \"item_op\": \"%s\"}," +
"{\"item\": \"성명\", \"item_op\": \"%s\"}" +
"]" +
"}," +
"\"buttons\": [" +
Expand All @@ -73,8 +74,8 @@ public void sendPointChargeRequestReceivedMessage(String email, int point, Strin
"}" +
"]" +
"}",
name, SINITTO_IMAGE_URL, kakaoProperties.frontUri(), kakaoProperties.frontUri(), point, point,
kakaoProperties.frontUri(), kakaoProperties.frontUri()
name, SINITTO_IMAGE_URL, kakaoProperties.frontUri(), kakaoProperties.frontUri(), point, point, depositMessage,
kakaoProperties.bankName(), kakaoProperties.accountNumber(), kakaoProperties.name(), kakaoProperties.frontUri(), kakaoProperties.frontUri()
);


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public PointChargeResponse savePointChargeRequest(Long memberId, int price) {

pointLogRepository.save(new PointLog(PointLog.Content.CHARGE_REQUEST.getMessage(), member, price, PointLog.Status.CHARGE_REQUEST));

kakaoMessageService.sendPointChargeRequestReceivedMessage(member.getEmail(), price, member.getName());
kakaoMessageService.sendPointChargeRequestReceivedMessage(member.getEmail(), price, member.getName(), member.getDepositMessage());

return new PointChargeResponse(member.getDepositMessage());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoSettings;
import org.springframework.beans.factory.annotation.Value;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
Expand All @@ -22,15 +21,16 @@ public class KakaoApiServiceTest {
private HttpServletRequest httpServletRequest;
@Mock
private KakaoProperties kakaoProperties;
@Value("kakao.clientId")
private String clientId;
@Value("kakao.devRedirectUri")
private String devRedirectUri;
@Value("kakao.redirectUri")
private String redirectUri;
private String clientId = "testClientId";

private String devRedirectUri = "testDevUri";

private String redirectUri = "https://testRedirectUri";

private String frontUriWithoutHttps = "testRedirectUri";

@Test
@DisplayName("getAuthorizationUrl 메소드 테스트 - devUri 포홤 시")
@DisplayName("getAuthorizationUrl 메소드 테스트 - devUri 포함 시")
void getAuthorizationUrlTestWithDevUri() {
//given
when(httpServletRequest.getHeader("Referer")).thenReturn("http://localhost:5173");
Expand All @@ -49,10 +49,11 @@ void getAuthorizationUrlTestWithDevUri() {
}

@Test
@DisplayName("getAuthorizationUrl 메소드 테스트 - 배포 uri 포홤 시")
@DisplayName("getAuthorizationUrl 메소드 테스트 - 배포 uri 포함 시")
void getAuthorizationUrlTestWithAwsUri() {
//given
when(httpServletRequest.getHeader("Referer")).thenReturn("https://dc9u22hnkwb24.cloudfront.net");
when(kakaoProperties.frontUriWithoutHttps()).thenReturn(frontUriWithoutHttps);
when(httpServletRequest.getHeader("Referer")).thenReturn("https://testRedirectUri");
when(kakaoProperties.redirectUri()).thenReturn(redirectUri);
when(kakaoProperties.clientId()).thenReturn(clientId);

Expand All @@ -72,6 +73,7 @@ void getAuthorizationUrlTestWithAwsUri() {
void getAuthorizationUrlTestWithAnotherUri() {
//given
when(httpServletRequest.getHeader("Referer")).thenReturn("http://test-uri.com");
when(kakaoProperties.frontUriWithoutHttps()).thenReturn(frontUriWithoutHttps);

//when, then
assertThrows(BadRequestException.class, () -> kakaoApiService.getAuthorizationUrl(httpServletRequest));
Expand Down

0 comments on commit 6cfe171

Please sign in to comment.