]>
git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/singlePod.js
0d0e6a82ef27469dafaf86f24c0f586da68d1408
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 () {
19 before(function (done
) {
24 utils
.flushTests(next
)
27 utils
.runServer(1, function (server1
) {
33 utils
.loginAndGetAccessToken(server
, function (err
, token
) {
35 server
.accessToken
= token
40 webtorrent
.create({ host: 'client', port: '1' }, next
)
45 it('Should not have videos', function (done
) {
46 utils
.getVideosList(server
.url
, function (err
, res
) {
49 expect(res
.body
).to
.be
.an('array')
50 expect(res
.body
.length
).to
.equal(0)
56 it('Should upload the video', function (done
) {
58 utils
.uploadVideo(server
.url
, server
.accessToken
, 'my super name', 'my super description', 'video_short.webm', done
)
61 it('Should seed the uploaded video', function (done
) {
62 // Yes, this could be long
65 utils
.getVideosList(server
.url
, function (err
, res
) {
68 expect(res
.body
).to
.be
.an('array')
69 expect(res
.body
.length
).to
.equal(1)
71 const video
= res
.body
[0]
72 expect(video
.name
).to
.equal('my super name')
73 expect(video
.description
).to
.equal('my super description')
74 expect(video
.podUrl
).to
.equal('http://localhost:9001')
75 expect(video
.magnetUri
).to
.exist
76 expect(video
.author
).to
.equal('root')
77 expect(video
.isLocal
).to
.be
.true
79 utils
.testImage(server
.url
, 'video_short.webm', video
.thumbnailPath
, function (err
, test
) {
81 expect(test
).to
.equal(true)
85 webtorrent
.add(video
.magnetUri
, function (torrent
) {
86 expect(torrent
.files
).to
.exist
87 expect(torrent
.files
.length
).to
.equal(1)
88 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
90 // We remove it because we'll add it again
91 webtorrent
.remove(video
.magnetUri
, done
)
97 it('Should get the video', function (done
) {
98 // Yes, this could be long
101 utils
.getVideo(server
.url
, videoId
, function (err
, res
) {
104 const video
= res
.body
105 expect(video
.name
).to
.equal('my super name')
106 expect(video
.description
).to
.equal('my super description')
107 expect(video
.podUrl
).to
.equal('http://localhost:9001')
108 expect(video
.magnetUri
).to
.exist
109 expect(video
.author
).to
.equal('root')
110 expect(video
.isLocal
).to
.be
.true
112 utils
.testImage(server
.url
, 'video_short.webm', video
.thumbnailPath
, function (err
, test
) {
114 expect(test
).to
.equal(true)
116 webtorrent
.add(video
.magnetUri
, function (torrent
) {
117 expect(torrent
.files
).to
.exist
118 expect(torrent
.files
.length
).to
.equal(1)
119 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
127 it('Should search the video', function (done
) {
128 utils
.searchVideo(server
.url
, 'my', function (err
, res
) {
131 expect(res
.body
).to
.be
.an('array')
132 expect(res
.body
.length
).to
.equal(1)
134 const video
= res
.body
[0]
135 expect(video
.name
).to
.equal('my super name')
136 expect(video
.description
).to
.equal('my super description')
137 expect(video
.podUrl
).to
.equal('http://localhost:9001')
138 expect(video
.author
).to
.equal('root')
139 expect(video
.isLocal
).to
.be
.true
141 utils
.testImage(server
.url
, 'video_short.webm', video
.thumbnailPath
, function (err
, test
) {
143 expect(test
).to
.equal(true)
150 it('Should not find a search', function (done
) {
151 utils
.searchVideo(server
.url
, 'hello', function (err
, res
) {
154 expect(res
.body
).to
.be
.an('array')
155 expect(res
.body
.length
).to
.equal(0)
161 it('Should remove the video', function (done
) {
162 utils
.removeVideo(server
.url
, server
.accessToken
, videoId
, function (err
) {
165 fs
.readdir(pathUtils
.join(__dirname
, '../../../test1/uploads/'), function (err
, files
) {
168 expect(files
.length
).to
.equal(0)
174 it('Should not have videos', function (done
) {
175 utils
.getVideosList(server
.url
, function (err
, res
) {
178 expect(res
.body
).to
.be
.an('array')
179 expect(res
.body
.length
).to
.equal(0)
185 it('Should upload 6 videos', function (done
) {
188 'video_short.mp4', 'video_short.ogv', 'video_short.webm',
189 'video_short1.webm', 'video_short2.webm', 'video_short3.webm'
191 async
.each(videos
, function (video
, callbackEach
) {
192 utils
.uploadVideo(server
.url
, server
.accessToken
, video
+ ' name', video
+ ' description', video
, callbackEach
)
196 it('Should have the correct durations', function (done
) {
197 utils
.getVideosList(server
.url
, function (err
, res
) {
200 const videos
= res
.body
201 expect(videos
).to
.be
.an('array')
202 expect(videos
.length
).to
.equal(6)
204 const videosByName
= keyBy(videos
, 'name')
205 expect(videosByName
['video_short.mp4 name'].duration
).to
.equal(5)
206 expect(videosByName
['video_short.ogv name'].duration
).to
.equal(5)
207 expect(videosByName
['video_short.webm name'].duration
).to
.equal(5)
208 expect(videosByName
['video_short1.webm name'].duration
).to
.equal(10)
209 expect(videosByName
['video_short2.webm name'].duration
).to
.equal(5)
210 expect(videosByName
['video_short3.webm name'].duration
).to
.equal(5)
216 it('Should have the correct thumbnails', function (done
) {
217 utils
.getVideosList(server
.url
, function (err
, res
) {
218 const videos
= res
.body
220 async
.each(videos
, function (video
, callbackEach
) {
222 const videoName
= video
.name
.replace(' name', '')
224 utils
.testImage(server
.url
, videoName
, video
.thumbnailPath
, function (err
, test
) {
227 expect(test
).to
.equal(true)
234 after(function (done
) {
235 process
.kill(-server
.app
.pid
)
236 process
.kill(-webtorrent
.app
.pid
)
238 // Keep the logs if the test failed
240 utils
.flushTests(done
)