Skip to content

Commit e1a1921

Browse files
committed
test: 상품 조회 기능 테스트 추가
캐시, 커서 페이징, 인기 상품 기능에 대한 테스트 추가 - ProductReadServiceTest: 상품 조회 서비스 단위 테스트 - ProductRepositoryImplTest: 커서 페이징 레포지토리 통합 테스트 - ProductV1ApiE2ETest: 커서 페이징, 인기 상품 E2E 테스트 추가 - InMemoryProductRepository: 커서 페이징 및 인기 상품 조회 메서드 구현 - InMemoryMemberRepository: findByIdIn 메서드 추가
1 parent 7339613 commit e1a1921

5 files changed

Lines changed: 1084 additions & 1 deletion

File tree

apps/commerce-api/src/test/java/com/loopers/domain/members/InMemoryMemberRepository.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ public boolean existsByMemberId(String memberId) {
2525
return store.containsKey(memberId);
2626
}
2727

28+
@Override
29+
public boolean existsById(Long id) {
30+
return store.values().stream()
31+
.anyMatch(member -> member.getId().equals(id));
32+
}
33+
2834
public void clear() {
2935
store.clear();
3036
}

apps/commerce-api/src/test/java/com/loopers/domain/product/InMemoryProductRepository.java

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ public Page<Product> findAll(ProductSearchFilter condition, Pageable pageable) {
3838
return new PageImpl<>(allProducts, pageable, allProducts.size());
3939
}
4040

41+
@Override
42+
public List<Product> findAllByCursor(ProductSearchFilter filter, String cursor, int size) {
43+
// 간단한 구현: 커서는 무시하고 size만큼 반환
44+
return store.values().stream()
45+
.limit(size + 1)
46+
.collect(Collectors.toList());
47+
}
48+
4149
@Override
4250
public Product save(Product product) {
4351
if (product.getId() == null) {
@@ -92,6 +100,45 @@ public int decrementLikeCount(Long productId) {
92100
return 1;
93101
}
94102

103+
@Override
104+
public int updateLikeCount(Long productId, long count) {
105+
Product product = store.get(productId);
106+
if (product == null) {
107+
return 0;
108+
}
109+
product.setLikeCount((int) count);
110+
return 1;
111+
}
112+
113+
@Override
114+
public List<Product> findTopByLikeCount(int limit) {
115+
return store.values().stream()
116+
.sorted((p1, p2) -> {
117+
int likeCompare = Integer.compare(p2.getLikeCount(), p1.getLikeCount());
118+
if (likeCompare != 0) {
119+
return likeCompare;
120+
}
121+
return Long.compare(p2.getId(), p1.getId());
122+
})
123+
.limit(limit)
124+
.collect(Collectors.toList());
125+
}
126+
127+
@Override
128+
public List<Product> findTopByBrandIdAndLikeCount(Long brandId, int limit) {
129+
return store.values().stream()
130+
.filter(product -> product.getBrandId().equals(brandId))
131+
.sorted((p1, p2) -> {
132+
int likeCompare = Integer.compare(p2.getLikeCount(), p1.getLikeCount());
133+
if (likeCompare != 0) {
134+
return likeCompare;
135+
}
136+
return Long.compare(p2.getId(), p1.getId());
137+
})
138+
.limit(limit)
139+
.collect(Collectors.toList());
140+
}
141+
95142
public void clear() {
96143
store.clear();
97144
sequence = 0L;
@@ -105,4 +152,4 @@ public Product saveWithId(Long id, Product product) {
105152
}
106153
return productWithId;
107154
}
108-
}
155+
}

0 commit comments

Comments
 (0)