36 lines
1003 B
JavaScript
36 lines
1003 B
JavaScript
"use strict";
|
|
|
|
const test = require("node:test");
|
|
const assert = require("node:assert/strict");
|
|
const { calculateCredits } = require("../src/lib/credits");
|
|
|
|
const config = {
|
|
baseCredits: 1,
|
|
includedChars: 25000,
|
|
stepChars: 10000,
|
|
stepCredits: 1,
|
|
maxCharsPerArticle: 120000,
|
|
};
|
|
|
|
test("charges base credit up to included chars", () => {
|
|
assert.equal(calculateCredits(1, config), 1);
|
|
assert.equal(calculateCredits(25000, config), 1);
|
|
});
|
|
|
|
test("charges one extra credit after crossing step boundary", () => {
|
|
assert.equal(calculateCredits(25001, config), 2);
|
|
assert.equal(calculateCredits(35000, config), 2);
|
|
});
|
|
|
|
test("charges multiple steps correctly", () => {
|
|
assert.equal(calculateCredits(45001, config), 4);
|
|
});
|
|
|
|
test("rejects oversized articles", () => {
|
|
assert.throws(() => calculateCredits(120001, config), /article_too_long/);
|
|
});
|
|
|
|
test("rejects non-positive charCount", () => {
|
|
assert.throws(() => calculateCredits(0, config), /charCount must be a positive integer/);
|
|
});
|