Skip to content

Commit e91c7ab

Browse files
committed
refactor: notification handlers
Signed-off-by: Adam Setch <[email protected]>
1 parent aa3eae9 commit e91c7ab

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

src/renderer/__helpers__/jest.setup.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import axios from 'axios';
99
*/
1010
axios.defaults.adapter = 'http';
1111

12-
1312
/**
1413
* Prevent the following errors with jest:
1514
* - ReferenceError: TextEncoder is not defined
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { partialMockNotification } from '../../../__mocks__/partial-mocks';
2+
import type { SubjectType } from '../../../typesGitHub';
3+
import { checkSuiteHandler } from './checkSuite';
4+
import { commitHandler } from './commit';
5+
import { defaultHandler } from './default';
6+
import { discussionHandler } from './discussion';
7+
import { createNotificationHandler } from './index';
8+
import { issueHandler } from './issue';
9+
import { pullRequestHandler } from './pullRequest';
10+
import { releaseHandler } from './release';
11+
import { repositoryDependabotAlertsThreadHandler } from './repositoryDependabotAlertsThread';
12+
import { repositoryInvitationHandler } from './repositoryInvitation';
13+
import { repositoryVulnerabilityAlertHandler } from './repositoryVulnerabilityAlert';
14+
import { workflowRunHandler } from './workflowRun';
15+
16+
describe('renderer/utils/notifications/handlers/index.ts', () => {
17+
describe('createNotificationHandler', () => {
18+
const cases: Array<[SubjectType, object]> = [
19+
['CheckSuite', checkSuiteHandler],
20+
['Commit', commitHandler],
21+
['Discussion', discussionHandler],
22+
['Issue', issueHandler],
23+
['PullRequest', pullRequestHandler],
24+
['Release', releaseHandler],
25+
[
26+
'RepositoryDependabotAlertsThread',
27+
repositoryDependabotAlertsThreadHandler,
28+
],
29+
['RepositoryInvitation', repositoryInvitationHandler],
30+
['RepositoryVulnerabilityAlert', repositoryVulnerabilityAlertHandler],
31+
['WorkflowRun', workflowRunHandler],
32+
];
33+
34+
it.each(cases)(
35+
'returns expected handler instance for %s',
36+
(type, expected) => {
37+
const notification = partialMockNotification({ type });
38+
const handler = createNotificationHandler(notification);
39+
expect(handler).toBe(expected);
40+
},
41+
);
42+
43+
it('falls back to default handler for unknown type', () => {
44+
const notification = partialMockNotification({
45+
type: 'SomeFutureType' as SubjectType,
46+
});
47+
const handler = createNotificationHandler(notification);
48+
expect(handler).toBe(defaultHandler);
49+
});
50+
});
51+
});

0 commit comments

Comments
 (0)