Skip to content

Commit

Permalink
feat: 쿠폰 대기열 사이즈를 반환하는 기능 구현 및 테스트
Browse files Browse the repository at this point in the history
  • Loading branch information
hongdosan committed Nov 28, 2023
1 parent b734916 commit 5c55268
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,18 @@ public void addIfAbsentQueue(String couponName, Long memberId, double registerTi
);
}

public Set<Long> range(String key, long start, long end) {
public Set<Long> range(String couponName, long start, long end) {
return zSetRedisRepository
.range(requireNonNull(key), start, end)
.range(requireNonNull(couponName), start, end)
.stream()
.map(Long.class::cast)
.collect(Collectors.toSet());
}

public Long queueSize(String couponName) {
return zSetRedisRepository.size(requireNonNull(couponName));
}

public void deleteQueue(String couponName) {
valueRedisRepository.delete(requireNonNull(couponName));
}
Expand All @@ -51,17 +55,6 @@ public int increaseIssuedStock(String couponName) {
.intValue();
}

public int getIssuedStock(String couponName) {
String stockKey = String.format(STOCK_KEY, requireNonNull(couponName));
String stockValue = valueRedisRepository.get(requireNonNull(stockKey));

if (stockValue == null) {
return 0;
}

return Integer.parseInt(stockValue);
}

public void deleteIssuedStock(String couponName) {
String stockKey = String.format(STOCK_KEY, requireNonNull(couponName));
valueRedisRepository.delete(requireNonNull(stockKey));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ void sendCouponIssueResult_fcmToken_null() {
notificationService.sendCouponIssueResult(1L, "couponName", SUCCESS_ISSUE_BODY);

// Then
verify(fcmService).sendAsync(any(String.class), any(String.class));
verify(fcmService).sendAsync(isNull(), any(String.class));
}

@DisplayName("특정 인증 시간에 해당하는 방 사용자들에게 알림을 성공적으로 보낸다. - Void")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,27 @@ void range_NullPointerException() {
.isInstanceOf(NullPointerException.class);
}

@DisplayName("대기열의 사이즈를 성공적으로 반환한다. - Long")
@Test
void queueSize_success() {
// Given
given(zSetRedisRepository.size(any(String.class))).willReturn(2L);

// When
Long actual = couponManageRepository.queueSize("CouponName");

// Then
assertThat(actual).isEqualTo(2L);
}

@DisplayName("쿠폰명이 Null인 대기열의 사이즈를 반환한다. - NullPointerException")
@Test
void queueSize_NullPointerException() {
// When & Then
assertThatThrownBy(() -> couponManageRepository.queueSize(null))
.isInstanceOf(NullPointerException.class);
}

@DisplayName("쿠폰 대기열을 성공적으로 삭제한다. - Void")
@Test
void deleteQueue_success() {
Expand Down Expand Up @@ -117,40 +138,6 @@ void increaseIssuedStock_NullPointerException() {
.isInstanceOf(NullPointerException.class);
}

@DisplayName("쿠폰의 현재 할당된 재고를 성공적으로 조회한다. - int")
@Test
void getIssuedStock_success() {
// Given
given(valueRedisRepository.get(any(String.class))).willReturn("1");

// When
int actual = couponManageRepository.getIssuedStock("couponName");

// Then
assertThat(actual).isEqualTo(1);
}

@DisplayName("쿠폰의 현재 할당된 재고가 없어서 0이 조회된다. - int")
@Test
void getIssuedStock_zero() {
// Given
given(valueRedisRepository.get(any(String.class))).willReturn(null);

// When
int actual = couponManageRepository.getIssuedStock("couponName");

// Then
assertThat(actual).isZero();
}

@DisplayName("쿠폰명이 Null인 쿠폰의 할당된 재고를 조회한다. - NullPointerException")
@Test
void getIssuedStock_NullPointerException() {
// When & Then
assertThatThrownBy(() -> couponManageRepository.getIssuedStock(null))
.isInstanceOf(NullPointerException.class);
}

@DisplayName("할당된 쿠폰 재고를 성공적으로 삭제한다. - Void")
@Test
void deleteIssuedStock_success() {
Expand Down

0 comments on commit 5c55268

Please sign in to comment.