]>
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 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
78 webtorrent
.add(video
.magnetUri
, function (torrent
) {
79 expect(torrent
.files
).to
.exist
80 expect(torrent
.files
.length
).to
.equal(1)
81 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
88 it('Should get the video', function (done
) {
89 // Yes, this could be long
92 utils
.getVideo(server
.url
, video_id
, function (err
, res
) {
95 const video
= res
.body
96 expect(video
.name
).to
.equal('my super name')
97 expect(video
.description
).to
.equal('my super description')
98 expect(video
.podUrl
).to
.equal('http://localhost:9001')
99 expect(video
.magnetUri
).to
.exist
101 webtorrent
.add(video
.magnetUri
, function (torrent
) {
102 expect(torrent
.files
).to
.exist
103 expect(torrent
.files
.length
).to
.equal(1)
104 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
111 it('Should search the video', function (done
) {
112 utils
.searchVideo(server
.url
, 'my', function (err
, res
) {
115 expect(res
.body
).to
.be
.an('array')
116 expect(res
.body
.length
).to
.equal(1)
118 const video
= res
.body
[0]
119 expect(video
.name
).to
.equal('my super name')
120 expect(video
.description
).to
.equal('my super description')
121 expect(video
.podUrl
).to
.equal('http://localhost:9001')
127 it('Should not find a search', function (done
) {
128 utils
.searchVideo(server
.url
, 'hello', function (err
, res
) {
131 expect(res
.body
).to
.be
.an('array')
132 expect(res
.body
.length
).to
.equal(0)
138 it('Should remove the video', function (done
) {
139 utils
.removeVideo(server
.url
, server
.access_token
, video_id
, function (err
) {
142 fs
.readdir(pathUtils
.join(__dirname
, '../../../test1/uploads/'), function (err
, files
) {
145 expect(files
.length
).to
.equal(0)
151 it('Should not have videos', function (done
) {
152 utils
.getVideosList(server
.url
, function (err
, res
) {
155 expect(res
.body
).to
.be
.an('array')
156 expect(res
.body
.length
).to
.equal(0)
162 after(function (done
) {
163 process
.kill(-server
.app
.pid
)
164 process
.kill(-webtorrent
.app
.pid
)
166 // Keep the logs if the test failed
168 utils
.flushTests(done
)