]>
git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/singlePod.js
3 const async
= require('async')
4 const chai
= require('chai')
5 const expect
= chai
.expect
6 const fs
= require('fs')
7 const keyBy
= require('lodash/keyBy')
8 const pathUtils
= require('path')
10 const webtorrent
= require(pathUtils
.join(__dirname
, '../../lib/webtorrent'))
11 webtorrent
.silent
= true
13 const utils
= require('./utils')
15 describe('Test a single pod', function () {
18 let videosListBase
= null
20 before(function (done
) {
25 utils
.flushTests(next
)
28 utils
.runServer(1, function (server1
) {
34 utils
.loginAndGetAccessToken(server
, function (err
, token
) {
36 server
.accessToken
= token
41 webtorrent
.create({ host: 'client', port: '1' }, next
)
46 it('Should not have videos', function (done
) {
47 utils
.getVideosList(server
.url
, function (err
, res
) {
50 expect(res
.body
).to
.be
.an('array')
51 expect(res
.body
.length
).to
.equal(0)
57 it('Should upload the video', function (done
) {
59 utils
.uploadVideo(server
.url
, server
.accessToken
, 'my super name', 'my super description', 'video_short.webm', done
)
62 it('Should seed the uploaded video', function (done
) {
63 // Yes, this could be long
66 utils
.getVideosList(server
.url
, function (err
, res
) {
69 expect(res
.body
).to
.be
.an('array')
70 expect(res
.body
.length
).to
.equal(1)
72 const video
= res
.body
[0]
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
77 expect(video
.author
).to
.equal('root')
78 expect(video
.isLocal
).to
.be
.true
80 utils
.testImage(server
.url
, 'video_short.webm', video
.thumbnailPath
, function (err
, test
) {
82 expect(test
).to
.equal(true)
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('')
91 // We remove it because we'll add it again
92 webtorrent
.remove(video
.magnetUri
, done
)
98 it('Should get the video', function (done
) {
99 // Yes, this could be long
102 utils
.getVideo(server
.url
, videoId
, function (err
, res
) {
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
110 expect(video
.author
).to
.equal('root')
111 expect(video
.isLocal
).to
.be
.true
113 utils
.testImage(server
.url
, 'video_short.webm', video
.thumbnailPath
, function (err
, test
) {
115 expect(test
).to
.equal(true)
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('')
128 it('Should search the video', function (done
) {
129 utils
.searchVideo(server
.url
, 'my', function (err
, res
) {
132 expect(res
.body
).to
.be
.an('array')
133 expect(res
.body
.length
).to
.equal(1)
135 const video
= res
.body
[0]
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')
139 expect(video
.author
).to
.equal('root')
140 expect(video
.isLocal
).to
.be
.true
142 utils
.testImage(server
.url
, 'video_short.webm', video
.thumbnailPath
, function (err
, test
) {
144 expect(test
).to
.equal(true)
151 it('Should not find a search', function (done
) {
152 utils
.searchVideo(server
.url
, 'hello', function (err
, res
) {
155 expect(res
.body
).to
.be
.an('array')
156 expect(res
.body
.length
).to
.equal(0)
162 it('Should remove the video', function (done
) {
163 utils
.removeVideo(server
.url
, server
.accessToken
, videoId
, function (err
) {
166 fs
.readdir(pathUtils
.join(__dirname
, '../../../test1/uploads/'), function (err
, files
) {
169 expect(files
.length
).to
.equal(0)
175 it('Should not have videos', function (done
) {
176 utils
.getVideosList(server
.url
, function (err
, res
) {
179 expect(res
.body
).to
.be
.an('array')
180 expect(res
.body
.length
).to
.equal(0)
186 it('Should upload 6 videos', function (done
) {
189 'video_short.mp4', 'video_short.ogv', 'video_short.webm',
190 'video_short1.webm', 'video_short2.webm', 'video_short3.webm'
192 async
.each(videos
, function (video
, callbackEach
) {
193 utils
.uploadVideo(server
.url
, server
.accessToken
, video
+ ' name', video
+ ' description', video
, callbackEach
)
197 it('Should have the correct durations', function (done
) {
198 utils
.getVideosList(server
.url
, function (err
, res
) {
201 const videos
= res
.body
202 expect(videos
).to
.be
.an('array')
203 expect(videos
.length
).to
.equal(6)
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)
217 it('Should have the correct thumbnails', function (done
) {
218 utils
.getVideosList(server
.url
, function (err
, res
) {
221 const videos
= res
.body
223 videosListBase
= videos
225 async
.each(videos
, function (video
, callbackEach
) {
227 const videoName
= video
.name
.replace(' name', '')
229 utils
.testImage(server
.url
, videoName
, video
.thumbnailPath
, function (err
, test
) {
232 expect(test
).to
.equal(true)
239 it('Should list only the two first videos', function (done
) {
240 utils
.getVideosListPagination(server
.url
, 0, 2, function (err
, res
) {
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
)
252 it('Should list only the next three videos', function (done
) {
253 utils
.getVideosListPagination(server
.url
, 2, 3, function (err
, res
) {
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
)
266 it('Should list the last video', function (done
) {
267 utils
.getVideosListPagination(server
.url
, 5, 6, function (err
, res
) {
270 const videos
= res
.body
271 expect(videos
.length
).to
.equal(1)
272 expect(videos
[0].name
=== videosListBase
[5].name
)
278 it('Should search the first video', function (done
) {
279 utils
.searchVideoWithPagination(server
.url
, 'webm', 0, 1, function (err
, res
) {
282 const videos
= res
.body
283 expect(videos
.length
).to
.equal(1)
284 expect(videos
[0].name
=== 'video_short.webm name')
290 it('Should search the last two videos', function (done
) {
291 utils
.searchVideoWithPagination(server
.url
, 'webm', 2, 2, function (err
, res
) {
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')
303 it('Should search all the videos', function (done
) {
304 utils
.searchVideoWithPagination(server
.url
, 'webm', 0, 15, function (err
, res
) {
307 const videos
= res
.body
308 expect(videos
.length
).to
.equal(4)
314 after(function (done
) {
315 process
.kill(-server
.app
.pid
)
316 process
.kill(-webtorrent
.app
.pid
)
318 // Keep the logs if the test failed
320 utils
.flushTests(done
)