|
| 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