Fix comeback bonus

This commit is contained in:
Joey Yakimowich-Payne 2026-01-19 13:10:07 -07:00
commit 99977bc8e6
No known key found for this signature in database
GPG key ID: DDF6AF5B21B407D4
4 changed files with 44 additions and 3 deletions

View file

@ -231,6 +231,7 @@ describe('calculatePointsWithBreakdown', () => {
const result = calculatePointsWithBreakdown({
...baseParams,
playerRank: 5,
currentQuestionIndex: 1,
config: { ...DEFAULT_GAME_CONFIG, comebackBonusEnabled: false },
});
@ -242,6 +243,7 @@ describe('calculatePointsWithBreakdown', () => {
const result = calculatePointsWithBreakdown({
...baseParams,
playerRank: rank,
currentQuestionIndex: 1,
config: { ...DEFAULT_GAME_CONFIG, comebackBonusEnabled: true, comebackBonusPoints: 100 },
});
@ -253,6 +255,7 @@ describe('calculatePointsWithBreakdown', () => {
const result = calculatePointsWithBreakdown({
...baseParams,
playerRank: 4,
currentQuestionIndex: 1,
config: { ...DEFAULT_GAME_CONFIG, comebackBonusEnabled: true, comebackBonusPoints: 100 },
});
@ -264,11 +267,33 @@ describe('calculatePointsWithBreakdown', () => {
const result = calculatePointsWithBreakdown({
...baseParams,
playerRank: 10,
currentQuestionIndex: 2,
config: { ...DEFAULT_GAME_CONFIG, comebackBonusEnabled: true, comebackBonusPoints: 150 },
});
expect(result.comebackBonus).toBe(150);
});
it('applies no comeback bonus on first question (index 0)', () => {
const result = calculatePointsWithBreakdown({
...baseParams,
playerRank: 5,
currentQuestionIndex: 0,
config: { ...DEFAULT_GAME_CONFIG, comebackBonusEnabled: true, comebackBonusPoints: 100 },
});
expect(result.comebackBonus).toBe(0);
});
it('applies no comeback bonus when currentQuestionIndex is undefined', () => {
const result = calculatePointsWithBreakdown({
...baseParams,
playerRank: 5,
config: { ...DEFAULT_GAME_CONFIG, comebackBonusEnabled: true, comebackBonusPoints: 100 },
});
expect(result.comebackBonus).toBe(0);
});
});
describe('first correct bonus', () => {
@ -319,9 +344,10 @@ describe('calculatePointsWithBreakdown', () => {
const result = calculatePointsWithBreakdown({
...baseParams,
streak: 4, // Above threshold
playerRank: 5, // Qualifies for comeback
streak: 4,
playerRank: 5,
isFirstCorrect: true,
currentQuestionIndex: 2,
config,
});