forked from syntaxbullet/AuroraBot-discord
test: fix mock leakage in db tests
This commit is contained in:
@@ -1,18 +1,5 @@
|
|||||||
import { describe, it, expect, mock, beforeEach } from "bun:test";
|
import { describe, it, expect, mock, beforeEach } from "bun:test";
|
||||||
|
|
||||||
// Mock shutdown module before importing db
|
|
||||||
mock.module("./shutdown", () => {
|
|
||||||
let shuttingDown = false;
|
|
||||||
let transactions = 0;
|
|
||||||
return {
|
|
||||||
isShuttingDown: () => shuttingDown,
|
|
||||||
setShuttingDown: (v: boolean) => { shuttingDown = v; },
|
|
||||||
incrementTransactions: () => { transactions++; },
|
|
||||||
decrementTransactions: () => { transactions--; },
|
|
||||||
getActiveTransactions: () => transactions,
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
// Mock DrizzleClient
|
// Mock DrizzleClient
|
||||||
mock.module("./DrizzleClient", () => ({
|
mock.module("./DrizzleClient", () => ({
|
||||||
DrizzleClient: {
|
DrizzleClient: {
|
||||||
@@ -21,11 +8,15 @@ mock.module("./DrizzleClient", () => ({
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
import { withTransaction } from "./db";
|
import { withTransaction } from "./db";
|
||||||
import { setShuttingDown, getActiveTransactions } from "./shutdown";
|
import { setShuttingDown, getActiveTransactions, decrementTransactions } from "./shutdown";
|
||||||
|
|
||||||
describe("db withTransaction", () => {
|
describe("db withTransaction", () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
setShuttingDown(false);
|
setShuttingDown(false);
|
||||||
|
// Reset transaction count
|
||||||
|
while (getActiveTransactions() > 0) {
|
||||||
|
decrementTransactions();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should allow transactions when not shutting down", async () => {
|
it("should allow transactions when not shutting down", async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user