feat: introduce weekly bonus for daily rewards, updating calculations, configuration, and command UI.
This commit is contained in:
@@ -62,6 +62,7 @@ mock.module("@/lib/config", () => ({
|
||||
daily: {
|
||||
amount: 100n,
|
||||
streakBonus: 10n,
|
||||
weeklyBonus: 50n,
|
||||
cooldownMs: 86400000, // 24 hours
|
||||
}
|
||||
}
|
||||
@@ -139,6 +140,7 @@ describe("economyService", () => {
|
||||
expect(result.streak).toBe(6);
|
||||
// Base 100 + (6-1)*10 = 150
|
||||
expect(result.amount).toBe(150n);
|
||||
expect(result.isWeekly).toBe(false);
|
||||
|
||||
// Check updates
|
||||
expect(mockUpdate).toHaveBeenCalledWith(users);
|
||||
@@ -146,6 +148,28 @@ describe("economyService", () => {
|
||||
expect(mockInsert).toHaveBeenCalledWith(transactions);
|
||||
});
|
||||
|
||||
it("should claim weekly bonus correctly on 7th day", async () => {
|
||||
const recentPast = new Date("2023-01-01T11:00:00Z");
|
||||
|
||||
mockFindFirst
|
||||
.mockResolvedValueOnce({ expiresAt: recentPast })
|
||||
.mockResolvedValueOnce({ id: 1n, dailyStreak: 6, balance: 1000n }); // User currently at 6 days
|
||||
|
||||
const result = await economyService.claimDaily("1");
|
||||
|
||||
expect(result.claimed).toBe(true);
|
||||
// Streak should increase: 6 + 1 = 7
|
||||
expect(result.streak).toBe(7);
|
||||
|
||||
// Base: 100
|
||||
// Streak Bonus: (7-1)*10 = 60
|
||||
// Weekly Bonus: 50
|
||||
// Total: 210
|
||||
expect(result.amount).toBe(210n);
|
||||
expect(result.isWeekly).toBe(true);
|
||||
expect(result.weeklyBonus).toBe(50n);
|
||||
});
|
||||
|
||||
it("should throw if cooldown is active", async () => {
|
||||
const future = new Date("2023-01-02T12:00:00Z"); // +24h
|
||||
mockFindFirst.mockResolvedValue({ expiresAt: future });
|
||||
|
||||
Reference in New Issue
Block a user