1
1
'use strict'
2
2
3
- const figgyPudding = require ( 'figgy-pudding' )
3
+ // const figgyPudding = require('figgy-pudding')
4
4
const test = require ( 'tap' ) . test
5
- const tnock = require ( './util /tnock.js' )
5
+ const tnock = require ( './fixtures /tnock.js' )
6
6
7
7
const hooks = require ( '../index.js' )
8
8
9
- const OPTS = figgyPudding ( { registry : { } } ) ( {
9
+ const OPTS = {
10
10
registry : 'https://mock.reg/'
11
- } )
11
+ }
12
+
12
13
const HOOK_URL = 'https://my.hook.url/'
14
+ const REG = 'https://registry.npmjs.org/'
15
+
16
+ test ( 'add package hook with no options' , t => {
17
+ const params = {
18
+ type : 'package' ,
19
+ name : 'mypkg' ,
20
+ endpoint : HOOK_URL ,
21
+ secret : 'sekrit'
22
+ }
23
+ const hook = Object . assign ( {
24
+ id : 'deadbeef' ,
25
+ status : 'active'
26
+ } , params )
27
+ tnock ( t , REG )
28
+ . post ( '/-/npm/v1/hooks/hook' , params )
29
+ . reply ( 200 , hook )
30
+ return hooks . add ( 'mypkg' , HOOK_URL , 'sekrit' )
31
+ . then ( json => t . deepEqual ( json , hook ) )
32
+ } )
13
33
14
34
test ( 'add package hook' , t => {
15
35
const params = {
@@ -83,6 +103,14 @@ test('add scope hook', t => {
83
103
. then ( json => t . deepEqual ( json , hook ) )
84
104
} )
85
105
106
+ test ( 'rm with no options' , t => {
107
+ tnock ( t , REG )
108
+ . delete ( '/-/npm/v1/hooks/hook/hithere' )
109
+ . reply ( 200 , { id : 'hithere' } )
110
+ return hooks . rm ( 'hithere' )
111
+ . then ( json => t . equal ( json . id , 'hithere' ) )
112
+ } )
113
+
86
114
test ( 'rm' , t => {
87
115
tnock ( t , OPTS . registry )
88
116
. delete ( '/-/npm/v1/hooks/hook/hithere' )
@@ -109,6 +137,14 @@ test('rm null on other err', t => {
109
137
)
110
138
} )
111
139
140
+ test ( 'find with no options' , t => {
141
+ tnock ( t , REG )
142
+ . get ( '/-/npm/v1/hooks/hook/hithere' )
143
+ . reply ( 200 , { id : 'hithere' } )
144
+ return hooks . find ( 'hithere' )
145
+ . then ( json => t . equal ( json . id , 'hithere' ) )
146
+ } )
147
+
112
148
test ( 'find' , t => {
113
149
tnock ( t , OPTS . registry )
114
150
. get ( '/-/npm/v1/hooks/hook/hithere' )
@@ -117,6 +153,35 @@ test('find', t => {
117
153
. then ( json => t . equal ( json . id , 'hithere' ) )
118
154
} )
119
155
156
+ test ( 'ls' , t => {
157
+ const entries = [
158
+ { id : 'first' } ,
159
+ { id : 'second' } ,
160
+ { id : 'third' }
161
+ ]
162
+ tnock ( t , REG )
163
+ . get ( '/-/npm/v1/hooks' )
164
+ . reply ( 200 , { objects : entries } )
165
+ return hooks . ls ( ) . then (
166
+ json => t . deepEqual ( json , entries )
167
+ )
168
+ } )
169
+
170
+ test ( 'ls.stream' , t => {
171
+ const entries = [
172
+ { id : 'first' } ,
173
+ { id : 'second' } ,
174
+ { id : 'third' }
175
+ ]
176
+ tnock ( t , REG )
177
+ . get ( '/-/npm/v1/hooks' )
178
+ . reply ( 200 , { objects : entries } )
179
+
180
+ return hooks . ls . stream ( ) . collect ( ) . then (
181
+ json => t . deepEqual ( json , entries )
182
+ )
183
+ } )
184
+
120
185
test ( 'ls' , t => {
121
186
const entries = [
122
187
{ id : 'first' } ,
@@ -140,9 +205,10 @@ test('ls package', t => {
140
205
tnock ( t , OPTS . registry )
141
206
. get ( '/-/npm/v1/hooks?package=%40npm%2Fhooks' )
142
207
. reply ( 200 , { objects : entries } )
143
- return hooks . ls ( OPTS . concat ( {
208
+ return hooks . ls ( {
209
+ ...OPTS ,
144
210
package : '@npm/hooks'
145
- } ) ) . then ( json => t . deepEqual ( json , entries ) )
211
+ } ) . then ( json => t . deepEqual ( json , entries ) )
146
212
} )
147
213
148
214
test ( 'ls limit+offset' , t => {
@@ -154,10 +220,11 @@ test('ls limit+offset', t => {
154
220
tnock ( t , OPTS . registry )
155
221
. get ( '/-/npm/v1/hooks?limit=10&offset=20' )
156
222
. reply ( 200 , { objects : entries } )
157
- return hooks . ls ( OPTS . concat ( {
223
+ return hooks . ls ( {
224
+ ...OPTS ,
158
225
limit : 10 ,
159
226
offset : 20
160
- } ) ) . then ( json => t . deepEqual ( json , entries ) )
227
+ } ) . then ( json => t . deepEqual ( json , entries ) )
161
228
} )
162
229
163
230
test ( 'ls package+limit+offset' , t => {
@@ -169,11 +236,22 @@ test('ls package+limit+offset', t => {
169
236
tnock ( t , OPTS . registry )
170
237
. get ( '/-/npm/v1/hooks?package=%40npm%2Fhooks&limit=10&offset=20' )
171
238
. reply ( 200 , { objects : entries } )
172
- return hooks . ls ( OPTS . concat ( {
239
+ return hooks . ls ( {
240
+ ...OPTS ,
173
241
limit : 10 ,
174
242
offset : 20 ,
175
243
package : '@npm/hooks'
176
- } ) ) . then ( json => t . deepEqual ( json , entries ) )
244
+ } ) . then ( json => t . deepEqual ( json , entries ) )
245
+ } )
246
+ test ( 'update with no options' , t => {
247
+ tnock ( t , REG )
248
+ . put ( '/-/npm/v1/hooks/hook/hi' )
249
+ . reply ( 200 , ( uri , body ) => body )
250
+ return hooks . update ( 'hi' , HOOK_URL , 'sekrit' )
251
+ . then ( json => t . deepEqual ( json , {
252
+ endpoint : HOOK_URL ,
253
+ secret : 'sekrit'
254
+ } ) )
177
255
} )
178
256
179
257
test ( 'update' , t => {
0 commit comments