Fix tests

This commit is contained in:
Arunavo Ray
2025-07-17 13:05:18 +05:30
parent 39bfb1e2d1
commit bde1f7b5d6
3 changed files with 117 additions and 52 deletions

View File

@@ -3,16 +3,71 @@
* This file is automatically loaded before running tests
*/
import { afterEach, beforeEach } from "bun:test";
import { mock } from "bun:test";
// Clean up after each test
afterEach(() => {
// Add any cleanup logic here
// Set NODE_ENV to test
process.env.NODE_ENV = "test";
// Mock the database module to prevent real database access during tests
mock.module("@/lib/db", () => {
const mockDb = {
select: () => ({
from: () => ({
where: () => ({
limit: () => Promise.resolve([])
})
})
}),
insert: () => ({
values: () => Promise.resolve()
}),
update: () => ({
set: () => ({
where: () => Promise.resolve()
})
}),
delete: () => ({
where: () => Promise.resolve()
})
};
return {
db: mockDb,
users: {},
events: {},
configs: {},
repositories: {},
mirrorJobs: {},
organizations: {},
sessions: {},
accounts: {},
verificationTokens: {},
oauthApplications: {},
oauthAccessTokens: {},
oauthConsent: {},
ssoProviders: {}
};
});
// Setup before each test
beforeEach(() => {
// Add any setup logic here
// Mock drizzle-orm to prevent database migrations from running
mock.module("drizzle-orm/bun-sqlite/migrator", () => {
return {
migrate: () => {}
};
});
// Mock config encryption utilities
mock.module("@/lib/utils/config-encryption", () => {
return {
decryptConfigTokens: (config: any) => {
// Return the config as-is for tests
return config;
},
encryptConfigTokens: (config: any) => {
// Return the config as-is for tests
return config;
}
};
});
// Add DOM testing support if needed