fix(finance): expose sample recharge QR in dev

This commit is contained in:
2026-09-05 08:56:02 +08:00
parent cf955477d8
commit 3df6fb511f
4 changed files with 31 additions and 6 deletions
+2 -2
View File
@@ -5,5 +5,5 @@ spring:
password: ${FINANCE_DB_PASSWORD} password: ${FINANCE_DB_PASSWORD}
driver-class-name: com.mysql.cj.jdbc.Driver driver-class-name: com.mysql.cj.jdbc.Driver
baiyue.clients.warehouse.url: ${WAREHOUSE_SERVICE_URL:} baiyue.clients.warehouse.url: ${WAREHOUSE_SERVICE_URL:}
baiyue.finance.recharge.wechat-qr-code-url: ${FINANCE_RECHARGE_WECHAT_QR_CODE_URL:/customer-recharge-qr.svg} baiyue.finance.recharge.wechat-qr-code-url: ${FINANCE_RECHARGE_WECHAT_QR_CODE_URL:}
baiyue.finance.recharge.alipay-qr-code-url: ${FINANCE_RECHARGE_ALIPAY_QR_CODE_URL:/customer-recharge-qr.svg} baiyue.finance.recharge.alipay-qr-code-url: ${FINANCE_RECHARGE_ALIPAY_QR_CODE_URL:}
@@ -55,14 +55,22 @@ public class FinanceWalletService {
FinanceDocumentNumberGenerator numberGenerator, FinanceDocumentNumberGenerator numberGenerator,
@Value("${baiyue.security.internal-service-token:}") String internalToken, @Value("${baiyue.security.internal-service-token:}") String internalToken,
@Value("${baiyue.finance.recharge.wechat-qr-code-url:}") String wechatQrCodeUrl, @Value("${baiyue.finance.recharge.wechat-qr-code-url:}") String wechatQrCodeUrl,
@Value("${baiyue.finance.recharge.alipay-qr-code-url:}") String alipayQrCodeUrl) { @Value("${baiyue.finance.recharge.alipay-qr-code-url:}") String alipayQrCodeUrl,
@Value("${spring.profiles.active:}") String activeProfiles) {
this.jdbc = jdbc; this.jdbc = jdbc;
this.objectMapper = objectMapper; this.objectMapper = objectMapper;
this.fileClient = fileClient; this.fileClient = fileClient;
this.numberGenerator = numberGenerator; this.numberGenerator = numberGenerator;
this.internalToken = internalToken; this.internalToken = internalToken;
this.wechatQrCodeUrl = blankToNull(wechatQrCodeUrl); boolean development = List.of(activeProfiles.split(",")).stream()
this.alipayQrCodeUrl = blankToNull(alipayQrCodeUrl); .map(String::trim).anyMatch("dev"::equalsIgnoreCase);
this.wechatQrCodeUrl = rechargeQrCode(wechatQrCodeUrl, development);
this.alipayQrCodeUrl = rechargeQrCode(alipayQrCodeUrl, development);
}
private static String rechargeQrCode(String configured, boolean development) {
String value = blankToNull(configured);
return value == null && development ? "/customer-recharge-qr.svg" : value;
} }
public WalletAccount account(long customerId) { public WalletAccount account(long customerId) {
@@ -4,3 +4,9 @@ spring:
url: ${FINANCE_DB_URL:jdbc:mysql://127.0.0.1:3306/baiyue_finance?useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true} url: ${FINANCE_DB_URL:jdbc:mysql://127.0.0.1:3306/baiyue_finance?useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true}
username: ${FINANCE_DB_USERNAME:root} username: ${FINANCE_DB_USERNAME:root}
password: ${FINANCE_DB_PASSWORD:123456} password: ${FINANCE_DB_PASSWORD:123456}
baiyue:
finance:
recharge:
wechat-qr-code-url: ${FINANCE_RECHARGE_WECHAT_QR_CODE_URL:/customer-recharge-qr.svg}
alipay-qr-code-url: ${FINANCE_RECHARGE_ALIPAY_QR_CODE_URL:/customer-recharge-qr.svg}
@@ -44,6 +44,17 @@ class FinanceWalletBehaviorTest {
alipay -> { assertThat(alipay.paymentMethod()).isEqualTo("ALIPAY"); assertThat(alipay.enabled()).isFalse(); }); alipay -> { assertThat(alipay.paymentMethod()).isEqualTo("ALIPAY"); assertThat(alipay.enabled()).isFalse(); });
} }
@Test
void developmentProfileUsesTheNonPayableSampleQrCode() {
var channels = new FinanceWalletService(mock(JdbcTemplate.class), new ObjectMapper().findAndRegisterModules(),
mock(FinanceFileClient.class), mock(FinanceDocumentNumberGenerator.class), "token", "", "", "dev").channels();
assertThat(channels).allSatisfy(channel -> {
assertThat(channel.enabled()).isTrue();
assertThat(channel.qrCodeUrl()).isEqualTo("/customer-recharge-qr.svg");
});
}
@Test @Test
void manualDeductionCannotExceedAvailableBalance() throws Exception { void manualDeductionCannotExceedAvailableBalance() throws Exception {
JdbcTemplate jdbc = mock(JdbcTemplate.class); JdbcTemplate jdbc = mock(JdbcTemplate.class);
@@ -72,6 +83,6 @@ class FinanceWalletBehaviorTest {
private static FinanceWalletService service(JdbcTemplate jdbc, String wechat, String alipay) { private static FinanceWalletService service(JdbcTemplate jdbc, String wechat, String alipay) {
return new FinanceWalletService(jdbc, new ObjectMapper().findAndRegisterModules(), return new FinanceWalletService(jdbc, new ObjectMapper().findAndRegisterModules(),
mock(FinanceFileClient.class), mock(FinanceDocumentNumberGenerator.class), "token", wechat, alipay); mock(FinanceFileClient.class), mock(FinanceDocumentNumberGenerator.class), "token", wechat, alipay, "test");
} }
} }