0
0
Fork 0
mirror of https://github.com/renovatebot/renovate.git synced 2025-03-16 09:03:59 +00:00
renovatebot_renovate/lib/util/git/author.spec.ts
2025-03-13 15:48:02 +00:00

55 lines
1.5 KiB
TypeScript

import addrs from 'email-addresses';
import { parseGitAuthor } from './author';
vi.mock('email-addresses', { spy: true });
describe('util/git/author', () => {
describe('parseGitAuthor', () => {
it('returns null if empty email given', () => {
expect(parseGitAuthor(undefined as never)).toBeNull();
});
it('catches errors', () => {
vi.mocked(addrs.parseOneAddress).mockImplementationOnce(() => {
throw new Error('foo');
});
expect(parseGitAuthor('renovate@whitesourcesoftware.com')).toBeNull();
});
it('handles a normal address', () => {
expect(parseGitAuthor('renovate@whitesourcesoftware.com')).not.toBeNull();
});
it('parses bot email', () => {
expect(parseGitAuthor('renovate[bot]@users.noreply.github.com')).toEqual({
address: 'renovate[bot]@users.noreply.github.com',
name: 'renovate[bot]',
});
});
it('parses bot name and email', () => {
expect(
parseGitAuthor(
'renovate[bot] <renovate[bot]@users.noreply.github.com>',
),
).toEqual({
address: 'renovate[bot]@users.noreply.github.com',
name: 'renovate[bot]',
});
});
it('escapes names', () => {
expect(parseGitAuthor('name [what] <name@what.com>')?.name).toBe(
`name [what]`,
);
});
it('tries again and fails', () => {
expect(parseGitAuthor('foo<foo>')).toBeNull();
});
it('gives up', () => {
expect(parseGitAuthor('a.b.c')).toBeNull();
});
});
});