games_app/backend/dist-test-faq/tests/withdrawEligibility.test.js

52 lines
2.2 KiB
JavaScript

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const node_test_1 = require("node:test");
const strict_1 = __importDefault(require("node:assert/strict"));
// Mirror of prediqo_web withdrawEligibility (kept in sync for backend-facing docs/tests).
function computeWithdrawEligibility(input) {
const availableRaw = BigInt(input.availableRaw || '0');
const feeRaw = BigInt(input.feeRaw || '0');
const maxReceivableRaw = availableRaw > feeRaw ? availableRaw - feeRaw : 0n;
if (!input.withdrawalsEnabled)
return { allowed: false, reason: 'global_off' };
if (!input.hasWithdrawNetwork)
return { allowed: false, reason: 'no_network' };
if (maxReceivableRaw <= 0n)
return { allowed: false, reason: 'insufficient_for_fee' };
return { allowed: true, reason: null };
}
(0, node_test_1.describe)('withdraw eligibility rules', () => {
(0, node_test_1.test)('blocks when global kill-switch off', () => {
const r = computeWithdrawEligibility({
withdrawalsEnabled: false,
hasWithdrawNetwork: true,
availableRaw: '5000000',
feeRaw: '500000',
});
strict_1.default.equal(r.allowed, false);
strict_1.default.equal(r.reason, 'global_off');
});
(0, node_test_1.test)('blocks when available equals fee only', () => {
const r = computeWithdrawEligibility({
withdrawalsEnabled: true,
hasWithdrawNetwork: true,
availableRaw: '500000',
feeRaw: '500000',
});
strict_1.default.equal(r.allowed, false);
strict_1.default.equal(r.reason, 'insufficient_for_fee');
});
(0, node_test_1.test)('allows when available covers fee + dust', () => {
const r = computeWithdrawEligibility({
withdrawalsEnabled: true,
hasWithdrawNetwork: true,
availableRaw: '500001',
feeRaw: '500000',
});
strict_1.default.equal(r.allowed, true);
});
});
//# sourceMappingURL=withdrawEligibility.test.js.map