Intelligence, Advanced Charting & Trading Platform
test(risk): assert monthly/daily rate math and quota-reserve boundary safety
davoodmehraban89 committed
Oct 21, 2026 at 08:52 UTC
f9e077db97ac0fa1ba104021f4ac7432b9154589
1 file changed
+27
packages/market-domain/test/free-quota-budget.test.mjs
new
+27
@@ -0,0 +1,27 @@
1
+import test from 'node:test';import assert from 'node:assert/strict';
2
+import {quotaBudget,officialFreePlanBudget} from '../src/free-quota-budget.mjs';
3
+test('30 day navasan no-reserve arithmetic is precisely six hours',()=>{
4
+ const r=officialFreePlanBudget('NAVASAN',{reserveFraction:0});
5
+ assert.equal(r.mathematicallyMinimalMinutes,360);assert.equal(r.suggestedMinutes,360);
6
+ assert.equal(r.plannedCalls,120);assert.equal(r.guaranteedLatencyMs,null)
7
+});
8
+test('31 day navasan floor 372 minutes',()=>assert.equal(officialFreePlanBudget('NAVASAN',{daysInMonth:31,reserveFraction:0}).mathematicallyMinimalMinutes,372));
9
+test('Gheymat one-call floor 5.76 min, two-call doubles',()=>{
10
+ assert.equal(officialFreePlanBudget('GHEYMAT_ONLINE',{reserveFraction:0}).mathematicallyMinimalMinutes,5.76);
11
+ assert.equal(officialFreePlanBudget('GHEYMAT_ONLINE',{callsPerPoll:2,reserveFraction:0}).mathematicallyMinimalMinutes,11.52)
12
+});
13
+test('reserve never overcommits quota, including odd windows',()=>{
14
+ for(const calls of [1,5,17,120,250]){
15
+ for(const k of [1,2,4]){
16
+ try{const x=quotaBudget({calls,windowMinutes:1440,callsPerPoll:k,reserveFraction:0});
17
+ assert.ok(x.plannedCalls<=calls);assert.ok(x.remainingCalls>=0);
18
+ assert.equal(x.latencyVerified,false);
19
+ }catch(e){assert.ok(e instanceof RangeError)}
20
+ }
21
+ }
22
+});
23
+test('account/plan drift and unknown providers rejected, no asserted SLA',()=>{
24
+ assert.throws(()=>officialFreePlanBudget('HIDDEN_PROVIDER'));
25
+ assert.throws(()=>officialFreePlanBudget('NAVASAN',{daysInMonth:32}));
26
+ assert.throws(()=>quotaBudget({calls:250,windowMinutes:1440,reserveFraction:1}));
27
+});