]>
Commit | Line | Data |
---|---|---|
9f10b292 C |
1 | 'use strict' |
2 | ||
f0f5567b C |
3 | const async = require('async') |
4 | const chai = require('chai') | |
5 | const expect = chai.expect | |
6 | const fs = require('fs') | |
3a8a8b51 | 7 | const keyBy = require('lodash/keyBy') |
f0f5567b | 8 | const pathUtils = require('path') |
9f10b292 | 9 | |
f0f5567b | 10 | const webtorrent = require(pathUtils.join(__dirname, '../../lib/webtorrent')) |
9f10b292 C |
11 | webtorrent.silent = true |
12 | ||
f0f5567b | 13 | const utils = require('./utils') |
9f10b292 C |
14 | |
15 | describe('Test a single pod', function () { | |
0c1cbbfe | 16 | let server = null |
bc503c2a | 17 | let videoId = -1 |
9f10b292 C |
18 | |
19 | before(function (done) { | |
20 | this.timeout(20000) | |
21 | ||
22 | async.series([ | |
23 | function (next) { | |
24 | utils.flushTests(next) | |
25 | }, | |
26 | function (next) { | |
0c1cbbfe C |
27 | utils.runServer(1, function (server1) { |
28 | server = server1 | |
29 | next() | |
30 | }) | |
31 | }, | |
32 | function (next) { | |
33 | utils.loginAndGetAccessToken(server, function (err, token) { | |
34 | if (err) throw err | |
35 | server.access_token = token | |
9f10b292 C |
36 | next() |
37 | }) | |
38 | }, | |
39 | function (next) { | |
40 | webtorrent.create({ host: 'client', port: '1' }, next) | |
41 | } | |
42 | ], done) | |
43 | }) | |
8c308c2b | 44 | |
9f10b292 | 45 | it('Should not have videos', function (done) { |
0c1cbbfe | 46 | utils.getVideosList(server.url, function (err, res) { |
9f10b292 | 47 | if (err) throw err |
8c308c2b | 48 | |
9f10b292 C |
49 | expect(res.body).to.be.an('array') |
50 | expect(res.body.length).to.equal(0) | |
8c308c2b | 51 | |
9f10b292 | 52 | done() |
8c308c2b | 53 | }) |
9f10b292 | 54 | }) |
8c308c2b | 55 | |
9f10b292 C |
56 | it('Should upload the video', function (done) { |
57 | this.timeout(5000) | |
0c1cbbfe | 58 | utils.uploadVideo(server.url, server.access_token, 'my super name', 'my super description', 'video_short.webm', done) |
9f10b292 | 59 | }) |
8c308c2b | 60 | |
9f10b292 C |
61 | it('Should seed the uploaded video', function (done) { |
62 | // Yes, this could be long | |
63 | this.timeout(60000) | |
8c308c2b | 64 | |
0c1cbbfe | 65 | utils.getVideosList(server.url, function (err, res) { |
9f10b292 | 66 | if (err) throw err |
8c308c2b | 67 | |
9f10b292 C |
68 | expect(res.body).to.be.an('array') |
69 | expect(res.body.length).to.equal(1) | |
8c308c2b | 70 | |
f0f5567b | 71 | const video = res.body[0] |
9f10b292 C |
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 | |
6d8ada5f C |
76 | expect(video.author).to.equal('root') |
77 | expect(video.isLocal).to.be.true | |
8c308c2b | 78 | |
36d56024 | 79 | utils.testImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) { |
9e5f3740 C |
80 | if (err) throw err |
81 | expect(test).to.equal(true) | |
2df82d42 | 82 | |
bc503c2a | 83 | videoId = video.id |
2df82d42 | 84 | |
9e5f3740 C |
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('') | |
89 | ||
90 | done() | |
91 | }) | |
2df82d42 C |
92 | }) |
93 | }) | |
94 | }) | |
95 | ||
96 | it('Should get the video', function (done) { | |
97 | // Yes, this could be long | |
98 | this.timeout(60000) | |
99 | ||
bc503c2a | 100 | utils.getVideo(server.url, videoId, function (err, res) { |
2df82d42 C |
101 | if (err) throw err |
102 | ||
103 | const video = res.body | |
104 | expect(video.name).to.equal('my super name') | |
105 | expect(video.description).to.equal('my super description') | |
106 | expect(video.podUrl).to.equal('http://localhost:9001') | |
107 | expect(video.magnetUri).to.exist | |
6d8ada5f C |
108 | expect(video.author).to.equal('root') |
109 | expect(video.isLocal).to.be.true | |
8c308c2b | 110 | |
36d56024 | 111 | utils.testImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) { |
9e5f3740 C |
112 | if (err) throw err |
113 | expect(test).to.equal(true) | |
8c308c2b | 114 | |
9e5f3740 C |
115 | webtorrent.add(video.magnetUri, function (torrent) { |
116 | expect(torrent.files).to.exist | |
117 | expect(torrent.files.length).to.equal(1) | |
118 | expect(torrent.files[0].path).to.exist.and.to.not.equal('') | |
119 | ||
120 | done() | |
121 | }) | |
876d1bcf | 122 | }) |
8c308c2b | 123 | }) |
9f10b292 | 124 | }) |
8c308c2b | 125 | |
9f10b292 | 126 | it('Should search the video', function (done) { |
0c1cbbfe | 127 | utils.searchVideo(server.url, 'my', function (err, res) { |
9f10b292 | 128 | if (err) throw err |
4d5f8138 | 129 | |
9f10b292 C |
130 | expect(res.body).to.be.an('array') |
131 | expect(res.body.length).to.equal(1) | |
4d5f8138 | 132 | |
f0f5567b | 133 | const video = res.body[0] |
9f10b292 C |
134 | expect(video.name).to.equal('my super name') |
135 | expect(video.description).to.equal('my super description') | |
136 | expect(video.podUrl).to.equal('http://localhost:9001') | |
6d8ada5f C |
137 | expect(video.author).to.equal('root') |
138 | expect(video.isLocal).to.be.true | |
4d5f8138 | 139 | |
36d56024 | 140 | utils.testImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) { |
9e5f3740 C |
141 | if (err) throw err |
142 | expect(test).to.equal(true) | |
143 | ||
144 | done() | |
145 | }) | |
4d5f8138 | 146 | }) |
9f10b292 | 147 | }) |
4d5f8138 | 148 | |
9f10b292 | 149 | it('Should not find a search', function (done) { |
0c1cbbfe | 150 | utils.searchVideo(server.url, 'hello', function (err, res) { |
9f10b292 | 151 | if (err) throw err |
4d5f8138 | 152 | |
9f10b292 C |
153 | expect(res.body).to.be.an('array') |
154 | expect(res.body.length).to.equal(0) | |
4d5f8138 | 155 | |
9f10b292 | 156 | done() |
4d5f8138 | 157 | }) |
9f10b292 | 158 | }) |
4d5f8138 | 159 | |
9f10b292 | 160 | it('Should remove the video', function (done) { |
bc503c2a | 161 | utils.removeVideo(server.url, server.accessToken, videoId, function (err) { |
9f10b292 | 162 | if (err) throw err |
f5a60a51 | 163 | |
3d446a26 | 164 | fs.readdir(pathUtils.join(__dirname, '../../../test1/uploads/'), function (err, files) { |
9f10b292 | 165 | if (err) throw err |
f5a60a51 | 166 | |
9f10b292 C |
167 | expect(files.length).to.equal(0) |
168 | done() | |
876d1bcf | 169 | }) |
8c308c2b | 170 | }) |
9f10b292 | 171 | }) |
8c308c2b | 172 | |
9f10b292 | 173 | it('Should not have videos', function (done) { |
0c1cbbfe | 174 | utils.getVideosList(server.url, function (err, res) { |
9f10b292 | 175 | if (err) throw err |
8c308c2b | 176 | |
9f10b292 C |
177 | expect(res.body).to.be.an('array') |
178 | expect(res.body.length).to.equal(0) | |
8c308c2b | 179 | |
9f10b292 | 180 | done() |
8c308c2b | 181 | }) |
9f10b292 | 182 | }) |
8c308c2b | 183 | |
3a8a8b51 C |
184 | it('Should upload 6 videos', function (done) { |
185 | this.timeout(25000) | |
186 | const videos = [ | |
187 | 'video_short.mp4', 'video_short.ogv', 'video_short.webm', | |
188 | 'video_short1.webm', 'video_short2.webm', 'video_short3.webm' | |
189 | ] | |
bc503c2a C |
190 | async.each(videos, function (video, callbackEach) { |
191 | utils.uploadVideo(server.url, server.accessToken, video + ' name', video + ' description', video, callbackEach) | |
3a8a8b51 C |
192 | }, done) |
193 | }) | |
194 | ||
195 | it('Should have the correct durations', function (done) { | |
196 | utils.getVideosList(server.url, function (err, res) { | |
197 | if (err) throw err | |
198 | ||
199 | const videos = res.body | |
200 | expect(videos).to.be.an('array') | |
201 | expect(videos.length).to.equal(6) | |
202 | ||
bc503c2a C |
203 | const videosByName = keyBy(videos, 'name') |
204 | expect(videosByName['video_short.mp4 name'].duration).to.equal(5) | |
205 | expect(videosByName['video_short.ogv name'].duration).to.equal(5) | |
206 | expect(videosByName['video_short.webm name'].duration).to.equal(5) | |
207 | expect(videosByName['video_short1.webm name'].duration).to.equal(10) | |
208 | expect(videosByName['video_short2.webm name'].duration).to.equal(5) | |
209 | expect(videosByName['video_short3.webm name'].duration).to.equal(5) | |
3a8a8b51 C |
210 | |
211 | done() | |
212 | }) | |
213 | }) | |
214 | ||
9e5f3740 C |
215 | it('Should have the correct thumbnails', function (done) { |
216 | utils.getVideosList(server.url, function (err, res) { | |
217 | const videos = res.body | |
218 | ||
bc503c2a | 219 | async.each(videos, function (video, callbackEach) { |
9e5f3740 | 220 | if (err) throw err |
bc503c2a | 221 | const videoName = video.name.replace(' name', '') |
9e5f3740 | 222 | |
bc503c2a | 223 | utils.testImage(server.url, videoName, video.thumbnailPath, function (err, test) { |
9e5f3740 C |
224 | if (err) throw err |
225 | ||
226 | expect(test).to.equal(true) | |
bc503c2a | 227 | callbackEach() |
9e5f3740 C |
228 | }) |
229 | }, done) | |
230 | }) | |
231 | }) | |
232 | ||
9f10b292 | 233 | after(function (done) { |
0c1cbbfe | 234 | process.kill(-server.app.pid) |
9f10b292 | 235 | process.kill(-webtorrent.app.pid) |
8c308c2b | 236 | |
9f10b292 C |
237 | // Keep the logs if the test failed |
238 | if (this.ok) { | |
239 | utils.flushTests(done) | |
240 | } else { | |
241 | done() | |
242 | } | |
8c308c2b | 243 | }) |
9f10b292 | 244 | }) |