]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/singlePod.js
64d5475dd7b5c558ef128446614da7d9c986ac21
[github/Chocobozzz/PeerTube.git] / server / tests / api / singlePod.js
1 'use strict'
2
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')
8
9 const webtorrent = require(pathUtils.join(__dirname, '../../lib/webtorrent'))
10 webtorrent.silent = true
11
12 const utils = require('./utils')
13
14 describe('Test a single pod', function () {
15 let server = null
16 let video_id = -1
17
18 before(function (done) {
19 this.timeout(20000)
20
21 async.series([
22 function (next) {
23 utils.flushTests(next)
24 },
25 function (next) {
26 utils.runServer(1, function (server1) {
27 server = server1
28 next()
29 })
30 },
31 function (next) {
32 utils.loginAndGetAccessToken(server, function (err, token) {
33 if (err) throw err
34 server.access_token = token
35 next()
36 })
37 },
38 function (next) {
39 webtorrent.create({ host: 'client', port: '1' }, next)
40 }
41 ], done)
42 })
43
44 it('Should not have videos', function (done) {
45 utils.getVideosList(server.url, function (err, res) {
46 if (err) throw err
47
48 expect(res.body).to.be.an('array')
49 expect(res.body.length).to.equal(0)
50
51 done()
52 })
53 })
54
55 it('Should upload the video', function (done) {
56 this.timeout(5000)
57 utils.uploadVideo(server.url, server.access_token, 'my super name', 'my super description', 'video_short.webm', done)
58 })
59
60 it('Should seed the uploaded video', function (done) {
61 // Yes, this could be long
62 this.timeout(60000)
63
64 utils.getVideosList(server.url, function (err, res) {
65 if (err) throw err
66
67 expect(res.body).to.be.an('array')
68 expect(res.body.length).to.equal(1)
69
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
76 video_id = video.id
77
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('')
82
83 done()
84 })
85 })
86 })
87
88 it('Should get the video', function (done) {
89 // Yes, this could be long
90 this.timeout(60000)
91
92 utils.getVideo(server.url, video_id, function (err, res) {
93 if (err) throw err
94
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
100
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('')
105
106 done()
107 })
108 })
109 })
110
111 it('Should search the video', function (done) {
112 utils.searchVideo(server.url, 'my', function (err, res) {
113 if (err) throw err
114
115 expect(res.body).to.be.an('array')
116 expect(res.body.length).to.equal(1)
117
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')
122
123 done()
124 })
125 })
126
127 it('Should not find a search', function (done) {
128 utils.searchVideo(server.url, 'hello', function (err, res) {
129 if (err) throw err
130
131 expect(res.body).to.be.an('array')
132 expect(res.body.length).to.equal(0)
133
134 done()
135 })
136 })
137
138 it('Should remove the video', function (done) {
139 utils.removeVideo(server.url, server.access_token, video_id, function (err) {
140 if (err) throw err
141
142 fs.readdir(pathUtils.join(__dirname, '../../../test1/uploads/'), function (err, files) {
143 if (err) throw err
144
145 expect(files.length).to.equal(0)
146 done()
147 })
148 })
149 })
150
151 it('Should not have videos', function (done) {
152 utils.getVideosList(server.url, function (err, res) {
153 if (err) throw err
154
155 expect(res.body).to.be.an('array')
156 expect(res.body.length).to.equal(0)
157
158 done()
159 })
160 })
161
162 after(function (done) {
163 process.kill(-server.app.pid)
164 process.kill(-webtorrent.app.pid)
165
166 // Keep the logs if the test failed
167 if (this.ok) {
168 utils.flushTests(done)
169 } else {
170 done()
171 }
172 })
173 })