feat: max-length config (#194)

Co-authored-by: Hiroki Osame <hiroki.osame@gmail.com>
This commit is contained in:
Rocktim
2023-04-25 20:25:45 +05:30
committed by GitHub
parent 4d7712f1e8
commit edce283e9c
7 changed files with 135 additions and 9 deletions

View File

@@ -52,6 +52,35 @@ export default testSuite(({ describe }) => {
const { stdout: commitMessage } = await git('log', ['--oneline']);
console.log('Committed with:', commitMessage);
expect(commitMessage.length <= 50).toBe(true);
await fixture.rm();
});
test('Generated commit message must be under 20 characters', async () => {
const { fixture, aicommits } = await createFixture({
...files,
'.aicommits': `${files['.aicommits']}\nmax-length=20`,
});
const git = await createGit(fixture.path);
await git('add', ['data.json']);
const committing = aicommits();
committing.stdout!.on('data', (buffer: Buffer) => {
const stdout = buffer.toString();
if (stdout.match('└')) {
committing.stdin!.write('y');
committing.stdin!.end();
}
});
await committing;
const { stdout: commitMessage } = await git('log', ['--pretty=format:%s']);
console.log('20 Committed with:', commitMessage, commitMessage.length);
expect(commitMessage.length <= 20).toBe(true);
await fixture.rm();
});
@@ -84,6 +113,7 @@ export default testSuite(({ describe }) => {
const { stdout: commitMessage } = await git('log', ['-n1', '--oneline']);
console.log('Committed with:', commitMessage);
expect(commitMessage.length <= 50).toBe(true);
await fixture.rm();
});
@@ -123,6 +153,7 @@ export default testSuite(({ describe }) => {
const { stdout: commitMessage } = await git('log', ['--oneline']);
console.log('Committed with:', commitMessage);
expect(commitMessage.length <= 50).toBe(true);
await fixture.rm();
});
@@ -157,6 +188,7 @@ export default testSuite(({ describe }) => {
const { stdout: commitMessage } = await git('log', ['--oneline']);
console.log('Committed with:', commitMessage);
expect(commitMessage).toMatch(japanesePattern);
expect(commitMessage.length <= 50).toBe(true);
await fixture.rm();
});
@@ -217,6 +249,7 @@ export default testSuite(({ describe }) => {
const { stdout: commitMessage } = await git('log', ['--oneline']);
console.log('Committed with:', commitMessage);
expect(commitMessage.length <= 50).toBe(true);
await fixture.rm();
});
@@ -248,6 +281,7 @@ export default testSuite(({ describe }) => {
const { stdout: commitMessage } = await git('log', ['--oneline']);
console.log('Committed with:', commitMessage);
expect(commitMessage.length <= 50).toBe(true);
await fixture.rm();
});

View File

@@ -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);
});