50 lines
1.8 KiB
TypeScript
50 lines
1.8 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import {
|
|
MAX_PLAYER_LEVEL,
|
|
awardExperience,
|
|
healerManExperienceAward,
|
|
levelProgressPercent,
|
|
maxHealthForLevel,
|
|
normalizeProgression,
|
|
totalExperienceForLevel,
|
|
xpRequiredForNextLevel,
|
|
} from "./progression";
|
|
|
|
describe("player progression", () => {
|
|
it("uses exact AzerothCore thresholds and carries overflow through boundaries", () => {
|
|
const result = awardExperience({ level: 1, xp: 0 }, 1_400);
|
|
expect(result).toMatchObject({ level: 3, xp: 100, levelsGained: 2, xpToNext: 1_400 });
|
|
expect(totalExperienceForLevel(3)).toBe(1_300);
|
|
expect(xpRequiredForNextLevel(1)).toBe(400);
|
|
expect(xpRequiredForNextLevel(79)).toBe(1_670_800);
|
|
});
|
|
|
|
it("normalizes corrupt and overflowing persisted progression", () => {
|
|
expect(normalizeProgression(Number.NaN, -20)).toEqual({ level: 1, xp: 0 });
|
|
expect(normalizeProgression(1, 425)).toEqual({ level: 2, xp: 25 });
|
|
});
|
|
|
|
it("stops cleanly at the level cap", () => {
|
|
const result = awardExperience(
|
|
{ level: MAX_PLAYER_LEVEL - 1, xp: 0 },
|
|
xpRequiredForNextLevel(MAX_PLAYER_LEVEL - 1),
|
|
);
|
|
expect(result.level).toBe(MAX_PLAYER_LEVEL);
|
|
expect(result.xp).toBe(0);
|
|
expect(result.xpToNext).toBe(0);
|
|
expect(result.reachedLevelCap).toBe(true);
|
|
expect(xpRequiredForNextLevel(MAX_PLAYER_LEVEL)).toBe(0);
|
|
});
|
|
|
|
it("scales health by class and clamps progress percentages", () => {
|
|
expect(maxHealthForLevel("warrior", 2)).toBeGreaterThan(maxHealthForLevel("mage", 2));
|
|
expect(levelProgressPercent(1, 200)).toBe(50);
|
|
expect(levelProgressPercent(1, 500)).toBe(100);
|
|
});
|
|
|
|
it("preserves each legacy reward as the same fraction of the current level", () => {
|
|
expect(healerManExperienceAward(25, 1)).toBe(100);
|
|
expect(healerManExperienceAward(75, 2)).toBe(450);
|
|
});
|
|
});
|