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

92 lines
4.1 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"));
const referralCapService_1 = require("../services/referralCapService");
(0, node_test_1.describe)('referral monthly commission caps', () => {
(0, node_test_1.test)('allows commission within amount and count limits', () => {
const result = (0, referralCapService_1.wouldExceedMonthlyCommissionCap)({
currentReservedAmount: 100000000n,
currentReservedCount: 10,
newCommissionAmount: 20000000n,
maxAmountRaw: 500000000n,
maxCount: 50,
});
strict_1.default.equal(result.exceeded, false);
});
(0, node_test_1.test)('blocks when monthly amount cap would be exceeded', () => {
const result = (0, referralCapService_1.wouldExceedMonthlyCommissionCap)({
currentReservedAmount: 490000000n,
currentReservedCount: 5,
newCommissionAmount: 20000000n,
maxAmountRaw: 500000000n,
maxCount: 50,
});
strict_1.default.equal(result.exceeded, true);
strict_1.default.equal(result.reason, 'amount');
});
(0, node_test_1.test)('blocks when monthly count cap would be exceeded', () => {
const result = (0, referralCapService_1.wouldExceedMonthlyCommissionCap)({
currentReservedAmount: 0n,
currentReservedCount: 50,
newCommissionAmount: 1000000n,
maxAmountRaw: 500000000n,
maxCount: 50,
});
strict_1.default.equal(result.exceeded, true);
strict_1.default.equal(result.reason, 'count');
});
(0, node_test_1.test)('treats zero caps as unlimited', () => {
const result = (0, referralCapService_1.wouldExceedMonthlyCommissionCap)({
currentReservedAmount: 999999999999n,
currentReservedCount: 999,
newCommissionAmount: 1000000n,
maxAmountRaw: 0n,
maxCount: 0,
});
strict_1.default.equal(result.exceeded, false);
});
});
(0, node_test_1.describe)('resolveEffectiveLevelCaps', () => {
const global = { maxAmountRaw: 500000000n, maxCount: 50 };
(0, node_test_1.test)('inherits global caps when level caps are zero', () => {
const caps = (0, referralCapService_1.resolveEffectiveLevelCaps)(global, {
monthlyMaxAmountRaw: '0',
monthlyMaxCount: 0,
});
strict_1.default.equal(caps.source, 'global');
strict_1.default.equal(caps.maxAmountRaw, 500000000n);
strict_1.default.equal(caps.maxCount, 50);
});
(0, node_test_1.test)('uses level amount cap while inheriting global count', () => {
const caps = (0, referralCapService_1.resolveEffectiveLevelCaps)(global, {
monthlyMaxAmountRaw: '100000000',
monthlyMaxCount: 0,
});
strict_1.default.equal(caps.source, 'level');
strict_1.default.equal(caps.maxAmountRaw, 100000000n);
strict_1.default.equal(caps.maxCount, 50);
});
(0, node_test_1.test)('uses level count cap while inheriting global amount', () => {
const caps = (0, referralCapService_1.resolveEffectiveLevelCaps)(global, {
monthlyMaxAmountRaw: '0',
monthlyMaxCount: 10,
});
strict_1.default.equal(caps.source, 'level');
strict_1.default.equal(caps.maxAmountRaw, 500000000n);
strict_1.default.equal(caps.maxCount, 10);
});
(0, node_test_1.test)('uses both level caps when both are set', () => {
const caps = (0, referralCapService_1.resolveEffectiveLevelCaps)(global, {
monthlyMaxAmountRaw: '200000000',
monthlyMaxCount: 5,
});
strict_1.default.equal(caps.source, 'level');
strict_1.default.equal(caps.maxAmountRaw, 200000000n);
strict_1.default.equal(caps.maxCount, 5);
});
});
//# sourceMappingURL=referralCapService.test.js.map