]>
git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/singlePod.js
e2999530eab334b5f5918ccc404ea5502467ac23
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
.access_token
= 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
.access_token
, '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
81 webtorrent
.add(video
.magnetUri
, function (torrent
) {
82 expect(torrent
.files
).to
.exist
83 expect(torrent
.files
.length
).to
.equal(1)
84 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
91 it('Should get the video', function (done
) {
92 // Yes, this could be long
95 utils
.getVideo(server
.url
, video_id
, function (err
, res
) {
98 const video
= res
.body
99 expect(video
.name
).to
.equal('my super name')
100 expect(video
.description
).to
.equal('my super description')
101 expect(video
.podUrl
).to
.equal('http://localhost:9001')
102 expect(video
.magnetUri
).to
.exist
103 expect(video
.author
).to
.equal('root')
104 expect(video
.isLocal
).to
.be
.true
106 webtorrent
.add(video
.magnetUri
, function (torrent
) {
107 expect(torrent
.files
).to
.exist
108 expect(torrent
.files
.length
).to
.equal(1)
109 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
116 it('Should search the video', function (done
) {
117 utils
.searchVideo(server
.url
, 'my', function (err
, res
) {
120 expect(res
.body
).to
.be
.an('array')
121 expect(res
.body
.length
).to
.equal(1)
123 const video
= res
.body
[0]
124 expect(video
.name
).to
.equal('my super name')
125 expect(video
.description
).to
.equal('my super description')
126 expect(video
.podUrl
).to
.equal('http://localhost:9001')
127 expect(video
.author
).to
.equal('root')
128 expect(video
.isLocal
).to
.be
.true
134 it('Should not find a search', function (done
) {
135 utils
.searchVideo(server
.url
, 'hello', function (err
, res
) {
138 expect(res
.body
).to
.be
.an('array')
139 expect(res
.body
.length
).to
.equal(0)
145 it('Should remove the video', function (done
) {
146 utils
.removeVideo(server
.url
, server
.access_token
, video_id
, function (err
) {
149 fs
.readdir(pathUtils
.join(__dirname
, '../../../test1/uploads/'), function (err
, files
) {
152 expect(files
.length
).to
.equal(0)
158 it('Should not have videos', function (done
) {
159 utils
.getVideosList(server
.url
, function (err
, res
) {
162 expect(res
.body
).to
.be
.an('array')
163 expect(res
.body
.length
).to
.equal(0)
169 it('Should upload 6 videos', function (done
) {
172 'video_short.mp4', 'video_short.ogv', 'video_short.webm',
173 'video_short1.webm', 'video_short2.webm', 'video_short3.webm'
175 async
.each(videos
, function (video
, callback_each
) {
176 utils
.uploadVideo(server
.url
, server
.access_token
, video
+ ' name', video
+ ' description', video
, callback_each
)
180 it('Should have the correct durations', function (done
) {
181 utils
.getVideosList(server
.url
, function (err
, res
) {
184 const videos
= res
.body
185 expect(videos
).to
.be
.an('array')
186 expect(videos
.length
).to
.equal(6)
188 const videos_by_name
= keyBy(videos
, 'name')
189 expect(videos_by_name
['video_short.mp4 name'].duration
).to
.equal(5)
190 expect(videos_by_name
['video_short.ogv name'].duration
).to
.equal(5)
191 expect(videos_by_name
['video_short.webm name'].duration
).to
.equal(5)
192 expect(videos_by_name
['video_short1.webm name'].duration
).to
.equal(10)
193 expect(videos_by_name
['video_short2.webm name'].duration
).to
.equal(5)
194 expect(videos_by_name
['video_short3.webm name'].duration
).to
.equal(5)
200 after(function (done
) {
201 process
.kill(-server
.app
.pid
)
202 process
.kill(-webtorrent
.app
.pid
)
204 // Keep the logs if the test failed
206 utils
.flushTests(done
)