Repository navigation
Expand file tree
/
Copy pathjunior-requesters.test.mjs
More file actions
88 lines (75 loc) · 2.98 KB
/
Copy pathjunior-requesters.test.mjs
File metadata and controls
88 lines (75 loc) · 2.98 KB
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
81
82
83
84
85
86
87
88
import { describe, expect, it } from 'vitest';
import { attribution, junior, setup } from './github-test-utils.mjs';
import { assignJuniorRequesters, parseJuniorRequesters, resolveLoginByName } from './junior-requesters.mjs';
describe('parseJuniorRequesters', () => {
it('reads linked logins and Slack names', () => {
expect(parseJuniorRequesters(attribution('**Jan Peer Stöcklmair**, @BYK'))).toEqual([
{ name: 'Jan Peer Stöcklmair' },
{ login: 'BYK' },
]);
});
it('skips automation runs', () => {
expect(
parseJuniorRequesters(
attribution('[automation `sched_1`](https://junior-prod.sentry.dev/automations/sched_1) · Run ID `sched_1:1`'),
),
).toEqual([]);
});
it('returns nothing without an attribution block', () => {
expect(parseJuniorRequesters('Some body')).toEqual([]);
expect(parseJuniorRequesters(null)).toEqual([]);
});
});
describe('resolveLoginByName', () => {
const members = [
{ login: 'mydea', name: 'Francesco Gringl-Novy' },
{ login: 'JPeer264', name: 'Jan Peer Stöcklmair' },
{ login: 's1gr1d', name: 'Sigrid' },
{ login: 'isaacs', name: 'isaacs' },
{ login: 'noname', name: null },
];
it('matches the full profile name, ignoring case and accents', () => {
expect(resolveLoginByName('francesco gringl-novy', members)).toBe('mydea');
expect(resolveLoginByName('Jan Peer Stocklmair', members)).toBe('JPeer264');
});
it('matches a single-word profile name to the first name', () => {
expect(resolveLoginByName('Sigrid Someone', members)).toBe('s1gr1d');
});
it('does not match a first name that is ambiguous', () => {
expect(resolveLoginByName('Sigrid Someone', [...members, { login: 'other', name: 'Sigrid' }])).toBeUndefined();
});
it('uses the manual mapping for names that cannot be matched', () => {
expect(resolveLoginByName('Isaac Schlueter', members)).toBe('isaacs');
});
it('does not match unknown people', () => {
expect(resolveLoginByName('Francesco Someone', members)).toBeUndefined();
});
});
describe('assignJuniorRequesters', () => {
it('assigns a Junior PR to its requester', async () => {
const { github, run } = setup(assignJuniorRequesters, {
user: junior,
draft: true,
body: attribution('**Alice Example**'),
});
await run();
expect(github.rest.issues.addAssignees).toHaveBeenCalledWith(expect.objectContaining({ assignees: ['a'] }));
});
it('keeps existing assignees', async () => {
const { github, run } = setup(assignJuniorRequesters, {
user: junior,
assignees: [{ login: 'b' }],
body: attribution('@a'),
});
await run();
expect(github.rest.issues.addAssignees).not.toHaveBeenCalled();
});
it('does not assign PRs opened by people', async () => {
const { github, run } = setup(assignJuniorRequesters, {
user: { login: 'b', type: 'User' },
body: attribution('@a'),
});
await run();
expect(github.rest.issues.addAssignees).not.toHaveBeenCalled();
});
});