-
Notifications
You must be signed in to change notification settings - Fork 1
/
git-info.spec.ts
80 lines (53 loc) · 2.64 KB
/
git-info.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import { describe, it, expect, vi } from 'vitest';
import { asyncExec } from '@/utils/os';
import { getTicketIdFromBranchName, shouldValidateTicketId } from '@/utils/git-info';
import { TICKET_ID_REGEX } from '@/constants/ticket-id';
vi.mock('@/utils/os');
describe('[utils/git-info]', () => {
describe('getTicketIdFromBranchName()', () => {
it('should return null when "getBranchName" throws', async () => {
vi.mocked(asyncExec).mockRejectedValueOnce(undefined);
const result = await getTicketIdFromBranchName(/^JUST A TEST$/);
expect(result).toBeNull();
});
it('should return null when "getBranchName" returns with a defined "stderr"', async () => {
vi.mocked(asyncExec).mockResolvedValueOnce({ stdout: '', stderr: 'DUMMY_ERROR' });
const result = await getTicketIdFromBranchName(/^JUST A TEST$/);
expect(result).toBeNull();
});
it('should return null when failed to match ticket Id', async () => {
vi.mocked(asyncExec).mockResolvedValueOnce({ stdout: 'TEST A JUST', stderr: '' });
const result = await getTicketIdFromBranchName(/^JUST A TEST$/);
expect(result === null).toEqual(true);
});
it('should ticket Id when there is one', async () => {
const ticketId = 'CLO-12345';
const ticketIdRegex = new RegExp(TICKET_ID_REGEX);
vi.mocked(asyncExec).mockResolvedValueOnce({ stdout: `[${ticketId}] JUST A TEST`, stderr: '' });
const result = await getTicketIdFromBranchName(ticketIdRegex);
expect(result === ticketId).toEqual(true);
});
});
describe('shouldValidateTicketId()', () => {
it('should return "false" when "getBranchName" throws', async () => {
vi.mocked(asyncExec).mockRejectedValueOnce(undefined);
const result = await shouldValidateTicketId(['JUST A TEST']);
expect(result).toEqual(false);
});
it('should return "false" when "getBranchName" returns with a defined "stderr"', async () => {
vi.mocked(asyncExec).mockResolvedValueOnce({ stdout: '', stderr: 'DUMMY_ERROR' });
const result = await shouldValidateTicketId(['JUST A TEST']);
expect(result).toEqual(false);
});
it('should return "true" when "getBranchName" returns a string contained in the ignored branchrs', async () => {
vi.mocked(asyncExec).mockResolvedValueOnce({ stdout: 'TEST', stderr: '' });
const result = await shouldValidateTicketId(['TEST']);
expect(result).toEqual(false);
});
it('should return "true" when "getBranchName" returns a string which is not contained in the ignored branchrs', async () => {
vi.mocked(asyncExec).mockResolvedValueOnce({ stdout: 'TEST', stderr: '' });
const result = await shouldValidateTicketId(['DUMMY_TEXT']);
expect(result).toEqual(true);
});
});
});