chore: Enhance database debugging setup and expand test mocks for Drizzle queries and Discord API interactions.
Some checks failed
Deploy to Production / test (push) Failing after 29s
Deploy to Production / build (push) Has been skipped
Deploy to Production / deploy (push) Has been skipped

This commit is contained in:
syntaxbullet
2026-01-30 16:12:15 +01:00
parent 7049cbfd9d
commit 9a2fc101da
10 changed files with 43 additions and 13 deletions

View File

@@ -7,6 +7,8 @@ const mockLimit = mock();
// Helper to support the chained calls in getLeaderboards
const mockChain = {
from: () => mockChain,
leftJoin: () => mockChain,
groupBy: () => mockChain,
orderBy: () => mockChain,
limit: mockLimit
};
@@ -75,7 +77,8 @@ describe("dashboardService", () => {
// First call is topLevels, second is topWealth
mockLimit
.mockResolvedValueOnce(mockTopLevels)
.mockResolvedValueOnce(mockTopWealth);
.mockResolvedValueOnce(mockTopWealth)
.mockResolvedValueOnce(mockTopWealth); // Mock net worth same as wealth for simplicity
const result = await dashboardService.getLeaderboards();
@@ -85,7 +88,7 @@ describe("dashboardService", () => {
expect(result.topWealth[0]!.balance).toBe("1000");
expect(result.topWealth[0]!.username).toBe("Alice");
expect(result.topWealth[1]!.balance).toBe("500");
expect(mockLimit).toHaveBeenCalledTimes(2);
expect(mockLimit).toHaveBeenCalledTimes(3);
});
test("should handle empty leaderboards", async () => {

View File

@@ -3,7 +3,7 @@ import { economyService } from "@shared/modules/economy/economy.service";
import { users, userTimers, transactions } from "@db/schema";
// Define mock functions
const mockFindMany = mock();
const mockFindMany = mock(() => Promise.resolve([]));
const mockFindFirst = mock();
const mockInsert = mock();
const mockUpdate = mock();
@@ -33,6 +33,7 @@ mock.module("@shared/db/DrizzleClient", () => {
query: {
users: { findFirst: mockFindFirst },
userTimers: { findFirst: mockFindFirst },
userQuests: { findMany: mockFindMany },
},
insert: mockInsert,
update: mockUpdate,
@@ -173,7 +174,7 @@ describe("economyService", () => {
it("should throw if cooldown is active", async () => {
const future = new Date("2023-01-02T12:00:00Z"); // +24h
mockFindFirst.mockResolvedValue({ expiresAt: future });
expect(economyService.claimDaily("1")).rejects.toThrow("Daily already claimed");
expect(economyService.claimDaily("1")).rejects.toThrow("You have already claimed your daily reward today");
});
it("should set cooldown to next UTC midnight", async () => {

View File

@@ -48,6 +48,8 @@ mock.module("@shared/db/DrizzleClient", () => {
inventory: { findFirst: mockFindFirst, findMany: mockFindMany },
items: { findFirst: mockFindFirst },
userTimers: { findFirst: mockFindFirst },
userQuests: { findMany: mockFindMany, findFirst: mockFindFirst },
quests: { findMany: mockFindMany },
},
insert: mockInsert,
update: mockUpdate,
@@ -79,6 +81,7 @@ describe("inventoryService", () => {
beforeEach(() => {
mockFindFirst.mockReset();
mockFindMany.mockReset();
mockFindMany.mockResolvedValue([]);
mockInsert.mockClear();
mockUpdate.mockClear();
mockDelete.mockClear();

View File

@@ -4,6 +4,7 @@ import { users, userTimers } from "@db/schema";
// Mock dependencies
const mockFindFirst = mock();
const mockFindMany = mock(() => Promise.resolve([]));
const mockUpdate = mock();
const mockSet = mock();
const mockWhere = mock();
@@ -24,8 +25,10 @@ mockOnConflictDoUpdate.mockResolvedValue({});
mock.module("@shared/db/DrizzleClient", () => {
const createMockTx = () => ({
query: {
users: { findFirst: mockFindFirst },
userTimers: { findFirst: mockFindFirst },
userQuests: { findMany: mockFindMany },
},
update: mockUpdate,
insert: mockInsert,

View File

@@ -30,7 +30,7 @@ mock.module("@shared/lib/config", () => ({
// Mock View
const mockGetUserWarningEmbed = mock(() => ({}));
mock.module("./moderation.view", () => ({
mock.module("@/modules/moderation/moderation.view", () => ({
getUserWarningEmbed: mockGetUserWarningEmbed
}));