File tree 2 files changed +37
-1
lines changed
2 files changed +37
-1
lines changed Original file line number Diff line number Diff line change @@ -268,7 +268,14 @@ export const assertValidMeasurement = measurement => {
268
268
assert ( measurement . end_at >= measurement . first_byte_at , 'end_at must be greater than or equal to first_byte_at' )
269
269
assert ( measurement . first_byte_at >= measurement . start_at , 'first_byte_at must be greater than or equal to start_at' )
270
270
271
- assert . strictEqual ( typeof measurement . head_status_code , 'number' , '`head_status_code` must be a number' )
271
+ if ( measurement . protocol === 'http' ) {
272
+ assert . strictEqual ( typeof measurement . head_status_code , 'number' , '`head_status_code` must be a number' )
273
+ } else {
274
+ assert (
275
+ measurement . head_status_code === undefined || measurement . head_status_code === null ,
276
+ '`head_status_code` must be undefined or null for non-HTTP retrievals'
277
+ )
278
+ }
272
279
}
273
280
}
274
281
Original file line number Diff line number Diff line change @@ -314,19 +314,48 @@ describe('assertValidMeasurement', () => {
314
314
assert . throws (
315
315
( ) => assertValidMeasurement ( {
316
316
...VALID_MEASUREMENT ,
317
+ protocol : 'http' ,
317
318
head_status_code : null
318
319
} ) ,
319
320
/ ` h e a d _ s t a t u s _ c o d e ` m u s t b e a n u m b e r /
320
321
)
321
322
assert . throws (
322
323
( ) => assertValidMeasurement ( {
323
324
...VALID_MEASUREMENT ,
325
+ protocol : 'http' ,
324
326
head_status_code : /** @type {any } */ ( '200' )
325
327
} ) ,
326
328
/ ` h e a d _ s t a t u s _ c o d e ` m u s t b e a n u m b e r /
327
329
)
328
330
} )
329
331
332
+ it ( 'accepts Graphsync measurements with OK retrieval result and head_status_code is null' , ( ) => {
333
+ assertValidMeasurement ( {
334
+ ...VALID_MEASUREMENT ,
335
+ protocol : 'graphsync' ,
336
+ head_status_code : null
337
+
338
+ } )
339
+ } )
340
+
341
+ it ( 'accepts Graphsync measurements with OK retrieval result and head_status_code is undefined' , ( ) => {
342
+ assertValidMeasurement ( {
343
+ ...VALID_MEASUREMENT ,
344
+ protocol : 'graphsync' ,
345
+ head_status_code : undefined
346
+ } )
347
+ } )
348
+
349
+ it ( 'rejects Graphsync measurements with head_status_code not null/undefined ' , ( ) => {
350
+ assert . throws (
351
+ ( ) => assertValidMeasurement ( {
352
+ ...VALID_MEASUREMENT ,
353
+ head_status_code : /** @type {any } */ ( '200' )
354
+ } ) ,
355
+ / ` h e a d _ s t a t u s _ c o d e ` m u s t b e u n d e f i n e d /
356
+ )
357
+ } )
358
+
330
359
it ( 'should throw an error for invalid start_at' , ( ) => {
331
360
const measurement = {
332
361
...VALID_MEASUREMENT ,
You can’t perform that action at this time.
0 commit comments