Skip to content

Commit be6cf82

Browse files
Improve backend tests by mocking the env module to simulate missing BENCHIFY_API_KEY. This replaces brittle spy usage and ensures resilience when Benchify is disabled.
🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
1 parent e1b363e commit be6cf82

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

backend/src/__tests__/process-str-replace.test.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -487,10 +487,19 @@ describe('Benchify resilience', () => {
487487
})
488488

489489
it('should fall back gracefully when Benchify is disabled', async () => {
490-
// Test with no API key - spy on the env object directly
491-
spyOn(envModule, 'env', 'get').mockReturnValue({
492-
// Empty object simulates no BENCHIFY_API_KEY
493-
} as any)
490+
// Test with no API key - mock the entire env module
491+
const mockEnv = {
492+
BENCHIFY_API_KEY: undefined,
493+
// Add other required env properties that might be accessed
494+
PORT: 3001,
495+
OPEN_ROUTER_API_KEY: 'mock-key',
496+
RELACE_API_KEY: 'mock-key',
497+
LINKUP_API_KEY: 'mock-key',
498+
} as any
499+
Object.defineProperty(envModule, 'env', {
500+
get: () => mockEnv,
501+
configurable: true,
502+
})
494503

495504
const result = await executeBatchStrReplaces({
496505
deferredStrReplaces: [

0 commit comments

Comments
 (0)