feat(M08-B): 补保洁微信转账回调与轮询
This commit is contained in:
@@ -51,6 +51,59 @@ const actor = {
|
||||
assert.equal(harness.repository.paid.length, 0);
|
||||
}
|
||||
|
||||
{
|
||||
const harness = createHarness({ queryState: 'SUCCESS' });
|
||||
const result = await harness.service.syncWechatTransfer({
|
||||
...actor,
|
||||
settlementId: '501',
|
||||
note: 'poll success'
|
||||
});
|
||||
assert.equal(result.transferState, 'SUCCESS');
|
||||
assert.equal(harness.state.queryOutBillNo, 'CLS-20260627-501');
|
||||
assert.equal(harness.repository.paid[0].payoutReference, 'wx-transfer-query-501');
|
||||
}
|
||||
|
||||
{
|
||||
const harness = createHarness({ queryState: 'FAIL', queryFailReason: 'ACCOUNT_ABNORMAL' });
|
||||
const result = await harness.service.syncWechatTransfer({
|
||||
...actor,
|
||||
settlementId: '501'
|
||||
});
|
||||
assert.equal(result.transferState, 'FAIL');
|
||||
assert.equal(harness.repository.failures[0].error, 'ACCOUNT_ABNORMAL');
|
||||
}
|
||||
|
||||
{
|
||||
const harness = createHarness({ queryState: 'PROCESSING' });
|
||||
const result = await harness.service.syncWechatTransfer({
|
||||
...actor,
|
||||
settlementId: '501'
|
||||
});
|
||||
assert.equal(result.transferState, 'PROCESSING');
|
||||
assert.equal(harness.repository.pending[0].payoutState, 'PROCESSING');
|
||||
}
|
||||
|
||||
{
|
||||
const harness = createHarness({
|
||||
notificationPayload: {
|
||||
mch_id: '1900000109',
|
||||
out_bill_no: 'CLS-20260627-501',
|
||||
transfer_bill_no: 'wx-notify-501',
|
||||
state: 'SUCCESS'
|
||||
}
|
||||
});
|
||||
const result = await harness.service.processWechatTransferNotification({
|
||||
timestamp: '1782700000',
|
||||
nonce: 'notify-nonce',
|
||||
serial: 'PLATFORM-SERIAL',
|
||||
signature: 'signature'
|
||||
}, '{"resource":"encrypted"}', 'notify-trace');
|
||||
assert.equal(result.transferState, 'SUCCESS');
|
||||
assert.equal(harness.state.verifiedNotification.rawBody, '{"resource":"encrypted"}');
|
||||
assert.equal(harness.repository.paid[0].tenantId, '7');
|
||||
assert.equal(harness.repository.paid[0].payoutReference, 'wx-notify-501');
|
||||
}
|
||||
|
||||
{
|
||||
const harness = createHarness({ transferState: 'FAIL', failReason: 'REAL_NAME_CHECK_FAILED' });
|
||||
const result = await harness.service.executeWechatTransfer({
|
||||
@@ -89,6 +142,7 @@ const actor = {
|
||||
function createHarness(options = {}) {
|
||||
const state = {
|
||||
transferInput: null,
|
||||
queryOutBillNo: null,
|
||||
settlement: {
|
||||
id: '501',
|
||||
settlementNo: 'CLS-20260627-501',
|
||||
@@ -96,8 +150,10 @@ function createHarness(options = {}) {
|
||||
storeId: '11',
|
||||
status: options.status ?? 'CONFIRMED',
|
||||
totalRewardCents: 1200,
|
||||
payoutReference: '',
|
||||
payoutState: ''
|
||||
payoutChannel: options.payoutChannel ?? 'WECHAT_TRANSFER',
|
||||
payoutReference: options.payoutReference ?? 'CLS-20260627-501',
|
||||
payoutState: options.payoutState ?? 'WAIT_USER_CONFIRM',
|
||||
payoutPackageInfo: options.payoutPackageInfo ?? 'package-info'
|
||||
},
|
||||
account: {
|
||||
id: '41',
|
||||
@@ -110,6 +166,9 @@ function createHarness(options = {}) {
|
||||
};
|
||||
const pool = {
|
||||
async execute(sql) {
|
||||
if (sql.includes("payout_channel = 'WECHAT_TRANSFER'")) {
|
||||
return [[{ ...state.settlement, tenantId: '7' }], []];
|
||||
}
|
||||
if (sql.includes('FROM qipai_cleaning_settlements')) {
|
||||
return [[state.settlement], []];
|
||||
}
|
||||
@@ -149,6 +208,21 @@ function createHarness(options = {}) {
|
||||
failReason: options.failReason ?? '',
|
||||
packageInfo: options.packageInfo ?? ''
|
||||
};
|
||||
},
|
||||
async queryMerchantTransferByOutBillNo(_credential, outBillNo) {
|
||||
state.queryOutBillNo = outBillNo;
|
||||
return {
|
||||
merchantId: options.queryMerchantId ?? '1900000109',
|
||||
outBillNo,
|
||||
transferBillNo: 'wx-transfer-query-501',
|
||||
state: options.queryState ?? 'SUCCESS',
|
||||
failReason: options.queryFailReason ?? '',
|
||||
amountCents: options.queryAmountCents ?? 1200
|
||||
};
|
||||
},
|
||||
verifyAndDecrypt(_credential, headers, rawBody) {
|
||||
state.verifiedNotification = { headers, rawBody };
|
||||
return options.notificationPayload ?? {};
|
||||
}
|
||||
};
|
||||
const credential = {
|
||||
@@ -157,7 +231,7 @@ function createHarness(options = {}) {
|
||||
serialNo: 'serial',
|
||||
privateKeyPem: 'private-key',
|
||||
apiV3Key: '0123456789abcdef0123456789abcdef',
|
||||
platformCertificates: {},
|
||||
platformCertificates: { 'PLATFORM-SERIAL': 'certificate' },
|
||||
transferSceneId: '1000',
|
||||
transferSceneReportInfos: [{ infoType: '岗位类型', infoContent: '保洁员' }]
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user