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

[#22][TEST] application layer test #27

Merged
merged 7 commits into from
May 17, 2024
Merged
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 @@ -8,6 +8,7 @@
import com.moin.remittance.domain.dto.remittance.v2.*;
import com.moin.remittance.domain.dto.requestparams.RemittanceQuoteRequestParamsDTO;

import com.moin.remittance.domain.entity.remittance.v2.RemittanceQuoteEntityV2;
import com.moin.remittance.exception.NullPointerQuotationException;

import com.moin.remittance.repository.v2.MemberRepositoryV2;
Expand Down Expand Up @@ -61,10 +62,10 @@ public RemittanceQuoteResponseV2DTO getRemittanceQuoteV2(long sourceAmount, Stri
ExchangeRateInfoDTO targetExRateDTO = exchangeRateInfoHashMap.get(targetCurrency); // target currency

// 2. ์†ก๊ธˆ ๊ฒฌ์ ์„œ ์ฐ์–ด๋‚ด๊ธฐ
RemittanceQuoteV2DTO remittanceQuoteDTO = quotation.createQuotation(sourceAmount, usdExRateDTO, targetExRateDTO, userId);
RemittanceQuoteEntityV2 remittanceQuoteEntity = quotation.createQuotation(sourceAmount, usdExRateDTO, targetExRateDTO, userId);

// 3. ์†ก๊ธˆ ๊ฒฌ์ ์„œ ์ €์žฅ(DB) -> ์†ก๊ธˆ ๊ฒฌ์ ์„œ ๋ฆฌํ„ด
return RemittanceQuoteResponseV2DTO.of(remittanceRepositoryV2.saveAndFlush(remittanceQuoteDTO.toEntity(remittanceQuoteDTO)));
return RemittanceQuoteResponseV2DTO.of(remittanceRepositoryV2.saveAndFlush(remittanceQuoteEntity));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

import com.moin.remittance.domain.dto.remittance.v2.ExchangeRateInfoDTO;
import com.moin.remittance.domain.dto.remittance.v2.RemittanceQuoteV2DTO;
import com.moin.remittance.domain.entity.remittance.v2.RemittanceQuoteEntityV2;
import com.moin.remittance.exception.NegativeNumberException;
import org.springframework.stereotype.Component;

@Component
public record Quotation(QuotationOffice quotationOffice, QuotationFactory quotationFactory) {

public RemittanceQuoteV2DTO createQuotation(long sourceAmount, ExchangeRateInfoDTO usd, ExchangeRateInfoDTO target, String userId) throws NegativeNumberException {
public RemittanceQuoteEntityV2 createQuotation(long sourceAmount, ExchangeRateInfoDTO usd, ExchangeRateInfoDTO target, String userId) throws NegativeNumberException {
return quotationFactory.estimating(sourceAmount, usd, target, userId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.moin.remittance.application.v2.transfer.impl.estimating.policy.FeePolicyFactory;
import com.moin.remittance.domain.dto.remittance.v2.ExchangeRateInfoDTO;
import com.moin.remittance.domain.dto.remittance.v2.RemittanceQuoteV2DTO;
import com.moin.remittance.domain.entity.remittance.v2.RemittanceQuoteEntityV2;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

Expand All @@ -27,10 +28,10 @@ public class QuotationFactory {
* @param usd USD ํ™˜์œจ ์ •๋ณด
* @param target ํƒ€๊ฒŸ ํ†ตํ™” ํ™˜์œจ ์ •๋ณด
*/
public RemittanceQuoteV2DTO estimating(long sourceAmount, ExchangeRateInfoDTO usd, ExchangeRateInfoDTO target, String userId) {
public RemittanceQuoteEntityV2 estimating(long sourceAmount, ExchangeRateInfoDTO usd, ExchangeRateInfoDTO target, String userId) {
BigDecimal fee = feePolicyFactory.getAppliedFeeFromPolicy(sourceAmount);

return RemittanceQuoteV2DTO.builder()// ์†ก๊ธˆ ๊ฒฌ์ ์„œ DTO
return RemittanceQuoteEntityV2.builder()// ์†ก๊ธˆ ๊ฒฌ์ ์„œ DTO
.sourceAmount(sourceAmount) // ์›ํ™”
.fee(fee) // ์ˆ˜์ˆ˜๋ฃŒ
.usdExchangeRate(usd.getBasePrice()) // USD ํ™˜์œจ
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
import com.moin.remittance.domain.entity.member.v2.MemberEntityV2;
import com.moin.remittance.exception.DuplicateUserIdException;
import com.moin.remittance.exception.InValidPatternTypeException;
import com.moin.remittance.exception.NotFoundMemberException;
import com.moin.remittance.domain.dto.member.MemberDTO;
import com.moin.remittance.application.v2.user.MemberServiceV2;
import com.moin.remittance.repository.v2.MemberRepositoryV2;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;

Expand All @@ -22,11 +20,10 @@
@Service
@RequiredArgsConstructor
public class MemberServiceImplV2 implements MemberServiceV2 {

private final MemberRepositoryV2 memberRepositoryV2;
private final BCryptPasswordEncoder bCryptPasswordEncoder;

@Value("${jwt.token.secret}")
private String key;

@Override
public void saveUser(MemberDTO member) {
Expand All @@ -38,14 +35,14 @@ public void saveUser(MemberDTO member) {
Pattern businessPattern = Pattern.compile(BUSINESS_NUMBER_REGEX);

Matcher targetMatcher;
switch (member.getIdType()) { // type ๋งค์นญ -> ํŒจํ„ด ์ฒดํฌ
case "reg_no":
switch (member.getIdType().toUpperCase()) { // type ๋งค์นญ -> ํŒจํ„ด ์ฒดํฌ
case "REG_NO":
targetMatcher = residentPattern.matcher(member.getIdValue());
if (!targetMatcher.matches()) {
throw new InValidPatternTypeException(BAD_INDIVIDUAL_MEMBER_INVALID_ID_VALUE);
}
break;
case "business_no":
case "BUSINESS_NO":
targetMatcher = businessPattern.matcher(member.getIdValue());
if (!targetMatcher.matches()) {
throw new InValidPatternTypeException(BAD_CORPORATION_MEMBER_INVALID_ID_VALUE);
Expand All @@ -63,12 +60,15 @@ public void saveUser(MemberDTO member) {
}

// 3. ๋น„๋ฐ€๋ฒˆํ˜ธ, ์ฃผ๋ฏผ๋“ฑ๋ก๋ฒˆํ˜ธ or ์‚ฌ์—…์ž๋“ฑ๋ก๋ฒˆํ˜ธ ์•”ํ˜ธํ™”ํ•ด์„œ ์ €์žฅ
memberRepositoryV2.saveAndFlush(MemberEntityV2.builder()
.userId(member.getUserId())
.password(bCryptPasswordEncoder.encode(member.getPassword()))
.name(member.getName())
.idType(member.getIdType())
.idValue(bCryptPasswordEncoder.encode(member.getIdValue()))
.build());
memberRepositoryV2.saveAndFlush(
MemberEntityV2.builder()
.userId(member.getUserId())
.password(bCryptPasswordEncoder.encode(member.getPassword()))
.name(member.getName())
.idType(member.getIdType())
.idValue(bCryptPasswordEncoder.encode(member.getIdValue()))
.build()
);

}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.moin.remittance.domain.dto.remittance.v2;

import lombok.*;
import lombok.Data;

import java.math.BigDecimal;
import java.time.OffsetDateTime;
Expand Down Expand Up @@ -32,4 +32,20 @@ public class RemittanceHistoryV2DTO {

// ์†ก๊ธˆ ์ ‘์ˆ˜ ์š”์ฒญ ๋‚ ์งœ
private OffsetDateTime requestedDate;

/* Test data ๋ชจ๋‹ˆํ„ฐ๋ง */
@Override
public String toString() {
return "\t\t\n{" + "\n" +
"\tsourceAmount: " + sourceAmount + ",\n" +
"\tfee: " + fee + ",\n" +
"\tusdExchangeRate: " + usdExchangeRate + ",\n" +
"\tusdAmount: " + usdAmount + ",\n" +
"\ttargetCurrency: " + targetCurrency + "\n" +
"\texchangeRate: " + exchangeRate + "\n" +
"\ttargetAmount: " + targetAmount + "\n" +
"\tuserId: " + userId + "\n" +
"\trequestedDate: " + requestedDate + "\n" +
"}";
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.moin.remittance.domain.dto.remittance.v2;


import lombok.Builder;
import lombok.Getter;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.List;

@Getter
Expand All @@ -15,4 +15,15 @@ public class TransactionLogV2DTO {
private int todayTransferCount;
private BigDecimal todayTransferUsdAmount;
private List<RemittanceHistoryV2DTO> history;

@Override
public String toString() {
return "RemittanceLogEntityV2 {" + "\n" +
"\tuserId: " + userId + ",\n" +
"\tname: " + name + ",\n" +
"\ttodayTransferCount: " + todayTransferCount + ",\n" +
"\ttodayTransferUsdAmount: " + todayTransferUsdAmount + ",\n" +
"\thistory: \n" + history + "\n" +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.lang.reflect.Member;
import java.util.UUID;

@Repository
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
package com.moin.remittance;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.test.context.junit.jupiter.SpringExtension;

@SpringBootTest
@EnableJpaRepositories(basePackages = "com.moin.remittance.repository")
Expand Down

This file was deleted.

Loading