diff --git a/.env.test b/.env.test index 82b5df5..10352b4 100644 --- a/.env.test +++ b/.env.test @@ -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" diff --git a/bot/lib/BotClient.test.ts b/bot/lib/BotClient.test.ts index 6408a41..88a3943 100644 --- a/bot/lib/BotClient.test.ts +++ b/bot/lib/BotClient.test.ts @@ -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 diff --git a/bot/lib/clientStats.test.ts b/bot/lib/clientStats.test.ts index a1cf1f1..9bbae54 100644 --- a/bot/lib/clientStats.test.ts +++ b/bot/lib/clientStats.test.ts @@ -20,6 +20,9 @@ mock.module("./BotClient", () => ({ commands: { size: 20, }, + knownCommands: { + size: 20, + }, lastCommandTimestamp: 1641481200000, }, })); diff --git a/docker-compose.yml b/docker-compose.yml index e29b8c0..53e8c29 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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: @@ -91,6 +91,6 @@ networks: volumes: # Named volumes for node_modules caching app_node_modules: - name: aurora_app_node_modules + name: aurora_app_node_modules web_node_modules: name: aurora_web_node_modules diff --git a/shared/modules/dashboard/dashboard.service.test.ts b/shared/modules/dashboard/dashboard.service.test.ts index 193d445..9ed0d1a 100644 --- a/shared/modules/dashboard/dashboard.service.test.ts +++ b/shared/modules/dashboard/dashboard.service.test.ts @@ -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 () => { diff --git a/shared/modules/economy/economy.service.test.ts b/shared/modules/economy/economy.service.test.ts index 10236d5..6f3a14a 100644 --- a/shared/modules/economy/economy.service.test.ts +++ b/shared/modules/economy/economy.service.test.ts @@ -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 () => { diff --git a/shared/modules/inventory/inventory.service.test.ts b/shared/modules/inventory/inventory.service.test.ts index 59ea7f6..d486593 100644 --- a/shared/modules/inventory/inventory.service.test.ts +++ b/shared/modules/inventory/inventory.service.test.ts @@ -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(); diff --git a/shared/modules/leveling/leveling.service.test.ts b/shared/modules/leveling/leveling.service.test.ts index 93cfd1e..e963fdf 100644 --- a/shared/modules/leveling/leveling.service.test.ts +++ b/shared/modules/leveling/leveling.service.test.ts @@ -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, diff --git a/shared/modules/moderation/moderation.service.test.ts b/shared/modules/moderation/moderation.service.test.ts index 7404f0b..a89c8cc 100644 --- a/shared/modules/moderation/moderation.service.test.ts +++ b/shared/modules/moderation/moderation.service.test.ts @@ -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 })); diff --git a/shared/scripts/debug-db.ts b/shared/scripts/debug-db.ts new file mode 100644 index 0000000..af3e553 --- /dev/null +++ b/shared/scripts/debug-db.ts @@ -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(); +}