@@ -111,6 +111,33 @@ describe('discovery-v1', function() {
111
111
assert . equal ( req . method , 'POST' ) ;
112
112
} ) ;
113
113
114
+ it ( 'should create an environment with size 1 by default' , function ( ) {
115
+ const req = discovery . createEnvironment (
116
+ {
117
+ name : 'new environment' ,
118
+ description : 'my description'
119
+ } ,
120
+ noop
121
+ ) ;
122
+ const jsonBodyParts = readMultipartReqJsons ( req ) ;
123
+ assert . equal ( jsonBodyParts . length , 1 ) ;
124
+ assert . equal ( jsonBodyParts [ 0 ] . size , 1 ) ;
125
+ } ) ;
126
+
127
+ it ( 'should create an environment with size 0' , function ( ) {
128
+ const req = discovery . createEnvironment (
129
+ {
130
+ name : 'new environment' ,
131
+ description : 'my description' ,
132
+ size : 0
133
+ } ,
134
+ noop
135
+ ) ;
136
+ const jsonBodyParts = readMultipartReqJsons ( req ) ;
137
+ assert . equal ( jsonBodyParts . length , 1 ) ;
138
+ assert . equal ( jsonBodyParts [ 0 ] . size , 0 ) ;
139
+ } ) ;
140
+
114
141
it ( 'should update an environment' , function ( ) {
115
142
const req = discovery . updateEnvironment (
116
143
{
@@ -265,6 +292,26 @@ describe('discovery-v1', function() {
265
292
) ;
266
293
assert . equal ( req . method , 'GET' ) ;
267
294
} ) ;
295
+
296
+ /**
297
+ * Return an array of parsed objects representing all valid JSON parts of a multipart request.
298
+ * @param {* } req
299
+ * @return {Array }
300
+ */
301
+ function readMultipartReqJsons ( req ) {
302
+ const result = [ ] ;
303
+ if ( req && req . body && req . body . length ) {
304
+ req . body . forEach ( part => {
305
+ try {
306
+ result . push ( JSON . parse ( Buffer . from ( part ) . toString ( 'ascii' ) ) ) ;
307
+ } catch ( err ) {
308
+ // JSON parse error -> this part is not JSON: skip.
309
+ }
310
+ } ) ;
311
+ }
312
+
313
+ return result ;
314
+ }
268
315
} ) ;
269
316
} ) ;
270
317
} ) ;
0 commit comments