Skip to content

Commit b4039d8

Browse files
committed
test: isolate config command mocks
1 parent faab965 commit b4039d8

2 files changed

Lines changed: 14 additions & 18 deletions

File tree

test/commands/config/set.test.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
1-
import { describe, it, expect, mock } from 'bun:test';
1+
import { describe, it, expect } from 'bun:test';
22
import { default as setCommand } from '../../../src/commands/config/set';
33

4-
// Mock file I/O
5-
mock.module('../../../src/config/loader', () => ({
6-
readConfigFile: () => ({}),
7-
writeConfigFile: mock(() => Promise.resolve()),
8-
}));
9-
104
describe('config set command', () => {
115
it('has correct name', () => {
126
expect(setCommand.name).toBe('config set');

test/commands/config/show.test.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
1-
import { describe, it, expect, mock } from 'bun:test';
1+
import { describe, it, expect, spyOn } from 'bun:test';
22
import { default as showCommand } from '../../../src/commands/config/show';
3+
import * as configLoader from '../../../src/config/loader';
34

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+
};
1412

1513
describe('config show command', () => {
1614
it('has correct name', () => {
1715
expect(showCommand.name).toBe('config show');
1816
});
1917

2018
it('shows configuration', async () => {
19+
const readConfigFile = spyOn(configLoader, 'readConfigFile').mockReturnValue(CONFIG_FILE);
2120
const config = {
2221
apiKey: 'test-key',
2322
region: 'global' as const,
@@ -54,10 +53,12 @@ describe('config show command', () => {
5453
expect(parsed.timeout).toBe(300);
5554
} finally {
5655
console.log = originalLog;
56+
readConfigFile.mockRestore();
5757
}
5858
});
5959

6060
it('includes default models in output', async () => {
61+
const readConfigFile = spyOn(configLoader, 'readConfigFile').mockReturnValue(CONFIG_FILE);
6162
const config = {
6263
region: 'global' as const,
6364
baseUrl: 'https://api.mmx.io',
@@ -95,6 +96,7 @@ describe('config show command', () => {
9596
expect(parsed.default_music_model).toBe('music-2.6');
9697
} finally {
9798
console.log = originalLog;
99+
readConfigFile.mockRestore();
98100
}
99101
});
100102
});

0 commit comments

Comments
 (0)