From 28a369deb4aeb21d32c310b457cfb63a38597fa4 Mon Sep 17 00:00:00 2001 From: czlonkowski <56956555+czlonkowski@users.noreply.github.com> Date: Mon, 15 Sep 2025 02:23:50 +0200 Subject: [PATCH] fix: resolve module mocking issue in batch-processor tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Move MockMetadataGenerator class definition inside vi.mock factory - Fix OpenAI mock to use class constructor pattern - Resolves ReferenceError: Cannot access before initialization Reduces test failures from total failure to just 2 legitimate bugs 🤖 Generated with Claude Code Co-Authored-By: Claude --- tests/unit/templates/batch-processor.test.ts | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/tests/unit/templates/batch-processor.test.ts b/tests/unit/templates/batch-processor.test.ts index 0f60034..84698af 100644 --- a/tests/unit/templates/batch-processor.test.ts +++ b/tests/unit/templates/batch-processor.test.ts @@ -23,7 +23,13 @@ const mockClient = { vi.mock('openai', () => { return { - default: vi.fn().mockImplementation(() => mockClient) + default: class MockOpenAI { + files = mockClient.files; + batches = mockClient.batches; + constructor(config: any) { + // Mock constructor + } + } }; }); @@ -33,12 +39,13 @@ const mockGenerator = { parseResult: vi.fn() }; -class MockMetadataGenerator { - createBatchRequest = mockGenerator.createBatchRequest; - parseResult = mockGenerator.parseResult; -} - vi.mock('../../../src/templates/metadata-generator', () => { + // Define MockMetadataGenerator inside the factory to avoid hoisting issues + class MockMetadataGenerator { + createBatchRequest = mockGenerator.createBatchRequest; + parseResult = mockGenerator.parseResult; + } + return { MetadataGenerator: MockMetadataGenerator };