1
|
|
|
// noinspection JSUnusedLocalSymbols |
2
|
|
|
/* eslint-env mocha */ |
3
|
|
|
/* eslint-disable no-unused-expressions */ |
4
|
|
|
|
5
|
|
|
var chai = require('chai') |
6
|
|
|
var expect = chai.expect |
7
|
|
|
var Commons = require('../../../../lib/http/_common') |
8
|
|
|
|
9
|
|
|
describe('Unit', function () { |
10
|
|
|
describe('/http', function () { |
11
|
|
|
describe('/_common.js', function () { |
12
|
|
|
it('contains all expected exceptions', function () { |
13
|
|
|
var exceptions = [ |
14
|
|
|
'NetworkException', |
15
|
|
|
'IllegalUrlException', |
16
|
|
|
'MissingHostException', |
17
|
|
|
'ConnectionErrorException', |
18
|
|
|
'RedirectVortexException', |
19
|
|
|
'NetworkErrorException', |
20
|
|
|
'TimeoutException', |
21
|
|
|
'VoxEngineErrorException' |
22
|
|
|
] |
23
|
|
|
|
24
|
|
|
exceptions.forEach(function (id) { |
25
|
|
|
var Clazz = Commons[id] |
26
|
|
|
var e = new Clazz() |
27
|
|
|
expect(e.name).to.eq(id) |
28
|
|
|
expect(e.message).to.be.ok |
29
|
|
|
expect(e.message).to.be.eq(Clazz.prototype.message) |
30
|
|
|
expect(e.code).to.be.ok |
31
|
|
|
expect(e.code).to.be.eq(Clazz.prototype.code) |
32
|
|
|
expect(e).to.be.instanceOf(Clazz) |
33
|
|
|
}) |
34
|
|
|
}) |
35
|
|
|
|
36
|
|
|
it('provides inverse exception index', function () { |
37
|
|
|
for (var i = -1; i >= -8; i--) { |
38
|
|
|
expect(Commons.codeExceptionIndex[i].prototype.code).to.eq(i) |
39
|
|
|
} |
40
|
|
|
}) |
41
|
|
|
|
42
|
|
|
it('passes provided code to exception', function () { |
43
|
|
|
expect(new Commons.NetworkException(null, -120).code).to.eq(-120) |
44
|
|
|
expect(new Commons.TimeoutException(null, -120).code).to.eq(-120) |
45
|
|
|
}) |
46
|
|
|
|
47
|
|
|
it('saves provided exception message', function () { |
48
|
|
|
expect(new Commons.NetworkException('dummy').message).to.eq('dummy') |
49
|
|
|
expect(new Commons.TimeoutException('dummy').message).to.eq('dummy') |
50
|
|
|
}) |
51
|
|
|
|
52
|
|
|
describe('.InvalidConfigurationException', function () { |
53
|
|
|
it('supplies default message', function () { |
54
|
|
|
// because 100% coverage that's why |
55
|
|
|
var exception = new Commons.InvalidConfigurationException() |
56
|
|
|
expect(exception.message).to.be.a('string') |
57
|
|
|
}) |
58
|
|
|
}) |
59
|
|
|
}) |
60
|
|
|
}) |
61
|
|
|
}) |
62
|
|
|
|