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();
|
|
});
|
|
});
|