-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathindex.test.js
More file actions
55 lines (47 loc) · 1.57 KB
/
Copy pathindex.test.js
File metadata and controls
55 lines (47 loc) · 1.57 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
const createFile = require('./')
const mockContext = require('../../tests/mockContext')
describe('createFile', () => {
let context
beforeEach(() => {
context = mockContext({
pull_request: {
head: {
sha: 123
}
}
}, {
repos: {
createFile: jest.fn()
}
})
})
it('creates a new file', async () => {
context.fromFile = () => Promise.resolve('Hello!')
await createFile(context, { filename: 'filename' })
expect(context.github.repos.createFile.mock.calls).toMatchSnapshot()
})
it('replaces file contents with context variables', async () => {
await createFile(context, {
filename: 'filename',
content: 'Hello {{ login }}!',
branch: 'a-feature-branch',
data: {
login: 'Jason'
}
})
expect(context.github.repos.createFile.mock.calls).toMatchSnapshot()
})
it('can choose a new filename', async () => {
await createFile(context, { filename: 'filename', new_name: 'CODEOWNERS' })
expect(context.github.repos.createFile.mock.calls).toMatchSnapshot()
})
it('can set a custom commit message', async () => {
await createFile(context, { filename: 'filename', message: 'Hello!' })
expect(context.github.repos.createFile.mock.calls[0][0].message).toBe('Hello!')
})
it('creates a new file on the given branch', async () => {
context.fromFile = () => Promise.resolve('Hello!')
await createFile(context, { filename: 'filename', branch: 'a-feature-branch' })
expect(context.github.repos.createFile.mock.calls).toMatchSnapshot()
})
})