mirror of
https://github.com/RayLabsHQ/gitea-mirror.git
synced 2025-12-09 13:06:45 +03:00
Fix tests
This commit is contained in:
@@ -4,6 +4,10 @@ import fs from "fs";
|
||||
import path from "path";
|
||||
import { migrate } from "drizzle-orm/bun-sqlite/migrator";
|
||||
|
||||
// Skip database initialization in test environment
|
||||
let db: ReturnType<typeof drizzle>;
|
||||
|
||||
if (process.env.NODE_ENV !== "test") {
|
||||
// Define the database URL - for development we'll use a local SQLite file
|
||||
const dataDir = path.join(process.cwd(), "data");
|
||||
// Ensure data directory exists
|
||||
@@ -29,7 +33,7 @@ try {
|
||||
}
|
||||
|
||||
// Create drizzle instance with the SQLite client
|
||||
export const db = drizzle({ client: sqlite });
|
||||
db = drizzle({ client: sqlite });
|
||||
|
||||
/**
|
||||
* Run Drizzle migrations
|
||||
@@ -59,6 +63,9 @@ function runDrizzleMigrations() {
|
||||
|
||||
// Run Drizzle migrations after db is initialized
|
||||
runDrizzleMigrations();
|
||||
}
|
||||
|
||||
export { db };
|
||||
|
||||
// Export all table definitions from schema
|
||||
export {
|
||||
|
||||
@@ -480,6 +480,9 @@ export async function getOrCreateGiteaOrg({
|
||||
try {
|
||||
console.log(`Attempting to get or create Gitea organization: ${orgName}`);
|
||||
|
||||
// Decrypt config tokens for API usage
|
||||
const decryptedConfig = decryptConfigTokens(config as Config);
|
||||
|
||||
const orgRes = await fetch(
|
||||
`${config.giteaConfig.url}/api/v1/orgs/${orgName}`,
|
||||
{
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user