fix: add config-encryption mocks to test files for CI compatibility

- Add config-encryption module mocks to gitea-enhanced.test.ts
- Add config-encryption module mocks to gitea-starred-repos.test.ts
- Update helpers mock in setup.bun.ts to include createEvent function

The CI environment was loading modules in a different order than local,
causing the config-encryption module to be accessed before it was mocked
in the global setup. Adding the mocks directly to the test files ensures
they are available regardless of module loading order.
This commit is contained in:
Arunavo Ray
2025-07-27 20:34:38 +05:30
parent 3a9b8380d4
commit 1a77a63a9a
3 changed files with 21 additions and 1 deletions

View File

@@ -25,6 +25,14 @@ mock.module("@/lib/db", () => ({
repositories: {}
}));
// Mock config encryption
mock.module("@/lib/utils/config-encryption", () => ({
decryptConfigTokens: (config: any) => config,
encryptConfigTokens: (config: any) => config,
getDecryptedGitHubToken: (config: any) => config.githubConfig?.token || "",
getDecryptedGiteaToken: (config: any) => config.giteaConfig?.token || ""
}));
// Now import the modules we're testing
import {
getGiteaRepoInfo,

View File

@@ -31,6 +31,14 @@ mock.module("@/lib/db", () => {
};
});
// Mock config encryption
mock.module("@/lib/utils/config-encryption", () => ({
decryptConfigTokens: (config: any) => config,
encryptConfigTokens: (config: any) => config,
getDecryptedGitHubToken: (config: any) => config.githubConfig?.token || "",
getDecryptedGiteaToken: (config: any) => config.giteaConfig?.token || ""
}));
describe("Starred Repository Error Handling", () => {
let originalFetch: typeof global.fetch;
let consoleLogs: string[] = [];

View File

@@ -97,8 +97,12 @@ mock.module("@/lib/utils/config-encryption", () => {
// Mock the helpers module to prevent database operations
mock.module("@/lib/helpers", () => {
const mockCreateMirrorJob = mock(() => Promise.resolve("mock-job-id"));
const mockCreateEvent = mock(() => Promise.resolve());
return {
createMirrorJob: mock(() => Promise.resolve("mock-job-id")),
createMirrorJob: mockCreateMirrorJob,
createEvent: mockCreateEvent,
// Add other helpers as needed
};
});