chore: improve DX scripts, fix test suite, and harden tooling
All checks were successful
Deploy to Production / test (push) Successful in 32s
All checks were successful
Deploy to Production / test (push) Successful in 32s
Scripts: - remote.sh: remove unused open_browser() function - deploy-remote.sh: add DB backup before deploy, --skip-backup flag, step numbering - db-backup.sh: fix macOS compat (xargs -r is GNU-only), use portable approach - db-restore.sh: add safety backup before restore, SQL file validation, file size display - logs.sh: default to no-follow with --tail=100, order-independent arg parsing - docker-cleanup.sh: add Docker health check, colored output - test-sequential.sh: exclude *.integration.test.ts by default, add --integration flag - simulate-ci.sh: pass --integration flag (has real DB) Tests: - db.test.ts: fix mock path from ./DrizzleClient to @shared/db/DrizzleClient - server.settings.test.ts: rewrite mocks for gameSettingsService (old config/saveConfig removed) - server.test.ts: add missing config.lootdrop and BotClient mocks, complete DrizzleClient chain - indexes.test.ts: rename to indexes.integration.test.ts (requires live DB) Config: - package.json: test script uses sequential runner, add test:ci and db:restore aliases - deploy.yml: use --integration flag in CI (has Postgres service)
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import { describe, test, expect, afterAll, mock } from "bun:test";
|
||||
import type { WebServerInstance } from "./server";
|
||||
import { createWebServer } from "./server";
|
||||
|
||||
interface MockBotStats {
|
||||
bot: { name: string; avatarUrl: string | null };
|
||||
@@ -13,21 +12,21 @@ interface MockBotStats {
|
||||
}
|
||||
|
||||
// 1. Mock DrizzleClient (dependency of dashboardService)
|
||||
// Must provide full chainable builder for select().from().leftJoin().groupBy().orderBy().limit()
|
||||
mock.module("@shared/db/DrizzleClient", () => {
|
||||
const mockBuilder = {
|
||||
where: mock(() => Promise.resolve([{ count: "5", balance: 1000n, level: 5, dailyStreak: 2 }])),
|
||||
then: (onfulfilled: any) => onfulfilled([{ count: "5", balance: 1000n, level: 5, dailyStreak: 2 }]),
|
||||
orderBy: mock(() => mockBuilder), // Chainable
|
||||
limit: mock(() => Promise.resolve([])), // Terminal
|
||||
};
|
||||
|
||||
const mockFrom = {
|
||||
from: mock(() => mockBuilder),
|
||||
};
|
||||
const mockBuilder: Record<string, any> = {};
|
||||
// Every chainable method returns mock builder; terminal calls return resolved promise
|
||||
mockBuilder.where = mock(() => Promise.resolve([{ count: "5", balance: 1000n, level: 5, dailyStreak: 2 }]));
|
||||
mockBuilder.then = (onfulfilled: any) => onfulfilled([{ count: "5", balance: 1000n, level: 5, dailyStreak: 2 }]);
|
||||
mockBuilder.orderBy = mock(() => mockBuilder);
|
||||
mockBuilder.limit = mock(() => Promise.resolve([]));
|
||||
mockBuilder.leftJoin = mock(() => mockBuilder);
|
||||
mockBuilder.groupBy = mock(() => mockBuilder);
|
||||
mockBuilder.from = mock(() => mockBuilder);
|
||||
|
||||
return {
|
||||
DrizzleClient: {
|
||||
select: mock(() => mockFrom),
|
||||
select: mock(() => mockBuilder),
|
||||
query: {
|
||||
transactions: { findMany: mock(() => Promise.resolve([])) },
|
||||
moderationCases: { findMany: mock(() => Promise.resolve([])) },
|
||||
@@ -54,7 +53,31 @@ mock.module("../../bot/lib/clientStats", () => ({
|
||||
})),
|
||||
}));
|
||||
|
||||
// 3. System Events (No mock needed, use real events)
|
||||
// 3. Mock config (used by lootdrop.service.getLootdropState)
|
||||
mock.module("@shared/lib/config", () => ({
|
||||
config: {
|
||||
lootdrop: {
|
||||
activityWindowMs: 120000,
|
||||
minMessages: 1,
|
||||
spawnChance: 1,
|
||||
cooldownMs: 3000,
|
||||
reward: { min: 40, max: 150, currency: "Astral Units" }
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
||||
// 4. Mock BotClient (used by stats helper for maintenanceMode)
|
||||
mock.module("../../bot/lib/BotClient", () => ({
|
||||
AuroraClient: {
|
||||
maintenanceMode: false,
|
||||
guilds: { cache: { get: () => null } },
|
||||
commands: [],
|
||||
knownCommands: new Map(),
|
||||
}
|
||||
}));
|
||||
|
||||
// Import after all mocks are set up
|
||||
import { createWebServer } from "./server";
|
||||
|
||||
describe("WebServer Security & Limits", () => {
|
||||
const port = 3001;
|
||||
|
||||
Reference in New Issue
Block a user