feat: max-length config (#194)
Co-authored-by: Hiroki Osame <hiroki.osame@gmail.com>
This commit is contained in:
@@ -25,6 +25,18 @@ export default testSuite(({ describe }) => {
|
||||
expect(stderr).toMatch('Invalid config property OPENAI_KEY: Must start with "sk-"');
|
||||
});
|
||||
|
||||
await test('set config file', async () => {
|
||||
await aicommits(['config', 'set', openAiToken]);
|
||||
|
||||
const configFile = await fs.readFile(configPath, 'utf8');
|
||||
expect(configFile).toMatch(openAiToken);
|
||||
});
|
||||
|
||||
await test('get config file', async () => {
|
||||
const { stdout } = await aicommits(['config', 'get', 'OPENAI_KEY']);
|
||||
expect(stdout).toBe(openAiToken);
|
||||
});
|
||||
|
||||
await test('reading unknown config', async () => {
|
||||
await fs.appendFile(configPath, 'UNKNOWN=1');
|
||||
|
||||
@@ -57,6 +69,38 @@ export default testSuite(({ describe }) => {
|
||||
});
|
||||
});
|
||||
|
||||
await describe('max-length', ({ test }) => {
|
||||
test('must be an integer', async () => {
|
||||
const { stderr } = await aicommits(['config', 'set', 'max-length=abc'], {
|
||||
reject: false,
|
||||
});
|
||||
|
||||
expect(stderr).toMatch('Must be an integer');
|
||||
});
|
||||
|
||||
test('must be at least 20 characters', async () => {
|
||||
const { stderr } = await aicommits(['config', 'set', 'max-length=10'], {
|
||||
reject: false,
|
||||
});
|
||||
|
||||
expect(stderr).toMatch(/must be greater than 20 characters/i);
|
||||
});
|
||||
|
||||
test('updates config', async () => {
|
||||
const defaultConfig = await aicommits(['config', 'get', 'max-length']);
|
||||
expect(defaultConfig.stdout).toBe('max-length=50');
|
||||
|
||||
const maxLength = 'max-length=60';
|
||||
await aicommits(['config', 'set', maxLength]);
|
||||
|
||||
const configFile = await fs.readFile(configPath, 'utf8');
|
||||
expect(configFile).toMatch(maxLength);
|
||||
|
||||
const get = await aicommits(['config', 'get', 'max-length']);
|
||||
expect(get.stdout).toBe(maxLength);
|
||||
});
|
||||
});
|
||||
|
||||
await test('set config file', async () => {
|
||||
await aicommits(['config', 'set', openAiToken]);
|
||||
|
||||
@@ -66,7 +110,6 @@ export default testSuite(({ describe }) => {
|
||||
|
||||
await test('get config file', async () => {
|
||||
const { stdout } = await aicommits(['config', 'get', 'OPENAI_KEY']);
|
||||
|
||||
expect(stdout).toBe(openAiToken);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user