feat(cleaning): close settlement integrity and reconciliation
This commit is contained in:
@@ -60,6 +60,8 @@ const actor = {
|
||||
mode: 'API'
|
||||
});
|
||||
assert.equal(result.transferState, 'SUCCESS');
|
||||
assert.equal(harness.repository.begun.length, 1);
|
||||
assert.equal(harness.repository.begun[0].payoutReference, 'CLP501');
|
||||
assert.equal(harness.repository.paid[0].payoutChannel, 'WECHAT_TRANSFER');
|
||||
assert.equal(harness.state.transferInput.amountCents, 1200);
|
||||
assert.equal(harness.state.transferInput.openid, 'openid-cleaner');
|
||||
@@ -79,6 +81,20 @@ const actor = {
|
||||
assert.equal(harness.repository.paid.length, 0);
|
||||
}
|
||||
|
||||
{
|
||||
const harness = createHarness({ payoutState: 'PROCESSING' });
|
||||
await assert.rejects(
|
||||
() => harness.service.executeWechatTransfer({
|
||||
...actor,
|
||||
settlementId: '501',
|
||||
mode: 'API'
|
||||
}),
|
||||
(error) => error instanceof CleaningPayoutError
|
||||
&& error.code === 'CLEANING_PAYOUT_ALREADY_STARTED'
|
||||
);
|
||||
assert.equal(harness.repository.begun.length, 0);
|
||||
}
|
||||
|
||||
{
|
||||
const harness = createHarness({ queryState: 'SUCCESS' });
|
||||
const result = await harness.service.syncWechatTransfer({
|
||||
@@ -87,7 +103,7 @@ const actor = {
|
||||
note: 'poll success'
|
||||
});
|
||||
assert.equal(result.transferState, 'SUCCESS');
|
||||
assert.equal(harness.state.queryOutBillNo, 'CLS-20260627-501');
|
||||
assert.equal(harness.state.queryOutBillNo, 'CLP501');
|
||||
assert.equal(harness.repository.paid[0].payoutReference, 'wx-transfer-query-501');
|
||||
}
|
||||
|
||||
@@ -115,7 +131,7 @@ const actor = {
|
||||
const harness = createHarness({
|
||||
notificationPayload: {
|
||||
mch_id: '1900000109',
|
||||
out_bill_no: 'CLS-20260627-501',
|
||||
out_bill_no: 'CLP501',
|
||||
transfer_bill_no: 'wx-notify-501',
|
||||
state: 'SUCCESS'
|
||||
}
|
||||
@@ -132,6 +148,27 @@ const actor = {
|
||||
assert.equal(harness.repository.paid[0].payoutReference, 'wx-notify-501');
|
||||
}
|
||||
|
||||
{
|
||||
const harness = createHarness({
|
||||
status: 'PAID',
|
||||
payoutState: 'SUCCESS',
|
||||
notificationPayload: {
|
||||
mch_id: '1900000109',
|
||||
out_bill_no: 'CLP501',
|
||||
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-replay-trace');
|
||||
assert.equal(result.idempotent, true);
|
||||
assert.equal(harness.repository.paid.length, 0);
|
||||
}
|
||||
|
||||
{
|
||||
const harness = createHarness({ transferState: 'FAIL', failReason: 'REAL_NAME_CHECK_FAILED' });
|
||||
const result = await harness.service.executeWechatTransfer({
|
||||
@@ -175,12 +212,14 @@ function createHarness(options = {}) {
|
||||
id: '501',
|
||||
settlementNo: 'CLS-20260627-501',
|
||||
cleanerUserId: '31',
|
||||
generatedBy: '21',
|
||||
storeId: '11',
|
||||
status: options.status ?? 'CONFIRMED',
|
||||
totalRewardCents: 1200,
|
||||
payoutChannel: options.payoutChannel ?? 'WECHAT_TRANSFER',
|
||||
payoutReference: options.payoutReference ?? 'CLS-20260627-501',
|
||||
payoutState: options.payoutState ?? 'WAIT_USER_CONFIRM',
|
||||
payoutRequestNo: options.payoutRequestNo ?? 'CLP501',
|
||||
payoutReference: options.payoutReference ?? 'CLP501',
|
||||
payoutState: options.payoutState ?? '',
|
||||
payoutPackageInfo: options.payoutPackageInfo ?? 'package-info'
|
||||
},
|
||||
account: {
|
||||
@@ -210,9 +249,17 @@ function createHarness(options = {}) {
|
||||
}
|
||||
};
|
||||
const repository = {
|
||||
begun: [],
|
||||
paid: [],
|
||||
failures: [],
|
||||
pending: [],
|
||||
async beginSettlementPayout(input) {
|
||||
this.begun.push(input);
|
||||
state.settlement.payoutChannel = input.payoutChannel;
|
||||
state.settlement.payoutReference = input.payoutReference;
|
||||
state.settlement.payoutState = 'PROCESSING';
|
||||
return { ...state.settlement };
|
||||
},
|
||||
async markSettlementPaid(input) {
|
||||
this.paid.push(input);
|
||||
return { ...state.settlement, status: 'PAID', payoutReference: input.payoutReference };
|
||||
|
||||
Reference in New Issue
Block a user