]>
git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/singlePod.js
efd8a64bc7fd4e94708c2754fb36b056a9eb660b
3 const async
= require('async')
4 const chai
= require('chai')
5 const expect
= chai
.expect
6 const fs
= require('fs')
7 const pathUtils
= require('path')
9 const webtorrent
= require(pathUtils
.join(__dirname
, '../../lib/webtorrent'))
10 webtorrent
.silent
= true
12 const utils
= require('./utils')
14 describe('Test a single pod', function () {
18 before(function (done
) {
23 utils
.flushTests(next
)
26 utils
.runServer(1, function (server1
) {
32 utils
.loginAndGetAccessToken(server
, function (err
, token
) {
34 server
.access_token
= token
39 webtorrent
.create({ host: 'client', port: '1' }, next
)
44 it('Should not have videos', function (done
) {
45 utils
.getVideosList(server
.url
, function (err
, res
) {
48 expect(res
.body
).to
.be
.an('array')
49 expect(res
.body
.length
).to
.equal(0)
55 it('Should upload the video', function (done
) {
57 utils
.uploadVideo(server
.url
, server
.access_token
, 'my super name', 'my super description', 'video_short.webm', done
)
60 it('Should seed the uploaded video', function (done
) {
61 // Yes, this could be long
64 utils
.getVideosList(server
.url
, function (err
, res
) {
67 expect(res
.body
).to
.be
.an('array')
68 expect(res
.body
.length
).to
.equal(1)
70 const video
= res
.body
[0]
71 expect(video
.name
).to
.equal('my super name')
72 expect(video
.description
).to
.equal('my super description')
73 expect(video
.podUrl
).to
.equal('http://localhost:9001')
74 expect(video
.magnetUri
).to
.exist
75 expect(video
.author
).to
.equal('root')
76 expect(video
.isLocal
).to
.be
.true
80 webtorrent
.add(video
.magnetUri
, function (torrent
) {
81 expect(torrent
.files
).to
.exist
82 expect(torrent
.files
.length
).to
.equal(1)
83 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
90 it('Should get the video', function (done
) {
91 // Yes, this could be long
94 utils
.getVideo(server
.url
, video_id
, function (err
, res
) {
97 const video
= res
.body
98 expect(video
.name
).to
.equal('my super name')
99 expect(video
.description
).to
.equal('my super description')
100 expect(video
.podUrl
).to
.equal('http://localhost:9001')
101 expect(video
.magnetUri
).to
.exist
102 expect(video
.author
).to
.equal('root')
103 expect(video
.isLocal
).to
.be
.true
105 webtorrent
.add(video
.magnetUri
, function (torrent
) {
106 expect(torrent
.files
).to
.exist
107 expect(torrent
.files
.length
).to
.equal(1)
108 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
115 it('Should search the video', function (done
) {
116 utils
.searchVideo(server
.url
, 'my', function (err
, res
) {
119 expect(res
.body
).to
.be
.an('array')
120 expect(res
.body
.length
).to
.equal(1)
122 const video
= res
.body
[0]
123 expect(video
.name
).to
.equal('my super name')
124 expect(video
.description
).to
.equal('my super description')
125 expect(video
.podUrl
).to
.equal('http://localhost:9001')
126 expect(video
.author
).to
.equal('root')
127 expect(video
.isLocal
).to
.be
.true
133 it('Should not find a search', function (done
) {
134 utils
.searchVideo(server
.url
, 'hello', function (err
, res
) {
137 expect(res
.body
).to
.be
.an('array')
138 expect(res
.body
.length
).to
.equal(0)
144 it('Should remove the video', function (done
) {
145 utils
.removeVideo(server
.url
, server
.access_token
, video_id
, function (err
) {
148 fs
.readdir(pathUtils
.join(__dirname
, '../../../test1/uploads/'), function (err
, files
) {
151 expect(files
.length
).to
.equal(0)
157 it('Should not have videos', function (done
) {
158 utils
.getVideosList(server
.url
, function (err
, res
) {
161 expect(res
.body
).to
.be
.an('array')
162 expect(res
.body
.length
).to
.equal(0)
168 after(function (done
) {
169 process
.kill(-server
.app
.pid
)
170 process
.kill(-webtorrent
.app
.pid
)
172 // Keep the logs if the test failed
174 utils
.flushTests(done
)