From 1a77a63a9a19dee1607681346b592ac1b929b655 Mon Sep 17 00:00:00 2001 From: Arunavo Ray Date: Sun, 27 Jul 2025 20:34:38 +0530 Subject: [PATCH] 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. --- src/lib/gitea-enhanced.test.ts | 8 ++++++++ src/lib/gitea-starred-repos.test.ts | 8 ++++++++ src/tests/setup.bun.ts | 6 +++++- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/lib/gitea-enhanced.test.ts b/src/lib/gitea-enhanced.test.ts index 0b32fb4..2fbf28d 100644 --- a/src/lib/gitea-enhanced.test.ts +++ b/src/lib/gitea-enhanced.test.ts @@ -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, diff --git a/src/lib/gitea-starred-repos.test.ts b/src/lib/gitea-starred-repos.test.ts index 5945ea5..a9d71dc 100644 --- a/src/lib/gitea-starred-repos.test.ts +++ b/src/lib/gitea-starred-repos.test.ts @@ -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[] = []; diff --git a/src/tests/setup.bun.ts b/src/tests/setup.bun.ts index 281e970..c9eb724 100644 --- a/src/tests/setup.bun.ts +++ b/src/tests/setup.bun.ts @@ -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 }; });