Skip to content

Commit

Permalink
Merge pull request #211 from readyvery/test
Browse files Browse the repository at this point in the history
3월 25일 배포
  • Loading branch information
1223v authored Mar 23, 2024
2 parents 0f6c15a + e73c0ab commit 2944918
Show file tree
Hide file tree
Showing 8 changed files with 152 additions and 5 deletions.
28 changes: 23 additions & 5 deletions src/main/java/com/readyvery/readyverydemo/domain/CeoInfo.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.readyvery.readyverydemo.domain;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
Expand All @@ -12,6 +15,7 @@
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
import lombok.AllArgsConstructor;
import lombok.Builder;
Expand All @@ -37,29 +41,38 @@ public class CeoInfo extends BaseTimeEntity {
@Column(nullable = false, length = 45)
private String email;

// 비밀번호
@Column(nullable = false, length = 100)
private String password;

// 닉네임
@Column(nullable = false)
private String nickName;

// 프로필 이미지
@Column(nullable = false, columnDefinition = "TEXT")
@Column(nullable = true)
private String imageUrl;

// 전화번호
@Column(nullable = false)
@Column
private String phone;

// 계좌번호
@Column
private String accountNumber;

// 유저 권한
@Column(nullable = false, columnDefinition = "VARCHAR(10) default 'USER'")
@Enumerated(EnumType.STRING)
private Role role;

// 소셜 로그인 타입
@Column(nullable = false)
@Column
@Enumerated(EnumType.STRING)
private SocialType socialType; // KAKAO, NAVER, GOOGLE

// 소셜 로그인 타입의 식별자 값 (일반 로그인인 경우 null)
@Column(nullable = false)
@Column
private String socialId; // 로그인한 소셜 타입의 식별자 값 (일반 로그인인 경우 null)

// 유저 상태
Expand All @@ -81,6 +94,11 @@ public class CeoInfo extends BaseTimeEntity {
// 사장님 가게 연관관계 매핑
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "store_idx")
private Store store;
private Store store = null;

// 사장님 입점신청서 연관관계 매핑
@Builder.Default
@OneToMany(mappedBy = "ceoInfo", cascade = CascadeType.ALL)
private List<CeoMetaInfo> ceoMetaInfos = new ArrayList<CeoMetaInfo>();

}
57 changes: 57 additions & 0 deletions src/main/java/com/readyvery/readyverydemo/domain/CeoMetaInfo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package com.readyvery.readyverydemo.domain;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;

@Getter
@NoArgsConstructor
@Entity
@Builder
@Table(name = "INFOTAINMENT")
@AllArgsConstructor
@Slf4j
public class CeoMetaInfo extends BaseTimeEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "ceo_meta_idx")
private Long id;

@Column(nullable = false, length = 45)
private String storeName;

@Column(nullable = false, length = 100)
private String storeAddress;

@Column(nullable = false, length = 45)
private String registrationNumber;

@Column(nullable = false, columnDefinition = "TEXT")
private String businessLicenseFileName;

@Column(nullable = false, columnDefinition = "TEXT")
private String businessReportFileName;

@Column(nullable = false, columnDefinition = "TEXT")
private String identityCardFileName;

@Column(nullable = false, columnDefinition = "TEXT")
private String bankAccountFileName;

// 입점신청 사장님 연관관계 매핑
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "ceo_idx")
private CeoInfo ceoInfo;

}
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ public Optional<String> extractAccessToken(HttpServletRequest request) {
public Optional<String> extractEmail(String accessToken) {
try {
// 토큰 유효성 검사하는 데에 사용할 알고리즘이 있는 JWT verifier builder 반환
log.info("액세스 토큰 유효성 검사");
return jwtTokenizer.verifyAccessToken(accessToken);
} catch (Exception e) {
log.error("액세스 토큰이 유효하지 않습니다.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ public class CurrentRes {
private String estimatedTime;
private String cancels;
private Long inout;
private Long expectPoint;
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@
import com.readyvery.readyverydemo.domain.Point;
import com.readyvery.readyverydemo.domain.Receipt;
import com.readyvery.readyverydemo.src.order.config.TossPaymentConfig;
import com.readyvery.readyverydemo.src.point.PointPolicy;

import lombok.RequiredArgsConstructor;

@Component
@RequiredArgsConstructor
public class OrderMapper {
private final TossPaymentConfig tossPaymentConfig;
private final PointPolicy pointPolicy;

public FoodyDetailRes foodieToFoodyDetailRes(Foodie foodie, Long inout) {
Long price = determinePrice(foodie, inout);
Expand Down Expand Up @@ -294,6 +296,7 @@ private ReceiptHistoryDto orderToReceiptHistoryDto(Order order) {
public CurrentRes orderToCurrentRes(Order order) {
return CurrentRes.builder()
.inout(order.getInOut())
.expectPoint(pointPolicy.calculatePoint(order.getAmount()))
.cancels(order.getReceipt().getCancels())
.name(order.getStore().getName())
.orderNum(order.getOrderNumber())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.readyvery.readyverydemo.src.point;

import org.springframework.stereotype.Service;

@Service
public class DefaultPointPolicy implements PointPolicy {
private Double pointRate = 2.5;

@Override
public Long calculatePoint(Long price) {
Double tmp = price * pointRate / 100 + 0.5; // 반올림
return tmp.longValue();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.readyvery.readyverydemo.src.point;

public interface PointPolicy {
Long calculatePoint(Long price);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.readyvery.readyverydemo.src.point;

import static org.junit.jupiter.api.Assertions.*;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.junit.jupiter.MockitoExtension;

@ExtendWith(MockitoExtension.class)
class DefaultPointPolicyTest {
@InjectMocks
private DefaultPointPolicy defaultPointPolicy;

@Test
@DisplayName("작은 금액 테스트")
void calculateSmallPoint() {
// given
Long amount = 1_050L; // 계산 금액
// when
Long point = defaultPointPolicy.calculatePoint(amount);
// then
assertEquals(26L, point);
}

@Test
@DisplayName("보통 금액 테스트")
void calculateNomalPoint() {
// given
Long amount = 10_000L; // 계산 금액
// when
Long point = defaultPointPolicy.calculatePoint(amount);
// then
assertEquals(250L, point);
}

@Test
@DisplayName("큰 금액 테스트")
void calculateBigPoint() {
// given
Long amount = 532_400L; // 계산 금액
// when
Long point = defaultPointPolicy.calculatePoint(amount);
// then
assertEquals(13_310L, point);
}
}

0 comments on commit 2944918

Please sign in to comment.