forked from kentaro-m/auto-assign-action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.test.ts
80 lines (72 loc) · 1.79 KB
/
run.test.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 { mocked } from 'jest-mock'
import * as core from '@actions/core'
import * as github from '@actions/github'
import { run } from '../src/run'
import * as utils from '../src/utils'
import * as handler from '../src/handler'
jest.mock('@actions/core')
jest.mock('@actions/github')
jest.mock('../src/utils')
jest.mock('../src/handler')
const mockedUtils = mocked(utils)
const coreMocked = mocked(core)
const mockedHandler = mocked(handler)
describe.only('run', () => {
beforeEach(() => {
// @ts-ignore
github.context = {
eventName: '',
workflow: '',
action: '',
actor: '',
payload: {
action: 'opened',
number: '1',
pull_request: {
number: 1,
title: 'test',
user: {
login: 'pr-creator',
},
},
repository: {
name: 'auto-assign',
owner: {
login: 'kentaro-m',
},
},
},
repo: {
owner: 'kentaro-m',
repo: 'auto-assign',
},
issue: {
owner: 'kentaro-m',
repo: 'auto-assign',
number: 1,
},
sha: '',
ref: '',
}
})
test('succeeds the process', async () => {
coreMocked.getInput.mockImplementation((name) => {
switch (name) {
case 'repo-token':
return 'token'
case 'configuration-path':
return '.github/auto_assign.yml'
default:
return ''
}
})
mockedUtils.fetchConfigurationFile.mockImplementation(async () => ({
addAssignees: false,
addReviewers: true,
reviewers: ['reviewerA', 'reviewerB', 'reviewerC'],
}))
mockedHandler.handlePullRequest.mockImplementation(async () => {})
await run()
expect(mockedHandler.handlePullRequest).toBeCalled()
})
})