]>
git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/singlePod.js
72002b6313eeaa6d8f7bb4d6608789dc463876fd
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
79 expect(utils
.dateIsValid(video
.createdDate
)).to
.be
.true
81 utils
.testImage(server
.url
, 'video_short.webm', video
.thumbnailPath
, function (err
, test
) {
83 expect(test
).to
.equal(true)
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('')
92 // We remove it because we'll add it again
93 webtorrent
.remove(video
.magnetUri
, done
)
99 it('Should get the video', function (done
) {
100 // Yes, this could be long
103 utils
.getVideo(server
.url
, videoId
, function (err
, res
) {
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
111 expect(video
.author
).to
.equal('root')
112 expect(video
.isLocal
).to
.be
.true
113 expect(utils
.dateIsValid(video
.createdDate
)).to
.be
.true
115 utils
.testImage(server
.url
, 'video_short.webm', video
.thumbnailPath
, function (err
, test
) {
117 expect(test
).to
.equal(true)
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('')
130 it('Should search the video', function (done
) {
131 utils
.searchVideo(server
.url
, 'my', function (err
, res
) {
134 expect(res
.body
).to
.be
.an('array')
135 expect(res
.body
.length
).to
.equal(1)
137 const video
= res
.body
[0]
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')
141 expect(video
.author
).to
.equal('root')
142 expect(video
.isLocal
).to
.be
.true
143 expect(utils
.dateIsValid(video
.createdDate
)).to
.be
.true
145 utils
.testImage(server
.url
, 'video_short.webm', video
.thumbnailPath
, function (err
, test
) {
147 expect(test
).to
.equal(true)
154 it('Should not find a search', function (done
) {
155 utils
.searchVideo(server
.url
, 'hello', function (err
, res
) {
158 expect(res
.body
).to
.be
.an('array')
159 expect(res
.body
.length
).to
.equal(0)
165 it('Should remove the video', function (done
) {
166 utils
.removeVideo(server
.url
, server
.accessToken
, videoId
, function (err
) {
169 fs
.readdir(pathUtils
.join(__dirname
, '../../../test1/uploads/'), function (err
, files
) {
172 expect(files
.length
).to
.equal(0)
178 it('Should not have videos', function (done
) {
179 utils
.getVideosList(server
.url
, function (err
, res
) {
182 expect(res
.body
).to
.be
.an('array')
183 expect(res
.body
.length
).to
.equal(0)
189 it('Should upload 6 videos', function (done
) {
192 'video_short.mp4', 'video_short.ogv', 'video_short.webm',
193 'video_short1.webm', 'video_short2.webm', 'video_short3.webm'
195 async
.each(videos
, function (video
, callbackEach
) {
196 utils
.uploadVideo(server
.url
, server
.accessToken
, video
+ ' name', video
+ ' description', video
, callbackEach
)
200 it('Should have the correct durations', function (done
) {
201 utils
.getVideosList(server
.url
, function (err
, res
) {
204 const videos
= res
.body
205 expect(videos
).to
.be
.an('array')
206 expect(videos
.length
).to
.equal(6)
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)
220 it('Should have the correct thumbnails', function (done
) {
221 utils
.getVideosList(server
.url
, function (err
, res
) {
224 const videos
= res
.body
226 videosListBase
= videos
228 async
.each(videos
, function (video
, callbackEach
) {
230 const videoName
= video
.name
.replace(' name', '')
232 utils
.testImage(server
.url
, videoName
, video
.thumbnailPath
, function (err
, test
) {
235 expect(test
).to
.equal(true)
242 it('Should list only the two first videos', function (done
) {
243 utils
.getVideosListPagination(server
.url
, 0, 2, function (err
, res
) {
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
)
255 it('Should list only the next three videos', function (done
) {
256 utils
.getVideosListPagination(server
.url
, 2, 3, function (err
, res
) {
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
)
269 it('Should list the last video', function (done
) {
270 utils
.getVideosListPagination(server
.url
, 5, 6, function (err
, res
) {
273 const videos
= res
.body
274 expect(videos
.length
).to
.equal(1)
275 expect(videos
[0].name
=== videosListBase
[5].name
)
281 it('Should search the first video', function (done
) {
282 utils
.searchVideoWithPagination(server
.url
, 'webm', 0, 1, function (err
, res
) {
285 const videos
= res
.body
286 expect(videos
.length
).to
.equal(1)
287 expect(videos
[0].name
=== 'video_short.webm name')
293 it('Should search the last two videos', function (done
) {
294 utils
.searchVideoWithPagination(server
.url
, 'webm', 2, 2, function (err
, res
) {
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')
306 it('Should search all the videos', function (done
) {
307 utils
.searchVideoWithPagination(server
.url
, 'webm', 0, 15, function (err
, res
) {
310 const videos
= res
.body
311 expect(videos
.length
).to
.equal(4)
317 after(function (done
) {
318 process
.kill(-server
.app
.pid
)
319 process
.kill(-webtorrent
.app
.pid
)
321 // Keep the logs if the test failed
323 utils
.flushTests(done
)