shinnosuke
2026-09-18 c2f0ec3b3891bc177bdc58c2a111ab9c4fea911d
talent-card-server/src/test/java/com/talentcard/server/business/merchant/MerchantManagementServiceTests.java
@@ -86,6 +86,40 @@
                .isInstanceOf(BusinessException.class);
    }
    /**
     * 体检医院在后台团单里只有「商品名称 / 封面图 / 可预约时间 / 检查项目」,没有商品金额。
     * 商家端照这套字段保存时:可预约时间要落到 purchase_notice.validPeriod,金额允许为空并按 0(免费)落库。
     */
    @Test
    void savesHealthCheckProductWithoutPriceAndKeepsReservationWindow() {
        jdbc.update("update merchant set merchant_type_code = 'medical' where id = ?", merchantId);
        Long productId = jdbc.queryForObject("select id from merchant_product where merchant_id = ? and product_no like 'MANAGEMENT-ONLINE-%'", Long.class, merchantId);
        Map<String, Object> updated = service.updateProduct(principal, productId, new MerchantProductUpdateRequest(
                "查血", null, "https://example.com/cover.jpg", List.of(),
                "[{\"name\":\"查血\",\"meaning\":\"检查血脂\",\"gender\":[\"男\",\"女\"]}]",
                Map.of("validPeriod", "2026-09-16 至 2026-09-18")
        ));
        assertThat(updated).containsEntry("merchantTypeCode", "medical");
        assertThat((BigDecimal) updated.get("salePrice")).isEqualByComparingTo(BigDecimal.ZERO);
        assertThat((Map<String, String>) updated.get("purchaseNotice"))
                .containsEntry("validPeriod", "2026-09-16 至 2026-09-18");
        Map<String, Object> detail = service.product(principal, productId);
        assertThat(String.valueOf(detail.get("detailText"))).contains("检查血脂");
    }
    /** 非体检医院仍然要有商品金额:商家端少了金额字段时不能静默按免费存下去。 */
    @Test
    void rejectsMissingPriceForNonHealthCheckMerchant() {
        Long productId = jdbc.queryForObject("select id from merchant_product where merchant_id = ? and product_no like 'MANAGEMENT-ONLINE-%'", Long.class, merchantId);
        assertThatThrownBy(() -> service.updateProduct(principal, productId, new MerchantProductUpdateRequest(
                "普通商品", null, "https://example.com/cover.jpg", List.of("https://example.com/product-1.jpg"),
                "图文详情", Map.of()
        ))).isInstanceOf(BusinessException.class).hasMessageContaining("商品金额");
    }
    private void insertProduct(String marker, int status, int auditStatus) {
        jdbc.update("""
                insert into merchant_product(merchant_id, product_no, product_type, product_name, cover_url, original_price, sale_price,