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)
48 lines
1.5 KiB
TypeScript
48 lines
1.5 KiB
TypeScript
import { describe, it, expect, mock, beforeEach } from "bun:test";
|
|
|
|
// Mock DrizzleClient — must match the import path used in db.ts
|
|
mock.module("@shared/db/DrizzleClient", () => ({
|
|
DrizzleClient: {
|
|
transaction: async (cb: any) => cb("MOCK_TX")
|
|
}
|
|
}));
|
|
|
|
import { withTransaction } from "./db";
|
|
import { setShuttingDown, getActiveTransactions, decrementTransactions } from "./shutdown";
|
|
|
|
describe("db withTransaction", () => {
|
|
beforeEach(() => {
|
|
setShuttingDown(false);
|
|
// Reset transaction count
|
|
while (getActiveTransactions() > 0) {
|
|
decrementTransactions();
|
|
}
|
|
});
|
|
|
|
it("should allow transactions when not shutting down", async () => {
|
|
const result = await withTransaction(async (tx) => {
|
|
return "success";
|
|
});
|
|
expect(result).toBe("success");
|
|
expect(getActiveTransactions()).toBe(0);
|
|
});
|
|
|
|
it("should throw error when shutting down", async () => {
|
|
setShuttingDown(true);
|
|
expect(withTransaction(async (tx) => {
|
|
return "success";
|
|
})).rejects.toThrow("System is shutting down, no new transactions allowed.");
|
|
expect(getActiveTransactions()).toBe(0);
|
|
});
|
|
|
|
it("should increment and decrement transaction count", async () => {
|
|
let countDuring = 0;
|
|
await withTransaction(async (tx) => {
|
|
countDuring = getActiveTransactions();
|
|
return "ok";
|
|
});
|
|
expect(countDuring).toBe(1);
|
|
expect(getActiveTransactions()).toBe(0);
|
|
});
|
|
});
|