|
1 | | -import { describe, it, expect, mock } from 'bun:test'; |
| 1 | +import { describe, it, expect, spyOn } from 'bun:test'; |
2 | 2 | import { default as showCommand } from '../../../src/commands/config/show'; |
| 3 | +import * as configLoader from '../../../src/config/loader'; |
3 | 4 |
|
4 | | -// Mock file I/O |
5 | | -mock.module('../../../src/config/loader', () => ({ |
6 | | - readConfigFile: () => ({ |
7 | | - api_key: 'sk-cp-test-key', |
8 | | - default_text_model: 'MiniMax-M2.7-highspeed', |
9 | | - default_speech_model: 'speech-2.8-hd', |
10 | | - default_video_model: 'MiniMax-Hailuo-2.3-6s-768p', |
11 | | - default_music_model: 'music-2.6', |
12 | | - }), |
13 | | -})); |
| 5 | +const CONFIG_FILE = { |
| 6 | + api_key: 'sk-cp-test-key', |
| 7 | + default_text_model: 'MiniMax-M2.7-highspeed', |
| 8 | + default_speech_model: 'speech-2.8-hd', |
| 9 | + default_video_model: 'MiniMax-Hailuo-2.3-6s-768p', |
| 10 | + default_music_model: 'music-2.6', |
| 11 | +}; |
14 | 12 |
|
15 | 13 | describe('config show command', () => { |
16 | 14 | it('has correct name', () => { |
17 | 15 | expect(showCommand.name).toBe('config show'); |
18 | 16 | }); |
19 | 17 |
|
20 | 18 | it('shows configuration', async () => { |
| 19 | + const readConfigFile = spyOn(configLoader, 'readConfigFile').mockReturnValue(CONFIG_FILE); |
21 | 20 | const config = { |
22 | 21 | apiKey: 'test-key', |
23 | 22 | region: 'global' as const, |
@@ -54,10 +53,12 @@ describe('config show command', () => { |
54 | 53 | expect(parsed.timeout).toBe(300); |
55 | 54 | } finally { |
56 | 55 | console.log = originalLog; |
| 56 | + readConfigFile.mockRestore(); |
57 | 57 | } |
58 | 58 | }); |
59 | 59 |
|
60 | 60 | it('includes default models in output', async () => { |
| 61 | + const readConfigFile = spyOn(configLoader, 'readConfigFile').mockReturnValue(CONFIG_FILE); |
61 | 62 | const config = { |
62 | 63 | region: 'global' as const, |
63 | 64 | baseUrl: 'https://api.mmx.io', |
@@ -95,6 +96,7 @@ describe('config show command', () => { |
95 | 96 | expect(parsed.default_music_model).toBe('music-2.6'); |
96 | 97 | } finally { |
97 | 98 | console.log = originalLog; |
| 99 | + readConfigFile.mockRestore(); |
98 | 100 | } |
99 | 101 | }); |
100 | 102 | }); |
0 commit comments