forked from phts/nodejs-torrent-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathannounce-params-validator.test.js
More file actions
54 lines (47 loc) · 1.57 KB
/
announce-params-validator.test.js
File metadata and controls
54 lines (47 loc) · 1.57 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
'use strict';
var expect = require('chai').expect;
var AnnounceParamsValidator = require('../release/announce-params-validator').default;
var createAnnounceParams = require('./helpers/create-announce-params');
describe('AnnounceParamsValidator', function() {
var parser, params;
describe('#validate', function() {
function throwsError (message) {
it(`throws an Error "${message}"`, function () {
expect(function() {
parser.validate();
}).to.throw(Error, message);
});
}
beforeEach(function () {
params = createAnnounceParams();
});
describe('when info hash is malformed', function () {
beforeEach(function () {
params.withInfoHash('invalid');
parser = new AnnounceParamsValidator(params);
});
throwsError('Info hash parameter is invalid');
});
describe('when info hash is missing', function () {
beforeEach(function () {
params.without('infoHash');
parser = new AnnounceParamsValidator(params);
});
throwsError('Info hash parameter is missing');
});
describe('when peer id is malformed', function () {
beforeEach(function () {
params.withPeerId('invalid');
parser = new AnnounceParamsValidator(params);
});
throwsError('Peer id parameter is invalid');
});
describe('when peer id is missing', function () {
beforeEach(function () {
params.without('peerId');
parser = new AnnounceParamsValidator(params);
});
throwsError('Peer id parameter is missing');
});
});
});