refactor: convert LootdropService from class to singleton object pattern

- Move instance properties to module-level state (channelActivity, channelCooldowns)
- Convert constructor cleanup interval to module-level initialization
- Export state variables for testing
- Update tests to use direct state access instead of (service as any)
- Maintains same behavior while following project service pattern

Closes #4
This commit is contained in:
syntaxbullet
2026-02-13 13:28:46 +01:00
parent 6eb4a32a12
commit 55d2376ca1
2 changed files with 204 additions and 205 deletions

View File

@@ -1,5 +1,5 @@
import { describe, it, expect, mock, beforeEach, afterEach, spyOn } from "bun:test";
import { lootdropService } from "@shared/modules/economy/lootdrop.service";
import { lootdropService, channelActivity, channelCooldowns } from "@shared/modules/economy/lootdrop.service";
import { lootdrops } from "@db/schema";
import { economyService } from "@shared/modules/economy/economy.service";
@@ -67,8 +67,8 @@ describe("lootdropService", () => {
mockFrom.mockClear();
// Reset internal state
(lootdropService as any).channelActivity = new Map();
(lootdropService as any).channelCooldowns = new Map();
channelActivity.clear();
channelCooldowns.clear();
// Mock Math.random
originalRandom = Math.random;