package com.talentcard.server.business.payment.huifu;
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
import java.util.HashMap;
|
import java.util.Map;
|
|
import org.junit.jupiter.api.Test;
|
|
/**
|
* A merchant onboarding application that the provider accepts for review must not be treated as a
|
* failure. The provider answers such a submission with business return code {@code 90000000}
|
* ("审核中") in the merchant onboarding return code table, which is neither {@code 00000000} nor a
|
* rejection. Parsing it as a rejection would mark a submitted application, and its settlement bank
|
* card, as rejected while the provider is still reviewing them.
|
*/
|
class HuifuOnboardingResultTests {
|
|
@Test
|
void anAcceptedApplicationUnderReviewIsNotAFailure() {
|
Map<String, Object> response = response("90000000", "审核中");
|
|
HuifuEnterpriseOnboardingGateway.Result enterprise = HuifuEnterpriseOnboardingGateway.Result.from(response);
|
assertThat(enterprise.accepted()).isTrue();
|
assertThat(enterprise.code()).isEqualTo("90000000");
|
assertThat(enterprise.huifuId()).isEqualTo("6666000123123123");
|
assertThat(enterprise.applyNo()).isEqualTo("2022012500073423");
|
// The provider issues the card token only when the application is approved.
|
assertThat(enterprise.tokenNo()).isEmpty();
|
|
Map<String, Object> individualResponse = response("90000000", "审核中");
|
HuifuIndividualOnboardingGateway.Result individual = HuifuIndividualOnboardingGateway.Result.from(individualResponse);
|
assertThat(individual.accepted()).isTrue();
|
assertThat(individual.huifuId()).isEqualTo("6666000123123123");
|
assertThat(individual.tokenNo()).isEmpty();
|
}
|
|
@Test
|
void anApprovedApplicationKeepsReturningTheMerchantNumberAndCardToken() {
|
Map<String, Object> response = response("00000000", "成功");
|
businessData(response).put("token_no", "10000713406");
|
|
HuifuEnterpriseOnboardingGateway.Result result = HuifuEnterpriseOnboardingGateway.Result.from(response);
|
assertThat(result.accepted()).isTrue();
|
assertThat(result.huifuId()).isEqualTo("6666000123123123");
|
assertThat(result.applyNo()).isEqualTo("2022012500073423");
|
assertThat(result.tokenNo()).isEqualTo("10000713406");
|
}
|
|
@Test
|
void aProviderRejectionAndAnUnknownOutcomeStayUnaccepted() {
|
HuifuEnterpriseOnboardingGateway.Result frozenSubMerchant = HuifuEnterpriseOnboardingGateway.Result.from(response("20000006", "商户状态异常"));
|
assertThat(frozenSubMerchant.accepted()).isFalse();
|
assertThat(frozenSubMerchant.code()).isEqualTo("20000006");
|
assertThat(frozenSubMerchant.message()).isEqualTo("商户状态异常");
|
|
// A business response without a business code must never be read as acceptance.
|
assertThat(HuifuIndividualOnboardingGateway.Result.from(response("", "")).accepted()).isFalse();
|
}
|
|
@Test
|
void theBusinessCodeIsReadFromTheNestedDataObject() {
|
// The mock tool and the SDK both nest the business fields under "data"; the outer gateway
|
// code is 10000 and must not decide the business outcome.
|
Map<String, Object> response = response("90000000", "审核中");
|
Map<String, Object> envelope = new HashMap<>(response);
|
envelope.put("resp_code", "10000");
|
envelope.put("resp_desc", "成功调用");
|
|
assertThat(HuifuEnterpriseOnboardingGateway.Result.from(envelope).accepted()).isTrue();
|
assertThat(HuifuEnterpriseOnboardingGateway.Result.from(envelope).code()).isEqualTo("90000000");
|
}
|
|
private Map<String, Object> response(String code, String message) {
|
Map<String, Object> response = new HashMap<>();
|
response.put("data", businessData(code, message));
|
return response;
|
}
|
|
private Map<String, Object> businessData(String code, String message) {
|
Map<String, Object> data = new HashMap<>();
|
data.put("resp_code", code);
|
data.put("resp_desc", message);
|
data.put("huifu_id", "6666000123123123");
|
data.put("apply_no", "2022012500073423");
|
return data;
|
}
|
|
/** The business fields live inside the nested {@code data} object of the provider response. */
|
@SuppressWarnings("unchecked")
|
private Map<String, Object> businessData(Map<String, Object> response) {
|
return (Map<String, Object>) response.get("data");
|
}
|
}
|