]>
Commit | Line | Data |
---|---|---|
9f10b292 C |
1 | 'use strict' |
2 | ||
f0f5567b C |
3 | const async = require('async') |
4 | const chai = require('chai') | |
5 | const expect = chai.expect | |
6 | const fs = require('fs') | |
7 | const pathUtils = require('path') | |
9f10b292 | 8 | |
f0f5567b | 9 | const webtorrent = require(pathUtils.join(__dirname, '../../lib/webtorrent')) |
9f10b292 C |
10 | webtorrent.silent = true |
11 | ||
f0f5567b | 12 | const utils = require('./utils') |
9f10b292 C |
13 | |
14 | describe('Test a single pod', function () { | |
0c1cbbfe | 15 | let server = null |
f0f5567b | 16 | let video_id = -1 |
9f10b292 C |
17 | |
18 | before(function (done) { | |
19 | this.timeout(20000) | |
20 | ||
21 | async.series([ | |
22 | function (next) { | |
23 | utils.flushTests(next) | |
24 | }, | |
25 | function (next) { | |
0c1cbbfe C |
26 | utils.runServer(1, function (server1) { |
27 | server = server1 | |
28 | next() | |
29 | }) | |
30 | }, | |
31 | function (next) { | |
32 | utils.loginAndGetAccessToken(server, function (err, token) { | |
33 | if (err) throw err | |
34 | server.access_token = token | |
9f10b292 C |
35 | next() |
36 | }) | |
37 | }, | |
38 | function (next) { | |
39 | webtorrent.create({ host: 'client', port: '1' }, next) | |
40 | } | |
41 | ], done) | |
42 | }) | |
8c308c2b | 43 | |
9f10b292 | 44 | it('Should not have videos', function (done) { |
0c1cbbfe | 45 | utils.getVideosList(server.url, function (err, res) { |
9f10b292 | 46 | if (err) throw err |
8c308c2b | 47 | |
9f10b292 C |
48 | expect(res.body).to.be.an('array') |
49 | expect(res.body.length).to.equal(0) | |
8c308c2b | 50 | |
9f10b292 | 51 | done() |
8c308c2b | 52 | }) |
9f10b292 | 53 | }) |
8c308c2b | 54 | |
9f10b292 C |
55 | it('Should upload the video', function (done) { |
56 | this.timeout(5000) | |
0c1cbbfe | 57 | utils.uploadVideo(server.url, server.access_token, 'my super name', 'my super description', 'video_short.webm', done) |
9f10b292 | 58 | }) |
8c308c2b | 59 | |
9f10b292 C |
60 | it('Should seed the uploaded video', function (done) { |
61 | // Yes, this could be long | |
62 | this.timeout(60000) | |
8c308c2b | 63 | |
0c1cbbfe | 64 | utils.getVideosList(server.url, function (err, res) { |
9f10b292 | 65 | if (err) throw err |
8c308c2b | 66 | |
9f10b292 C |
67 | expect(res.body).to.be.an('array') |
68 | expect(res.body.length).to.equal(1) | |
8c308c2b | 69 | |
f0f5567b | 70 | const video = res.body[0] |
9f10b292 C |
71 | expect(video.name).to.equal('my super name') |
72 | expect(video.description).to.equal('my super description') | |
73 | expect(video.podUrl).to.equal('http://localhost:9001') | |
74 | expect(video.magnetUri).to.exist | |
8c308c2b | 75 | |
2df82d42 C |
76 | video_id = video.id |
77 | ||
78 | webtorrent.add(video.magnetUri, function (torrent) { | |
79 | expect(torrent.files).to.exist | |
80 | expect(torrent.files.length).to.equal(1) | |
81 | expect(torrent.files[0].path).to.exist.and.to.not.equal('') | |
82 | ||
83 | done() | |
84 | }) | |
85 | }) | |
86 | }) | |
87 | ||
88 | it('Should get the video', function (done) { | |
89 | // Yes, this could be long | |
90 | this.timeout(60000) | |
91 | ||
0c1cbbfe | 92 | utils.getVideo(server.url, video_id, function (err, res) { |
2df82d42 C |
93 | if (err) throw err |
94 | ||
95 | const video = res.body | |
96 | expect(video.name).to.equal('my super name') | |
97 | expect(video.description).to.equal('my super description') | |
98 | expect(video.podUrl).to.equal('http://localhost:9001') | |
99 | expect(video.magnetUri).to.exist | |
8c308c2b | 100 | |
9f10b292 C |
101 | webtorrent.add(video.magnetUri, function (torrent) { |
102 | expect(torrent.files).to.exist | |
103 | expect(torrent.files.length).to.equal(1) | |
104 | expect(torrent.files[0].path).to.exist.and.to.not.equal('') | |
8c308c2b | 105 | |
9f10b292 | 106 | done() |
876d1bcf | 107 | }) |
8c308c2b | 108 | }) |
9f10b292 | 109 | }) |
8c308c2b | 110 | |
9f10b292 | 111 | it('Should search the video', function (done) { |
0c1cbbfe | 112 | utils.searchVideo(server.url, 'my', function (err, res) { |
9f10b292 | 113 | if (err) throw err |
4d5f8138 | 114 | |
9f10b292 C |
115 | expect(res.body).to.be.an('array') |
116 | expect(res.body.length).to.equal(1) | |
4d5f8138 | 117 | |
f0f5567b | 118 | const video = res.body[0] |
9f10b292 C |
119 | expect(video.name).to.equal('my super name') |
120 | expect(video.description).to.equal('my super description') | |
121 | expect(video.podUrl).to.equal('http://localhost:9001') | |
4d5f8138 | 122 | |
9f10b292 | 123 | done() |
4d5f8138 | 124 | }) |
9f10b292 | 125 | }) |
4d5f8138 | 126 | |
9f10b292 | 127 | it('Should not find a search', function (done) { |
0c1cbbfe | 128 | utils.searchVideo(server.url, 'hello', function (err, res) { |
9f10b292 | 129 | if (err) throw err |
4d5f8138 | 130 | |
9f10b292 C |
131 | expect(res.body).to.be.an('array') |
132 | expect(res.body.length).to.equal(0) | |
4d5f8138 | 133 | |
9f10b292 | 134 | done() |
4d5f8138 | 135 | }) |
9f10b292 | 136 | }) |
4d5f8138 | 137 | |
9f10b292 | 138 | it('Should remove the video', function (done) { |
0c1cbbfe | 139 | utils.removeVideo(server.url, server.access_token, video_id, function (err) { |
9f10b292 | 140 | if (err) throw err |
f5a60a51 | 141 | |
3d446a26 | 142 | fs.readdir(pathUtils.join(__dirname, '../../../test1/uploads/'), function (err, files) { |
9f10b292 | 143 | if (err) throw err |
f5a60a51 | 144 | |
9f10b292 C |
145 | expect(files.length).to.equal(0) |
146 | done() | |
876d1bcf | 147 | }) |
8c308c2b | 148 | }) |
9f10b292 | 149 | }) |
8c308c2b | 150 | |
9f10b292 | 151 | it('Should not have videos', function (done) { |
0c1cbbfe | 152 | utils.getVideosList(server.url, function (err, res) { |
9f10b292 | 153 | if (err) throw err |
8c308c2b | 154 | |
9f10b292 C |
155 | expect(res.body).to.be.an('array') |
156 | expect(res.body.length).to.equal(0) | |
8c308c2b | 157 | |
9f10b292 | 158 | done() |
8c308c2b | 159 | }) |
9f10b292 | 160 | }) |
8c308c2b | 161 | |
9f10b292 | 162 | after(function (done) { |
0c1cbbfe | 163 | process.kill(-server.app.pid) |
9f10b292 | 164 | process.kill(-webtorrent.app.pid) |
8c308c2b | 165 | |
9f10b292 C |
166 | // Keep the logs if the test failed |
167 | if (this.ok) { | |
168 | utils.flushTests(done) | |
169 | } else { | |
170 | done() | |
171 | } | |
8c308c2b | 172 | }) |
9f10b292 | 173 | }) |