CI (SIAX Cloud) / integration (push) Skipped
CI (SIAX Cloud) / sonar (push) Skipped
masterplan-lock / check (push) Successful in 5s
Security Scan (SIAX Cloud) / security (push) Successful in 15s
CI (SIAX Cloud) / security (push) Successful in 16s
CI (SIAX Cloud) / sonar (pull_request) Skipped
masterplan-lock / check (pull_request) Successful in 7s
Security Scan (SIAX Cloud) / security (pull_request) Successful in 21s
CI (SIAX Cloud) / security (pull_request) Successful in 25s
CI (SIAX Cloud) / quality (push) Successful in 1m17s
CI (SIAX Cloud) / integration (pull_request) Successful in 54s
CI (SIAX Cloud) / quality (pull_request) Successful in 1m7s
31 lines
1.4 KiB
TypeScript
31 lines
1.4 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import { quoteMaximumCredits } from '../../src/document-workbench/credit-quote';
|
|
|
|
describe('credit quote', () => {
|
|
it('rounds each component up exactly and retains the price book version', () => {
|
|
expect(
|
|
quoteMaximumCredits('v1', [
|
|
{ metric: 'pages', maxUnits: 11, creditsPerBlock: 3, unitsPerBlock: 10 },
|
|
{ metric: 'tokens', maxUnits: 2000, creditsPerBlock: 2, unitsPerBlock: 1000 },
|
|
]),
|
|
).toMatchObject({ priceBookVersion: 'v1', maximumCredits: 10 });
|
|
});
|
|
it('does not charge an unused component', () => {
|
|
expect(
|
|
quoteMaximumCredits('v1', [{ metric: 'pages', maxUnits: 0, creditsPerBlock: 1, unitsPerBlock: 10 }])
|
|
.maximumCredits,
|
|
).toBe(0);
|
|
});
|
|
it('rejects fractional, negative, duplicate and overflowing quantities', () => {
|
|
const line = { metric: 'pages', maxUnits: 1, creditsPerBlock: 1, unitsPerBlock: 1 };
|
|
expect(() => quoteMaximumCredits('', [line])).toThrow();
|
|
expect(() => quoteMaximumCredits('v1', [line, line])).toThrow();
|
|
expect(() => quoteMaximumCredits('v1', [{ ...line, maxUnits: 0.5 }])).toThrow();
|
|
expect(() => quoteMaximumCredits('v1', [{ ...line, creditsPerBlock: -1 }])).toThrow();
|
|
expect(() => quoteMaximumCredits('v1', [{ ...line, unitsPerBlock: 0 }])).toThrow();
|
|
expect(() =>
|
|
quoteMaximumCredits('v1', [{ ...line, maxUnits: Number.MAX_SAFE_INTEGER, creditsPerBlock: 2 }]),
|
|
).toThrow();
|
|
});
|
|
});
|