| | |
| | | |
| | | import static org.assertj.core.api.Assertions.assertThat; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.LinkedHashMap; |
| | | import java.util.Map; |
| | | |
| | | import com.talentcard.server.business.merchant.auth.MerchantPrincipal; |
| | | import org.junit.jupiter.api.BeforeEach; |
| | | import org.junit.jupiter.api.Test; |
| | |
| | | used_at timestamp |
| | | ) |
| | | """); |
| | | jdbc.execute(""" |
| | | create table merchant ( |
| | | id bigint primary key, |
| | | merchant_rights_config varchar(4000), |
| | | deleted tinyint not null default 0 |
| | | ) |
| | | """); |
| | | jdbc.execute(""" |
| | | create table merchant_store_consume_rule ( |
| | | id bigint primary key, |
| | | merchant_id bigint not null, |
| | | card_level varchar(64) not null, |
| | | rule_name varchar(128) not null, |
| | | discount_rate decimal(8, 4) not null, |
| | | subsidy_enabled tinyint not null, |
| | | status tinyint not null, |
| | | valid_start date, |
| | | valid_end date, |
| | | sort_no int not null default 0 |
| | | ) |
| | | """); |
| | | service = new ManualConsumptionService(jdbc); |
| | | principal = new MerchantPrincipal(9L, 88L, 7L, "operator"); |
| | | } |
| | |
| | | assertThat(service.consumeScannedTalentCode(principal, 3L)).isZero(); |
| | | assertThat(jdbc.queryForObject("select merchant_id from talent_dynamic_code where id = 3", Long.class)).isEqualTo(66L); |
| | | } |
| | | |
| | | @Test |
| | | void treatsLegacyPaidParkingConfigAsStoreConsumption() { |
| | | Map<String, Object> right = new LinkedHashMap<>(); |
| | | right.put("storeConsume", true); |
| | | right.put("consumeEnabled", false); |
| | | right.put("parkingType", "paid"); |
| | | |
| | | assertThat(service.configuredStoreConsumptionEnabled(right)).isTrue(); |
| | | right.put("parkingType", "free"); |
| | | assertThat(service.configuredStoreConsumptionEnabled(right)).isFalse(); |
| | | } |
| | | |
| | | @Test |
| | | void calculatesConfiguredPercentageAndFixedReductionPrices() { |
| | | Map<String, Object> dentalRight = configuredRight("卓越人才卡", ""); |
| | | dentalRight.put("consumeType", "折扣"); |
| | | dentalRight.put("consumeDiscount", "7"); |
| | | dentalRight.put("consumeDiscountSubsidy", true); |
| | | Map<String, Object> dentalAmounts = service.quote(service.configuredRule(dentalRight), null, new BigDecimal("100.00")); |
| | | assertThat(dentalAmounts).containsEntry("originalAmount", 10000L).containsEntry("payAmount", 7000L) |
| | | .containsEntry("discountAmount", 3000L).containsEntry("subsidyAmount", 3000L); |
| | | |
| | | Map<String, Object> hotelRight = configuredRight("卓越人才卡(外地)", ""); |
| | | hotelRight.put("consumeType", "优惠"); |
| | | hotelRight.put("consumeCoupon", "80"); |
| | | hotelRight.put("consumeCouponSubsidy", true); |
| | | Map<String, Object> hotelAmounts = service.quote(service.configuredRule(hotelRight), null, new BigDecimal("150.00")); |
| | | assertThat(hotelAmounts).containsEntry("originalAmount", 15000L).containsEntry("payAmount", 7000L).containsEntry("discountAmount", 8000L); |
| | | |
| | | Map<String, Object> fullyReducedAmounts = service.quote(service.configuredRule(hotelRight), null, new BigDecimal("50.00")); |
| | | assertThat(fullyReducedAmounts).containsEntry("payAmount", 0L).containsEntry("discountAmount", 5000L); |
| | | } |
| | | |
| | | @Test |
| | | void structuredRightsDoNotFallBackToLegacySeedRules() { |
| | | jdbc.update("insert into merchant(id, merchant_rights_config) values (?, ?)", 88L, |
| | | "[{\"level\":\"卓越人才卡\",\"enabled\":true,\"storeConsume\":false,\"consumeEnabled\":false}]"); |
| | | jdbc.update(""" |
| | | insert into merchant_store_consume_rule(id, merchant_id, card_level, rule_name, discount_rate, subsidy_enabled, status) |
| | | values (1, 88, 'EXCELLENT', '历史默认9折', 0.9000, 1, 1) |
| | | """); |
| | | |
| | | assertThat(service.hasApplicableRule(88L, "卓越人才卡", "OUTSIDE")).isFalse(); |
| | | } |
| | | |
| | | @Test |
| | | void matchesExcellentHotelConfigByTalentSourceArea() { |
| | | assertThat(service.matchesConfiguredLevel("卓越人才卡(外地)", "卓越人才卡", "OUTSIDE")).isTrue(); |
| | | assertThat(service.matchesConfiguredLevel("卓越人才卡(本地)", "卓越人才卡", "OUTSIDE")).isFalse(); |
| | | assertThat(service.matchesConfiguredLevel("卓越人才卡(本地)", "卓越人才卡", "LOCAL")).isTrue(); |
| | | } |
| | | |
| | | private Map<String, Object> configuredRight(String level, String discount) { |
| | | Map<String, Object> right = new LinkedHashMap<>(); |
| | | right.put("level", level); |
| | | right.put("tag", "到店消费优惠"); |
| | | right.put("discount", discount); |
| | | right.put("governmentSubsidy", true); |
| | | return right; |
| | | } |
| | | } |