2 var express = require('..');
3 var request = require('supertest')
5 describe('req', function(){
6 describe('.range(size)', function(){
7 it('should return parsed ranges', function (done) {
10 app.use(function (req, res) {
11 res.json(req.range(120))
16 .set('Range', 'bytes=0-50,51-100')
17 .expect(200, '[{"start":0,"end":50},{"start":51,"end":100}]', done)
20 it('should cap to the given size', function (done) {
23 app.use(function (req, res) {
24 res.json(req.range(75))
29 .set('Range', 'bytes=0-100')
30 .expect(200, '[{"start":0,"end":74}]', done)
33 it('should cap to the given size when open-ended', function (done) {
36 app.use(function (req, res) {
37 res.json(req.range(75))
42 .set('Range', 'bytes=0-')
43 .expect(200, '[{"start":0,"end":74}]', done)
46 it('should have a .type', function (done) {
49 app.use(function (req, res) {
50 res.json(req.range(120).type)
55 .set('Range', 'bytes=0-100')
56 .expect(200, '"bytes"', done)
59 it('should accept any type', function (done) {
62 app.use(function (req, res) {
63 res.json(req.range(120).type)
68 .set('Range', 'users=0-2')
69 .expect(200, '"users"', done)
72 it('should return undefined if no range', function (done) {
75 app.use(function (req, res) {
76 res.send(String(req.range(120)))
81 .expect(200, 'undefined', done)
85 describe('.range(size, options)', function(){
86 describe('with "combine: true" option', function(){
87 it('should return combined ranges', function (done) {
90 app.use(function (req, res) {
91 res.json(req.range(120, {
98 .set('Range', 'bytes=0-50,51-100')
99 .expect(200, '[{"start":0,"end":100}]', done)