@@ -3,6 +3,10 @@ const crypto = require('crypto')
3
3
const stream = require ( 'stream' )
4
4
const https = require ( 'https' )
5
5
6
+ afterEach ( ( ) => {
7
+ jest . clearAllMocks ( ) ;
8
+ } )
9
+
6
10
process . env [ 'GITHUB_WEBHOOK_SECRET' ] = 'for-testing'
7
11
process . env [ 'GITGITGADGET_TRIGGER_TOKEN' ] = 'token-for-testing'
8
12
@@ -84,8 +88,12 @@ const makeContext = (body, headers) => {
84
88
}
85
89
}
86
90
87
- const testIssueComment = ( comment , fn ) => {
88
- const repoOwner = 'gitgitgadget'
91
+ const testIssueComment = ( comment , repoOwner , fn ) => {
92
+ if ( ! fn ) {
93
+ fn = repoOwner
94
+ repoOwner = undefined
95
+ }
96
+ repoOwner ||= 'gitgitgadget'
89
97
const number = 0x70756c6c
90
98
const context = makeContext ( {
91
99
action : 'created' ,
@@ -140,3 +148,13 @@ testIssueComment('/test', async (context) => {
140
148
} )
141
149
expect ( mockRequest . end ) . toHaveBeenCalledTimes ( 1 )
142
150
} )
151
+
152
+ testIssueComment ( '/verify-repository' , 'nope' , ( context ) => {
153
+ expect ( context . done ) . toHaveBeenCalledTimes ( 1 )
154
+ expect ( context . res ) . toEqual ( {
155
+ body : 'Refusing to work on a repository other than gitgitgadget/git or git/git' ,
156
+ 'status' : 403 ,
157
+ } )
158
+ expect ( mockRequest . write ) . not . toHaveBeenCalled ( )
159
+ expect ( mockRequest . end ) . not . toHaveBeenCalled ( )
160
+ } )
0 commit comments