]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/singlePod.js
Move the count of results for the pagination in constants module
[github/Chocobozzz/PeerTube.git] / server / tests / api / singlePod.js
CommitLineData
9f10b292
C
1'use strict'
2
f0f5567b
C
3const async = require('async')
4const chai = require('chai')
5const expect = chai.expect
6const fs = require('fs')
3a8a8b51 7const keyBy = require('lodash/keyBy')
f0f5567b 8const pathUtils = require('path')
9f10b292 9
f0f5567b 10const webtorrent = require(pathUtils.join(__dirname, '../../lib/webtorrent'))
9f10b292
C
11webtorrent.silent = true
12
f0f5567b 13const utils = require('./utils')
9f10b292
C
14
15describe('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
8c308c2b 79
36d56024 80 utils.testImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) {
9e5f3740
C
81 if (err) throw err
82 expect(test).to.equal(true)
2df82d42 83
bc503c2a 84 videoId = video.id
2df82d42 85
9e5f3740
C
86 webtorrent.add(video.magnetUri, function (torrent) {
87 expect(torrent.files).to.exist
88 expect(torrent.files.length).to.equal(1)
89 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
90
b6c6f935
C
91 // We remove it because we'll add it again
92 webtorrent.remove(video.magnetUri, done)
9e5f3740 93 })
2df82d42
C
94 })
95 })
96 })
97
98 it('Should get the video', function (done) {
99 // Yes, this could be long
100 this.timeout(60000)
101
bc503c2a 102 utils.getVideo(server.url, videoId, function (err, res) {
2df82d42
C
103 if (err) throw err
104
105 const video = res.body
106 expect(video.name).to.equal('my super name')
107 expect(video.description).to.equal('my super description')
108 expect(video.podUrl).to.equal('http://localhost:9001')
109 expect(video.magnetUri).to.exist
6d8ada5f
C
110 expect(video.author).to.equal('root')
111 expect(video.isLocal).to.be.true
8c308c2b 112
36d56024 113 utils.testImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) {
9e5f3740
C
114 if (err) throw err
115 expect(test).to.equal(true)
8c308c2b 116
9e5f3740
C
117 webtorrent.add(video.magnetUri, function (torrent) {
118 expect(torrent.files).to.exist
119 expect(torrent.files.length).to.equal(1)
120 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
121
122 done()
123 })
876d1bcf 124 })
8c308c2b 125 })
9f10b292 126 })
8c308c2b 127
9f10b292 128 it('Should search the video', function (done) {
0c1cbbfe 129 utils.searchVideo(server.url, 'my', function (err, res) {
9f10b292 130 if (err) throw err
4d5f8138 131
9f10b292
C
132 expect(res.body).to.be.an('array')
133 expect(res.body.length).to.equal(1)
4d5f8138 134
f0f5567b 135 const video = res.body[0]
9f10b292
C
136 expect(video.name).to.equal('my super name')
137 expect(video.description).to.equal('my super description')
138 expect(video.podUrl).to.equal('http://localhost:9001')
6d8ada5f
C
139 expect(video.author).to.equal('root')
140 expect(video.isLocal).to.be.true
4d5f8138 141
36d56024 142 utils.testImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) {
9e5f3740
C
143 if (err) throw err
144 expect(test).to.equal(true)
145
146 done()
147 })
4d5f8138 148 })
9f10b292 149 })
4d5f8138 150
9f10b292 151 it('Should not find a search', function (done) {
0c1cbbfe 152 utils.searchVideo(server.url, 'hello', function (err, res) {
9f10b292 153 if (err) throw err
4d5f8138 154
9f10b292
C
155 expect(res.body).to.be.an('array')
156 expect(res.body.length).to.equal(0)
4d5f8138 157
9f10b292 158 done()
4d5f8138 159 })
9f10b292 160 })
4d5f8138 161
9f10b292 162 it('Should remove the video', function (done) {
bc503c2a 163 utils.removeVideo(server.url, server.accessToken, videoId, function (err) {
9f10b292 164 if (err) throw err
f5a60a51 165
3d446a26 166 fs.readdir(pathUtils.join(__dirname, '../../../test1/uploads/'), function (err, files) {
9f10b292 167 if (err) throw err
f5a60a51 168
9f10b292
C
169 expect(files.length).to.equal(0)
170 done()
876d1bcf 171 })
8c308c2b 172 })
9f10b292 173 })
8c308c2b 174
9f10b292 175 it('Should not have videos', function (done) {
0c1cbbfe 176 utils.getVideosList(server.url, function (err, res) {
9f10b292 177 if (err) throw err
8c308c2b 178
9f10b292
C
179 expect(res.body).to.be.an('array')
180 expect(res.body.length).to.equal(0)
8c308c2b 181
9f10b292 182 done()
8c308c2b 183 })
9f10b292 184 })
8c308c2b 185
3a8a8b51
C
186 it('Should upload 6 videos', function (done) {
187 this.timeout(25000)
188 const videos = [
189 'video_short.mp4', 'video_short.ogv', 'video_short.webm',
190 'video_short1.webm', 'video_short2.webm', 'video_short3.webm'
191 ]
bc503c2a
C
192 async.each(videos, function (video, callbackEach) {
193 utils.uploadVideo(server.url, server.accessToken, video + ' name', video + ' description', video, callbackEach)
3a8a8b51
C
194 }, done)
195 })
196
197 it('Should have the correct durations', function (done) {
198 utils.getVideosList(server.url, function (err, res) {
199 if (err) throw err
200
201 const videos = res.body
202 expect(videos).to.be.an('array')
203 expect(videos.length).to.equal(6)
204
bc503c2a
C
205 const videosByName = keyBy(videos, 'name')
206 expect(videosByName['video_short.mp4 name'].duration).to.equal(5)
207 expect(videosByName['video_short.ogv name'].duration).to.equal(5)
208 expect(videosByName['video_short.webm name'].duration).to.equal(5)
209 expect(videosByName['video_short1.webm name'].duration).to.equal(10)
210 expect(videosByName['video_short2.webm name'].duration).to.equal(5)
211 expect(videosByName['video_short3.webm name'].duration).to.equal(5)
3a8a8b51
C
212
213 done()
214 })
215 })
216
9e5f3740
C
217 it('Should have the correct thumbnails', function (done) {
218 utils.getVideosList(server.url, function (err, res) {
fbf1134e
C
219 if (err) throw err
220
9e5f3740 221 const videos = res.body
fbf1134e
C
222 // For the next test
223 videosListBase = videos
9e5f3740 224
bc503c2a 225 async.each(videos, function (video, callbackEach) {
9e5f3740 226 if (err) throw err
bc503c2a 227 const videoName = video.name.replace(' name', '')
9e5f3740 228
bc503c2a 229 utils.testImage(server.url, videoName, video.thumbnailPath, function (err, test) {
9e5f3740
C
230 if (err) throw err
231
232 expect(test).to.equal(true)
bc503c2a 233 callbackEach()
9e5f3740
C
234 })
235 }, done)
236 })
237 })
238
fbf1134e
C
239 it('Should list only the two first videos', function (done) {
240 utils.getVideosListPagination(server.url, 0, 2, function (err, res) {
241 if (err) throw err
242
243 const videos = res.body
244 expect(videos.length).to.equal(2)
245 expect(videos[0].name === videosListBase[0].name)
246 expect(videos[1].name === videosListBase[1].name)
247
248 done()
249 })
250 })
251
252 it('Should list only the next three videos', function (done) {
253 utils.getVideosListPagination(server.url, 2, 3, function (err, res) {
254 if (err) throw err
255
256 const videos = res.body
257 expect(videos.length).to.equal(4)
258 expect(videos[0].name === videosListBase[2].name)
259 expect(videos[1].name === videosListBase[3].name)
260 expect(videos[2].name === videosListBase[4].name)
261
262 done()
263 })
264 })
265
266 it('Should list the last video', function (done) {
267 utils.getVideosListPagination(server.url, 5, 6, function (err, res) {
268 if (err) throw err
269
270 const videos = res.body
271 expect(videos.length).to.equal(1)
272 expect(videos[0].name === videosListBase[5].name)
273
274 done()
275 })
276 })
277
278 it('Should search the first video', function (done) {
279 utils.searchVideoWithPagination(server.url, 'webm', 0, 1, function (err, res) {
280 if (err) throw err
281
282 const videos = res.body
283 expect(videos.length).to.equal(1)
284 expect(videos[0].name === 'video_short.webm name')
285
286 done()
287 })
288 })
289
290 it('Should search the last two videos', function (done) {
291 utils.searchVideoWithPagination(server.url, 'webm', 2, 2, function (err, res) {
292 if (err) throw err
293
294 const videos = res.body
295 expect(videos.length).to.equal(2)
296 expect(videos[0].name === 'video_short2.webm name')
297 expect(videos[1].name === 'video_short3.webm name')
298
299 done()
300 })
301 })
302
303 it('Should search all the videos', function (done) {
304 utils.searchVideoWithPagination(server.url, 'webm', 0, 15, function (err, res) {
305 if (err) throw err
306
307 const videos = res.body
308 expect(videos.length).to.equal(4)
309
310 done()
311 })
312 })
313
9f10b292 314 after(function (done) {
0c1cbbfe 315 process.kill(-server.app.pid)
9f10b292 316 process.kill(-webtorrent.app.pid)
8c308c2b 317
9f10b292
C
318 // Keep the logs if the test failed
319 if (this.ok) {
320 utils.flushTests(done)
321 } else {
322 done()
323 }
8c308c2b 324 })
9f10b292 325})