|
|
@@ -0,0 +1,83 @@
|
|
|
+package com.etotem.cfc.unit;
|
|
|
+
|
|
|
+import com.etotem.cfc.dto.RecommendItemVO;
|
|
|
+import com.etotem.cfc.entity.DeviceMaintenanceReminder;
|
|
|
+import com.etotem.cfc.service.K8RecommendationBoostService;
|
|
|
+import org.junit.jupiter.api.Test;
|
|
|
+
|
|
|
+import java.sql.Date;
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+import static org.junit.jupiter.api.Assertions.*;
|
|
|
+
|
|
|
+/**
|
|
|
+ * TDD 契约:换滤芯期商品置顶(spec §5.2)。
|
|
|
+ */
|
|
|
+class K8FilterRecommendationTest {
|
|
|
+
|
|
|
+ private final K8RecommendationBoostService svc = new K8RecommendationBoostService();
|
|
|
+
|
|
|
+ private RecommendItemVO item(Long id, int score) {
|
|
|
+ RecommendItemVO v = new RecommendItemVO();
|
|
|
+ v.setId(id);
|
|
|
+ v.setRecommendScore(score);
|
|
|
+ return v;
|
|
|
+ }
|
|
|
+
|
|
|
+ private DeviceMaintenanceReminder filterReminder() {
|
|
|
+ DeviceMaintenanceReminder r = new DeviceMaintenanceReminder();
|
|
|
+ r.setServiceType("replace_filter");
|
|
|
+ r.setBuyerId(54L);
|
|
|
+ r.setFamilyId(57L);
|
|
|
+ r.setDueDate(Date.valueOf(LocalDate.of(2027, 6, 26)));
|
|
|
+ r.setWindowStartDate(Date.valueOf(LocalDate.of(2027, 6, 19)));
|
|
|
+ r.setStatus("pending");
|
|
|
+ return r;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void window_inserts_filter_top_and_exempts_purchased() {
|
|
|
+ // 普通项分数最高 900;滤芯 id=7 因已购被排除在输入外 → 应被强插并置顶
|
|
|
+ List<RecommendItemVO> items = new ArrayList<>(Arrays.asList(item(1L, 900), item(2L, 800)));
|
|
|
+ List<RecommendItemVO> result = svc.applyFilterMaintenanceBoost(
|
|
|
+ items, Arrays.asList(filterReminder()), 7L, 1000, "还原水机滤芯");
|
|
|
+ assertEquals(3, result.size(), "滤芯应被强插(豁免已购去重)");
|
|
|
+ assertEquals(7L, result.get(0).getId(), "滤芯应置顶第1位");
|
|
|
+ assertTrue(result.get(0).getRecommendScore() > 900, "滤芯分应高于所有普通项");
|
|
|
+ assertTrue(result.get(0).getRecommendReason().contains("2027-06-26"), "推荐理由含到期日");
|
|
|
+ assertEquals("滤芯更换提醒", result.get(0).getBadge());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void already_present_filter_is_promoted_not_duplicated() {
|
|
|
+ List<RecommendItemVO> items = new ArrayList<>(Arrays.asList(item(1L, 900), item(7L, 10)));
|
|
|
+ List<RecommendItemVO> result = svc.applyFilterMaintenanceBoost(
|
|
|
+ items, Arrays.asList(filterReminder()), 7L, 1000, "还原水机滤芯");
|
|
|
+ assertEquals(2, result.size(), "不应重复插入");
|
|
|
+ assertEquals(7L, result.get(0).getId(), "已存在的滤芯应被提权置顶");
|
|
|
+ assertTrue(result.get(0).getRecommendScore() > 900);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void no_window_no_change() {
|
|
|
+ List<RecommendItemVO> items = new ArrayList<>(Arrays.asList(item(1L, 900), item(2L, 800)));
|
|
|
+ List<RecommendItemVO> result = svc.applyFilterMaintenanceBoost(
|
|
|
+ items, new ArrayList<>(), 7L, 1000, "还原水机滤芯");
|
|
|
+ assertEquals(2, result.size());
|
|
|
+ assertEquals(1L, result.get(0).getId(), "窗口外保持原序");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void only_replace_filter_type_triggers() {
|
|
|
+ DeviceMaintenanceReminder wash = new DeviceMaintenanceReminder();
|
|
|
+ wash.setServiceType("wash_machine");
|
|
|
+ List<RecommendItemVO> items = new ArrayList<>(Arrays.asList(item(1L, 900)));
|
|
|
+ List<RecommendItemVO> result = svc.applyFilterMaintenanceBoost(
|
|
|
+ items, Arrays.asList(wash), 7L, 1000, "还原水机滤芯");
|
|
|
+ assertEquals(1, result.size());
|
|
|
+ assertEquals(1L, result.get(0).getId(), "洗机提醒不触发滤芯置顶");
|
|
|
+ }
|
|
|
+}
|