]>
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') | |
3a8a8b51 | 7 | const keyBy = require('lodash/keyBy') |
f0f5567b | 8 | const pathUtils = require('path') |
9f10b292 | 9 | |
f0f5567b | 10 | const webtorrent = require(pathUtils.join(__dirname, '../../lib/webtorrent')) |
9f10b292 C |
11 | webtorrent.silent = true |
12 | ||
f0f5567b | 13 | const utils = require('./utils') |
9f10b292 C |
14 | |
15 | describe('Test a single pod', function () { | |
0c1cbbfe | 16 | let server = null |
bc503c2a | 17 | let videoId = -1 |
fbf1134e | 18 | let videosListBase = null |
9f10b292 C |
19 | |
20 | before(function (done) { | |
21 | this.timeout(20000) | |
22 | ||
23 | async.series([ | |
24 | function (next) { | |
25 | utils.flushTests(next) | |
26 | }, | |
27 | function (next) { | |
0c1cbbfe C |
28 | utils.runServer(1, function (server1) { |
29 | server = server1 | |
30 | next() | |
31 | }) | |
32 | }, | |
33 | function (next) { | |
34 | utils.loginAndGetAccessToken(server, function (err, token) { | |
35 | if (err) throw err | |
b6c6f935 | 36 | server.accessToken = token |
9f10b292 C |
37 | next() |
38 | }) | |
39 | }, | |
40 | function (next) { | |
41 | webtorrent.create({ host: 'client', port: '1' }, next) | |
42 | } | |
43 | ], done) | |
44 | }) | |
8c308c2b | 45 | |
9f10b292 | 46 | it('Should not have videos', function (done) { |
0c1cbbfe | 47 | utils.getVideosList(server.url, function (err, res) { |
9f10b292 | 48 | if (err) throw err |
8c308c2b | 49 | |
9f10b292 C |
50 | expect(res.body).to.be.an('array') |
51 | expect(res.body.length).to.equal(0) | |
8c308c2b | 52 | |
9f10b292 | 53 | done() |
8c308c2b | 54 | }) |
9f10b292 | 55 | }) |
8c308c2b | 56 | |
9f10b292 C |
57 | it('Should upload the video', function (done) { |
58 | this.timeout(5000) | |
b6c6f935 | 59 | utils.uploadVideo(server.url, server.accessToken, 'my super name', 'my super description', 'video_short.webm', done) |
9f10b292 | 60 | }) |
8c308c2b | 61 | |
9f10b292 C |
62 | it('Should seed the uploaded video', function (done) { |
63 | // Yes, this could be long | |
64 | this.timeout(60000) | |
8c308c2b | 65 | |
0c1cbbfe | 66 | utils.getVideosList(server.url, function (err, res) { |
9f10b292 | 67 | if (err) throw err |
8c308c2b | 68 | |
9f10b292 C |
69 | expect(res.body).to.be.an('array') |
70 | expect(res.body.length).to.equal(1) | |
8c308c2b | 71 | |
f0f5567b | 72 | const video = res.body[0] |
9f10b292 C |
73 | expect(video.name).to.equal('my super name') |
74 | expect(video.description).to.equal('my super description') | |
75 | expect(video.podUrl).to.equal('http://localhost:9001') | |
76 | expect(video.magnetUri).to.exist | |
6d8ada5f C |
77 | expect(video.author).to.equal('root') |
78 | expect(video.isLocal).to.be.true | |
bb10240e | 79 | expect(utils.dateIsValid(video.createdDate)).to.be.true |
8c308c2b | 80 | |
36d56024 | 81 | utils.testImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) { |
9e5f3740 C |
82 | if (err) throw err |
83 | expect(test).to.equal(true) | |
2df82d42 | 84 | |
bc503c2a | 85 | videoId = video.id |
2df82d42 | 86 | |
9e5f3740 C |
87 | webtorrent.add(video.magnetUri, function (torrent) { |
88 | expect(torrent.files).to.exist | |
89 | expect(torrent.files.length).to.equal(1) | |
90 | expect(torrent.files[0].path).to.exist.and.to.not.equal('') | |
91 | ||
b6c6f935 C |
92 | // We remove it because we'll add it again |
93 | webtorrent.remove(video.magnetUri, done) | |
9e5f3740 | 94 | }) |
2df82d42 C |
95 | }) |
96 | }) | |
97 | }) | |
98 | ||
99 | it('Should get the video', function (done) { | |
100 | // Yes, this could be long | |
101 | this.timeout(60000) | |
102 | ||
bc503c2a | 103 | utils.getVideo(server.url, videoId, function (err, res) { |
2df82d42 C |
104 | if (err) throw err |
105 | ||
106 | const video = res.body | |
107 | expect(video.name).to.equal('my super name') | |
108 | expect(video.description).to.equal('my super description') | |
109 | expect(video.podUrl).to.equal('http://localhost:9001') | |
110 | expect(video.magnetUri).to.exist | |
6d8ada5f C |
111 | expect(video.author).to.equal('root') |
112 | expect(video.isLocal).to.be.true | |
bb10240e | 113 | expect(utils.dateIsValid(video.createdDate)).to.be.true |
8c308c2b | 114 | |
36d56024 | 115 | utils.testImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) { |
9e5f3740 C |
116 | if (err) throw err |
117 | expect(test).to.equal(true) | |
8c308c2b | 118 | |
9e5f3740 C |
119 | webtorrent.add(video.magnetUri, function (torrent) { |
120 | expect(torrent.files).to.exist | |
121 | expect(torrent.files.length).to.equal(1) | |
122 | expect(torrent.files[0].path).to.exist.and.to.not.equal('') | |
123 | ||
124 | done() | |
125 | }) | |
876d1bcf | 126 | }) |
8c308c2b | 127 | }) |
9f10b292 | 128 | }) |
8c308c2b | 129 | |
9f10b292 | 130 | it('Should search the video', function (done) { |
0c1cbbfe | 131 | utils.searchVideo(server.url, 'my', function (err, res) { |
9f10b292 | 132 | if (err) throw err |
4d5f8138 | 133 | |
9f10b292 C |
134 | expect(res.body).to.be.an('array') |
135 | expect(res.body.length).to.equal(1) | |
4d5f8138 | 136 | |
f0f5567b | 137 | const video = res.body[0] |
9f10b292 C |
138 | expect(video.name).to.equal('my super name') |
139 | expect(video.description).to.equal('my super description') | |
140 | expect(video.podUrl).to.equal('http://localhost:9001') | |
6d8ada5f C |
141 | expect(video.author).to.equal('root') |
142 | expect(video.isLocal).to.be.true | |
bb10240e | 143 | expect(utils.dateIsValid(video.createdDate)).to.be.true |
4d5f8138 | 144 | |
36d56024 | 145 | utils.testImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) { |
9e5f3740 C |
146 | if (err) throw err |
147 | expect(test).to.equal(true) | |
148 | ||
149 | done() | |
150 | }) | |
4d5f8138 | 151 | }) |
9f10b292 | 152 | }) |
4d5f8138 | 153 | |
9f10b292 | 154 | it('Should not find a search', function (done) { |
0c1cbbfe | 155 | utils.searchVideo(server.url, 'hello', function (err, res) { |
9f10b292 | 156 | if (err) throw err |
4d5f8138 | 157 | |
9f10b292 C |
158 | expect(res.body).to.be.an('array') |
159 | expect(res.body.length).to.equal(0) | |
4d5f8138 | 160 | |
9f10b292 | 161 | done() |
4d5f8138 | 162 | }) |
9f10b292 | 163 | }) |
4d5f8138 | 164 | |
9f10b292 | 165 | it('Should remove the video', function (done) { |
bc503c2a | 166 | utils.removeVideo(server.url, server.accessToken, videoId, function (err) { |
9f10b292 | 167 | if (err) throw err |
f5a60a51 | 168 | |
3d446a26 | 169 | fs.readdir(pathUtils.join(__dirname, '../../../test1/uploads/'), function (err, files) { |
9f10b292 | 170 | if (err) throw err |
f5a60a51 | 171 | |
9f10b292 C |
172 | expect(files.length).to.equal(0) |
173 | done() | |
876d1bcf | 174 | }) |
8c308c2b | 175 | }) |
9f10b292 | 176 | }) |
8c308c2b | 177 | |
9f10b292 | 178 | it('Should not have videos', function (done) { |
0c1cbbfe | 179 | utils.getVideosList(server.url, function (err, res) { |
9f10b292 | 180 | if (err) throw err |
8c308c2b | 181 | |
9f10b292 C |
182 | expect(res.body).to.be.an('array') |
183 | expect(res.body.length).to.equal(0) | |
8c308c2b | 184 | |
9f10b292 | 185 | done() |
8c308c2b | 186 | }) |
9f10b292 | 187 | }) |
8c308c2b | 188 | |
3a8a8b51 C |
189 | it('Should upload 6 videos', function (done) { |
190 | this.timeout(25000) | |
191 | const videos = [ | |
192 | 'video_short.mp4', 'video_short.ogv', 'video_short.webm', | |
193 | 'video_short1.webm', 'video_short2.webm', 'video_short3.webm' | |
194 | ] | |
bc503c2a C |
195 | async.each(videos, function (video, callbackEach) { |
196 | utils.uploadVideo(server.url, server.accessToken, video + ' name', video + ' description', video, callbackEach) | |
3a8a8b51 C |
197 | }, done) |
198 | }) | |
199 | ||
200 | it('Should have the correct durations', function (done) { | |
201 | utils.getVideosList(server.url, function (err, res) { | |
202 | if (err) throw err | |
203 | ||
204 | const videos = res.body | |
205 | expect(videos).to.be.an('array') | |
206 | expect(videos.length).to.equal(6) | |
207 | ||
bc503c2a C |
208 | const videosByName = keyBy(videos, 'name') |
209 | expect(videosByName['video_short.mp4 name'].duration).to.equal(5) | |
210 | expect(videosByName['video_short.ogv name'].duration).to.equal(5) | |
211 | expect(videosByName['video_short.webm name'].duration).to.equal(5) | |
212 | expect(videosByName['video_short1.webm name'].duration).to.equal(10) | |
213 | expect(videosByName['video_short2.webm name'].duration).to.equal(5) | |
214 | expect(videosByName['video_short3.webm name'].duration).to.equal(5) | |
3a8a8b51 C |
215 | |
216 | done() | |
217 | }) | |
218 | }) | |
219 | ||
9e5f3740 C |
220 | it('Should have the correct thumbnails', function (done) { |
221 | utils.getVideosList(server.url, function (err, res) { | |
fbf1134e C |
222 | if (err) throw err |
223 | ||
9e5f3740 | 224 | const videos = res.body |
fbf1134e C |
225 | // For the next test |
226 | videosListBase = videos | |
9e5f3740 | 227 | |
bc503c2a | 228 | async.each(videos, function (video, callbackEach) { |
9e5f3740 | 229 | if (err) throw err |
bc503c2a | 230 | const videoName = video.name.replace(' name', '') |
9e5f3740 | 231 | |
bc503c2a | 232 | utils.testImage(server.url, videoName, video.thumbnailPath, function (err, test) { |
9e5f3740 C |
233 | if (err) throw err |
234 | ||
235 | expect(test).to.equal(true) | |
bc503c2a | 236 | callbackEach() |
9e5f3740 C |
237 | }) |
238 | }, done) | |
239 | }) | |
240 | }) | |
241 | ||
fbf1134e C |
242 | it('Should list only the two first videos', function (done) { |
243 | utils.getVideosListPagination(server.url, 0, 2, function (err, res) { | |
244 | if (err) throw err | |
245 | ||
246 | const videos = res.body | |
247 | expect(videos.length).to.equal(2) | |
248 | expect(videos[0].name === videosListBase[0].name) | |
249 | expect(videos[1].name === videosListBase[1].name) | |
250 | ||
251 | done() | |
252 | }) | |
253 | }) | |
254 | ||
255 | it('Should list only the next three videos', function (done) { | |
256 | utils.getVideosListPagination(server.url, 2, 3, function (err, res) { | |
257 | if (err) throw err | |
258 | ||
259 | const videos = res.body | |
260 | expect(videos.length).to.equal(4) | |
261 | expect(videos[0].name === videosListBase[2].name) | |
262 | expect(videos[1].name === videosListBase[3].name) | |
263 | expect(videos[2].name === videosListBase[4].name) | |
264 | ||
265 | done() | |
266 | }) | |
267 | }) | |
268 | ||
269 | it('Should list the last video', function (done) { | |
270 | utils.getVideosListPagination(server.url, 5, 6, function (err, res) { | |
271 | if (err) throw err | |
272 | ||
273 | const videos = res.body | |
274 | expect(videos.length).to.equal(1) | |
275 | expect(videos[0].name === videosListBase[5].name) | |
276 | ||
277 | done() | |
278 | }) | |
279 | }) | |
280 | ||
281 | it('Should search the first video', function (done) { | |
282 | utils.searchVideoWithPagination(server.url, 'webm', 0, 1, function (err, res) { | |
283 | if (err) throw err | |
284 | ||
285 | const videos = res.body | |
286 | expect(videos.length).to.equal(1) | |
287 | expect(videos[0].name === 'video_short.webm name') | |
288 | ||
289 | done() | |
290 | }) | |
291 | }) | |
292 | ||
293 | it('Should search the last two videos', function (done) { | |
294 | utils.searchVideoWithPagination(server.url, 'webm', 2, 2, function (err, res) { | |
295 | if (err) throw err | |
296 | ||
297 | const videos = res.body | |
298 | expect(videos.length).to.equal(2) | |
299 | expect(videos[0].name === 'video_short2.webm name') | |
300 | expect(videos[1].name === 'video_short3.webm name') | |
301 | ||
302 | done() | |
303 | }) | |
304 | }) | |
305 | ||
306 | it('Should search all the videos', function (done) { | |
307 | utils.searchVideoWithPagination(server.url, 'webm', 0, 15, function (err, res) { | |
308 | if (err) throw err | |
309 | ||
310 | const videos = res.body | |
311 | expect(videos.length).to.equal(4) | |
312 | ||
313 | done() | |
314 | }) | |
315 | }) | |
316 | ||
9f10b292 | 317 | after(function (done) { |
0c1cbbfe | 318 | process.kill(-server.app.pid) |
9f10b292 | 319 | process.kill(-webtorrent.app.pid) |
8c308c2b | 320 | |
9f10b292 C |
321 | // Keep the logs if the test failed |
322 | if (this.ok) { | |
323 | utils.flushTests(done) | |
324 | } else { | |
325 | done() | |
326 | } | |
8c308c2b | 327 | }) |
9f10b292 | 328 | }) |