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

@@ -1,4 +1,4 @@
DATABASE_URL="postgresql://postgres:postgres@localhost:5432/aurora_test"
DATABASE_URL="postgresql://auroradev:auroradev123@localhost:5432/aurora_test"
DISCORD_BOT_TOKEN="test_token"
DISCORD_CLIENT_ID="123456789"
DISCORD_GUILD_ID="123456789"

View File

@@ -20,7 +20,8 @@ mock.module("discord.js", () => ({
Routes: {
applicationGuildCommands: () => 'guild_route',
applicationCommands: () => 'global_route'
}
},
MessageFlags: {}
}));
// Mock loaders to avoid filesystem access during client init

View File

@@ -20,6 +20,9 @@ mock.module("./BotClient", () => ({
commands: {
size: 20,
},
knownCommands: {
size: 20,
},
lastCommandTimestamp: 1641481200000,
},
}));

View File

@@ -7,13 +7,14 @@ services:
- POSTGRES_PASSWORD=${DB_PASSWORD}
- POSTGRES_DB=${DB_NAME}
# Uncomment to access DB from host (for debugging/drizzle-kit studio)
# ports:
# - "127.0.0.1:${DB_PORT}:5432"
ports:
- "127.0.0.1:${DB_PORT}:5432"
volumes:
# Host-mounted to preserve existing VPS data
- ./shared/db/data:/var/lib/postgresql/data
networks:
- internal
- web
healthcheck:
test: [ "CMD-SHELL", "pg_isready -U ${DB_USER} -d ${DB_NAME}" ]
interval: 5s
@@ -26,7 +27,7 @@ services:
build:
context: .
dockerfile: Dockerfile
target: development # Use development stage
target: development # Use development stage
working_dir: /app
ports:
- "127.0.0.1:3000:3000"
@@ -67,8 +68,7 @@ services:
extends:
service: app
# Clear inherited ports from app and only expose studio port
ports:
!override
ports: !override
- "127.0.0.1:4983:4983"
# Override healthcheck since studio doesn't serve on port 3000
healthcheck:

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
}));

View File

@@ -0,0 +1,16 @@
import postgres from "postgres";
const connectionString = "postgresql://auroradev:auroradev123@127.0.0.1:5432/aurora_test";
console.log("Connecting to:", connectionString);
const sql = postgres(connectionString);
try {
const result = await sql`SELECT 1 as val`;
console.log("Success:", result);
await sql.end();
} catch (e) {
console.error("Connection failed:", e);
await sql.end();
}