This repository was archived by the owner on May 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest.js
More file actions
108 lines (96 loc) · 2.8 KB
/
test.js
File metadata and controls
108 lines (96 loc) · 2.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
const { expect } = require('chai')
const parseContentRangeHeader = require('./index')
describe('parseContentRangeHeader', () => {
it('parses a Content-Range header <unit> <range start>-<range end>/<size>', () => {
let header = 'bytes 0-500/1000'
let actual = parseContentRangeHeader(header)
expect(actual).to.eql({
isRangeSatisfied: true,
range: { start: 0, end: 500 },
unit: 'bytes',
isSizeKnown: true,
size: 1000
})
})
it('parses a Content-Range header <unit> */<size>', () => {
let header = 'bytes */1000'
let actual = parseContentRangeHeader(header)
expect(actual).to.eql({
isRangeSatisfied: false,
range: '*',
unit: 'bytes',
isSizeKnown: true,
size: 1000
})
})
it.only('parses a Content-Range header <unit> */*', () => {
let header = 'bytes */*'
let actual = parseContentRangeHeader(header)
expect(actual).to.eql({
isRangeSatisfied: false,
range: '*',
unit: 'bytes',
isSizeKnown: false,
size: '*'
})
})
it('parses a Content-Range header <unit> <range start>-<range end>/*', () => {
let header = 'bytes 0-50/*'
let actual = parseContentRangeHeader(header)
expect(actual).to.eql({
isRangeSatisfied: true,
range: { start: 0, end: 50 },
unit: 'bytes',
isSizeKnown: false,
size: '*'
})
})
it('throws an error if unit separator is missing', () => {
let header = 'bytes0-500/1000'
expect(() => {
parseContentRangeHeader(header)
}).to.throw(Error, 'missing unit separator')
})
it('throws an error if unit is missing', () => {
let header = ' '
expect(() => {
parseContentRangeHeader(header)
}).to.throw(Error, 'missing unit value')
})
it('throws an error if size separator is missing', () => {
let header = 'bytes 0-100'
expect(() => {
parseContentRangeHeader(header)
}).to.throw(Error, 'missing size separator')
})
it('throws an error if range is invalid', () => {
let header = 'bytes 0500/1000'
expect(() => {
parseContentRangeHeader(header)
}).to.throw(Error, 'invalid range')
})
it('throws an error if range start is not an integer', () => {
let header = 'bytes kjhas-500/1000'
expect(() => {
parseContentRangeHeader(header)
}).to.throw(Error, 'invalid range start value')
})
it('throws an error if range end is not an integer', () => {
let header = 'bytes 0-i500/1000'
expect(() => {
parseContentRangeHeader(header)
}).to.throw(Error, 'invalid range end value')
})
it('throws an error if range start is greater than range end', () => {
let header = 'bytes 10-5/1000'
expect(() => {
parseContentRangeHeader(header)
}).to.throw(Error, 'range start is greater than range end')
})
it('throws an error if size is known but is not an integer', () => {
let header = 'bytes 0-500/lkjs'
expect(() => {
parseContentRangeHeader(header)
}).to.throw(Error, 'invalid size value')
})
})