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