]>
Commit | Line | Data |
---|---|---|
cc43831a C |
1 | /* tslint:disable:no-unused-expression */ |
2 | ||
3 | import * as magnetUtil from 'magnet-uri' | |
4 | import * as chai from 'chai' | |
5 | import 'mocha' | |
6 | import { getVideo, killallServers, runServer, ServerInfo, uploadVideo } from '../../utils' | |
7 | import { flushTests, setAccessTokensToServers } from '../../utils/index' | |
8 | import { VideoDetails } from '../../../../shared/models/videos' | |
9 | import * as WebTorrent from 'webtorrent' | |
10 | ||
11 | describe('Test tracker', function () { | |
12 | let server: ServerInfo | |
13 | let badMagnet: string | |
14 | let goodMagnet: string | |
15 | ||
16 | before(async function () { | |
17 | this.timeout(60000) | |
18 | ||
19 | await flushTests() | |
20 | server = await runServer(1) | |
21 | await setAccessTokensToServers([ server ]) | |
22 | ||
23 | { | |
24 | const res = await uploadVideo(server.url, server.accessToken, {}) | |
25 | const videoUUID = res.body.video.uuid | |
26 | ||
27 | const resGet = await getVideo(server.url, videoUUID) | |
28 | const video: VideoDetails = resGet.body | |
29 | goodMagnet = video.files[0].magnetUri | |
30 | ||
31 | const parsed = magnetUtil.decode(goodMagnet) | |
32 | parsed.infoHash = '010597bb88b1968a5693a4fa8267c592ca65f2e9' | |
33 | ||
34 | badMagnet = magnetUtil.encode(parsed) | |
35 | } | |
36 | }) | |
37 | ||
38 | it('Should return an error when adding an incorrect infohash', done => { | |
39 | this.timeout(10000) | |
40 | const webtorrent = new WebTorrent() | |
41 | ||
42 | const torrent = webtorrent.add(badMagnet) | |
43 | ||
44 | torrent.on('error', done) | |
45 | torrent.on('warning', warn => { | |
46 | const message = typeof warn === 'string' ? warn : warn.message | |
47 | if (message.indexOf('Unknown infoHash ') !== -1) return done() | |
48 | }) | |
49 | ||
50 | torrent.on('done', () => done(new Error('No error on infohash'))) | |
51 | }) | |
52 | ||
53 | it('Should succeed with the correct infohash', done => { | |
54 | this.timeout(10000) | |
55 | const webtorrent = new WebTorrent() | |
56 | ||
57 | const torrent = webtorrent.add(goodMagnet) | |
58 | ||
59 | torrent.on('error', done) | |
60 | torrent.on('warning', warn => { | |
61 | const message = typeof warn === 'string' ? warn : warn.message | |
62 | if (message.indexOf('Unknown infoHash ') !== -1) return done(new Error('Error on infohash')) | |
63 | }) | |
64 | ||
65 | torrent.on('done', done) | |
66 | }) | |
67 | ||
68 | after(async function () { | |
69 | killallServers([ server ]) | |
70 | }) | |
71 | }) |