Skip to content

Commit 8aa301e

Browse files
authored
fix: added async and await like if there's no tomorrow (#9)
1 parent 4b6f23f commit 8aa301e

File tree

8 files changed

+303
-209
lines changed

8 files changed

+303
-209
lines changed

__test__/inputs.test.ts

Lines changed: 43 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -30,41 +30,53 @@ describe('inputsHelper tests', () => {
3030
jest.resetModules()
3131
})
3232

33-
it('requires token', () => {
34-
assert.throws(() => {
35-
inputsHelper.getInputs()
36-
}, /token can't be an empty string/)
33+
it('requires token', async () => {
34+
expect.assertions(1)
35+
await expect(inputsHelper.getInputs()).rejects.toEqual(
36+
TypeError("token can't be an empty string")
37+
)
3738
})
3839

39-
it('requires name', () => {
40+
it('requires name', async () => {
41+
expect.assertions(1)
42+
4043
inputs.token = '1234567abcdefg'
41-
assert.throws(() => {
42-
inputsHelper.getInputs()
43-
}, /name can't be an empty string/)
44+
45+
await expect(inputsHelper.getInputs()).rejects.toEqual(
46+
TypeError("name can't be an empty string")
47+
)
4448
})
4549

46-
it('requires status', () => {
50+
it('requires status', async () => {
51+
expect.assertions(1)
52+
4753
inputs.name = 'my_name'
4854
inputs.token = '1234567abcdefg'
49-
assert.throws(() => {
50-
inputsHelper.getInputs()
51-
}, /status can't be an empty string/)
55+
56+
await expect(inputsHelper.getInputs()).rejects.toEqual(
57+
TypeError("status can't be an empty string")
58+
)
5259
})
5360

54-
it('requires valid commit status', () => {
61+
it('requires valid commit status', async () => {
62+
expect.assertions(1)
63+
5564
inputs.name = 'my_name'
5665
inputs.token = '1234567abcdefg'
5766
inputs.status = 'bleh'
58-
assert.throws(() => {
59-
inputsHelper.getInputs()
60-
}, /TypeError: unknown commit or job status: bleh/)
67+
68+
await expect(inputsHelper.getInputs()).rejects.toEqual(
69+
TypeError('unknown commit or job status: bleh')
70+
)
6171
})
6272

63-
it('sets correct default values', () => {
73+
it('sets correct default values', async () => {
6474
inputs.name = 'my_name'
6575
inputs.token = '1234567abcdefg'
6676
inputs.status = 'Success'
67-
const params: IParams = inputsHelper.getInputs()
77+
78+
const params: IParams = await inputsHelper.getInputs()
79+
6880
expect(params).toBeTruthy()
6981
expect(params.name).toBe('my_name')
7082
expect(params.token).toBe('1234567abcdefg')
@@ -79,7 +91,7 @@ describe('inputsHelper tests', () => {
7991
expect(params.ignoreForks).toBeTruthy()
8092
})
8193

82-
it('sets success status', () => {
94+
it('sets success status', async () => {
8395
inputs.singleShot = 'false'
8496
inputs.status = 'Success'
8597
inputs.token = 'my_token'
@@ -92,7 +104,8 @@ describe('inputsHelper tests', () => {
92104
inputs.successComment = '/hold cancel'
93105
inputs.failComment = '/hold fail'
94106

95-
const params: IParams = inputsHelper.getInputs()
107+
const params: IParams = await inputsHelper.getInputs()
108+
96109
expect(params).toBeTruthy()
97110
expect(params.token).toBe('my_token')
98111
expect(params.url).toBe('my_url')
@@ -107,8 +120,7 @@ describe('inputsHelper tests', () => {
107120
expect(params.ignoreForks).toBeTruthy()
108121
})
109122

110-
it('sets pending status', () => {
111-
const isPost = true
123+
it('sets pending status', async () => {
112124
inputs.singleShot = 'false'
113125
inputs.status = 'Pending'
114126
inputs.token = 'my_token'
@@ -121,7 +133,8 @@ describe('inputsHelper tests', () => {
121133
inputs.successComment = '/hold cancel'
122134
inputs.failComment = '/hold fail'
123135

124-
const params: IParams = inputsHelper.getInputs(isPost)
136+
const params: IParams = await inputsHelper.getInputs()
137+
125138
expect(params).toBeTruthy()
126139
expect(params.token).toBe('my_token')
127140
expect(params.url).toBe('')
@@ -136,7 +149,7 @@ describe('inputsHelper tests', () => {
136149
expect(params.ignoreForks).toBeFalsy()
137150
})
138151

139-
it('sets correct status and comment', () => {
152+
it('sets correct status and comment', async () => {
140153
inputs.singleShot = 'false'
141154
inputs.token = 'my_token'
142155
inputs.url = ''
@@ -149,31 +162,32 @@ describe('inputsHelper tests', () => {
149162
inputs.successComment = '/hold cancel'
150163
inputs.failComment = '/hold fail'
151164

152-
let params: IParams = inputsHelper.getInputs()
165+
let params: IParams = await inputsHelper.getInputs()
166+
153167
expect(params).toBeTruthy()
154168
expect(params.status).toBe('success')
155169
expect(params.selectedComment).toBe('/hold cancel')
156170

157171
inputs.status = 'pending'
158-
params = inputsHelper.getInputs()
172+
params = await inputsHelper.getInputs()
159173
expect(params).toBeTruthy()
160174
expect(params.status).toBe('pending')
161175
expect(params.selectedComment).toBe('/hold')
162176

163177
inputs.status = 'failure'
164-
params = inputsHelper.getInputs()
178+
params = await inputsHelper.getInputs()
165179
expect(params).toBeTruthy()
166180
expect(params.status).toBe('failure')
167181
expect(params.selectedComment).toBe('/hold fail')
168182

169183
inputs.status = 'cancelled'
170-
params = inputsHelper.getInputs()
184+
params = await inputsHelper.getInputs()
171185
expect(params).toBeTruthy()
172186
expect(params.status).toBe('failure')
173187
expect(params.selectedComment).toBe('/hold fail')
174188

175189
inputs.status = 'error'
176-
params = inputsHelper.getInputs()
190+
params = await inputsHelper.getInputs()
177191
expect(params).toBeTruthy()
178192
expect(params.status).toBe('error')
179193
expect(params.selectedComment).toBe('/hold fail')

__test__/runner.test.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ describe('runner tests', () => {
3535
jest.resetModules()
3636
})
3737

38-
it('run sets status and comment', () => {
38+
it('run sets status and comment', async () => {
3939
const params = ({} as unknown) as IParams
4040
params.token = 'bleh'
4141
params.ignoreForks = true
@@ -44,13 +44,15 @@ describe('runner tests', () => {
4444
mockInputsHelper.getInputs.mockReturnValue(params)
4545
mockGithubHelper.CreateGithubHelper.mockReturnValue(mockIGithubHelper)
4646
mockIGithubHelper.isFork.mockReturnValue(false)
47-
runner.run()
47+
48+
await runner.run()
49+
4850
expect(mockUtils.validateEventType).toHaveBeenCalled()
4951
expect(mockIGithubHelper.setStatus).toHaveBeenCalledWith(params)
5052
expect(mockIGithubHelper.addComment).toHaveBeenCalledWith('my comment')
5153
})
5254

53-
it('run sets status and no comment', () => {
55+
it('run sets status and no comment', async () => {
5456
const params = ({} as unknown) as IParams
5557
params.token = 'bleh'
5658
params.ignoreForks = true
@@ -59,13 +61,15 @@ describe('runner tests', () => {
5961
mockInputsHelper.getInputs.mockReturnValue(params)
6062
mockGithubHelper.CreateGithubHelper.mockReturnValue(mockIGithubHelper)
6163
mockIGithubHelper.isFork.mockReturnValue(false)
62-
runner.run()
64+
65+
await runner.run()
66+
6367
expect(mockUtils.validateEventType).toHaveBeenCalled()
6468
expect(mockIGithubHelper.setStatus).toHaveBeenCalledWith(params)
6569
expect(mockIGithubHelper.addComment).toHaveBeenCalledTimes(0)
6670
})
6771

68-
it('run does not set status or comment', () => {
72+
it('run does not set status or comment', async () => {
6973
const params = ({} as unknown) as IParams
7074
params.token = 'bleh'
7175
params.ignoreForks = true
@@ -74,21 +78,25 @@ describe('runner tests', () => {
7478
mockInputsHelper.getInputs.mockReturnValue(params)
7579
mockGithubHelper.CreateGithubHelper.mockReturnValue(mockIGithubHelper)
7680
mockIGithubHelper.isFork.mockReturnValue(true)
77-
runner.run()
81+
82+
await runner.run()
83+
7884
expect(mockUtils.validateEventType).toHaveBeenCalled()
7985
expect(mockIGithubHelper.setStatus).toHaveBeenCalledTimes(0)
8086
expect(mockIGithubHelper.addComment).toHaveBeenCalledTimes(0)
8187
})
8288

83-
it('run sets status if ignore fork false', () => {
89+
it('run sets status if ignore fork false', async () => {
8490
const params = ({} as unknown) as IParams
8591
params.token = 'bleh'
8692
params.ignoreForks = false
8793
params.addHoldComment = true
8894
params.selectedComment = 'my comment'
8995
mockInputsHelper.getInputs.mockReturnValue(params)
9096
mockGithubHelper.CreateGithubHelper.mockReturnValue(mockIGithubHelper)
91-
runner.run()
97+
98+
await runner.run()
99+
92100
expect(mockUtils.validateEventType).toHaveBeenCalled()
93101
expect(mockIGithubHelper.isFork).toHaveBeenCalledTimes(0)
94102
expect(mockIGithubHelper.setStatus).toHaveBeenCalledWith(params)

0 commit comments

Comments
 (0)