MatchMaster/tools/coin-madness/check-ios-payment-fallback.cjs

42 lines
2.4 KiB
JavaScript

// In-memory only: never opens WeChat or creates real orders.
const assert = require('node:assert/strict');
const { fixture } = require('./check-api.cjs');
const create = (server = {}) => {
const f = fixture(new Map(), { ios: true, nativeError: { errCode: 16, errMsg: 'not supported' }, ...server });
f.info.status = 'purchasable';
return f;
};
const buy = f => f.client.request('purchase', { periodId: f.periodId });
const legacy = f => f.calls.filter(c => c.path === 'Utils.GoKEFu');
(async () => {
for (const errCode of [16, '16']) {
const f = create({ nativeError: { errCode, errMsg: 'not supported' } });
assert.equal((await buy(f)).code, 1);
assert.equal(f.counts().payCalls, 2);
assert.equal(legacy(f).length, 1);
const native = f.calls.find(c => c.path === 'wx/iosorderPaySig');
assert(native.body.createRequestId); assert(!f.calls.some(c => c.body.action === 'create_order'));
assert.equal(legacy(f)[0].body.payment_count, 1);
assert.equal(legacy(f)[0].body.payment_name, f.info.productId);
assert.equal(legacy(f)[0].body.price, f.info.priceFen);
assert.equal(f.client.ledger.orders[f.periodId].channel, 'legacy_ios');
assert(f.calls.some(c => c.path === 'wx/iosgetPayInfo' && c.body.outTradeNo === 'legacy-1'));
assert(!f.calls.some(c => c.body.outTradeNo === 'order-1'));
assert.equal(f.counts().saves, 0);
}
for (const server of [
{ ios: false }, { nativeError: { errCode: 2860 } },
{ nativeError: { errCode: -2, errMsg: 'cancel' } },
{ nativeError: { errCode: 16, errMsg: 'cancel' } },
]) {
const f = create(server); assert.equal((await buy(f)).code, 0);
assert.equal(legacy(f).length, 0); assert.equal(f.counts().payCalls, 1);
}
const failed = create({ customerError: { errCode: 16, errMsg: 'customer failed' } });
assert.equal((await buy(failed)).code, 0);
assert.equal(legacy(failed).length, 1); assert.equal(failed.counts().payCalls, 2);
const direct = create(); direct.game.iosCanPay = false;
assert.equal((await buy(direct)).code, 1); assert.equal(direct.counts().payCalls, 1);
console.log('PASS: iOS 16 fallback, shop GoKEFu order, iOS confirmation, no wallet grant; cancellation/other errors/Android excluded; no loop.');
})().catch(error => { console.error(error); process.exitCode = 1; });