]>
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 | |
b6c6f935 | 35 | server.accessToken = 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) | |
b6c6f935 | 58 | utils.uploadVideo(server.url, server.accessToken, '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 | ||
b6c6f935 C |
90 | // We remove it because we'll add it again |
91 | webtorrent.remove(video.magnetUri, done) | |
9e5f3740 | 92 | }) |
2df82d42 C |
93 | }) |
94 | }) | |
95 | }) | |
96 | ||
97 | it('Should get the video', function (done) { | |
98 | // Yes, this could be long | |
99 | this.timeout(60000) | |
100 | ||
bc503c2a | 101 | utils.getVideo(server.url, videoId, function (err, res) { |
2df82d42 C |
102 | if (err) throw err |
103 | ||
104 | const video = res.body | |
105 | expect(video.name).to.equal('my super name') | |
106 | expect(video.description).to.equal('my super description') | |
107 | expect(video.podUrl).to.equal('http://localhost:9001') | |
108 | expect(video.magnetUri).to.exist | |
6d8ada5f C |
109 | expect(video.author).to.equal('root') |
110 | expect(video.isLocal).to.be.true | |
8c308c2b | 111 | |
36d56024 | 112 | utils.testImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) { |
9e5f3740 C |
113 | if (err) throw err |
114 | expect(test).to.equal(true) | |
8c308c2b | 115 | |
9e5f3740 C |
116 | webtorrent.add(video.magnetUri, function (torrent) { |
117 | expect(torrent.files).to.exist | |
118 | expect(torrent.files.length).to.equal(1) | |
119 | expect(torrent.files[0].path).to.exist.and.to.not.equal('') | |
120 | ||
121 | done() | |
122 | }) | |
876d1bcf | 123 | }) |
8c308c2b | 124 | }) |
9f10b292 | 125 | }) |
8c308c2b | 126 | |
9f10b292 | 127 | it('Should search the video', function (done) { |
0c1cbbfe | 128 | utils.searchVideo(server.url, 'my', function (err, res) { |
9f10b292 | 129 | if (err) throw err |
4d5f8138 | 130 | |
9f10b292 C |
131 | expect(res.body).to.be.an('array') |
132 | expect(res.body.length).to.equal(1) | |
4d5f8138 | 133 | |
f0f5567b | 134 | const video = res.body[0] |
9f10b292 C |
135 | expect(video.name).to.equal('my super name') |
136 | expect(video.description).to.equal('my super description') | |
137 | expect(video.podUrl).to.equal('http://localhost:9001') | |
6d8ada5f C |
138 | expect(video.author).to.equal('root') |
139 | expect(video.isLocal).to.be.true | |
4d5f8138 | 140 | |
36d56024 | 141 | utils.testImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) { |
9e5f3740 C |
142 | if (err) throw err |
143 | expect(test).to.equal(true) | |
144 | ||
145 | done() | |
146 | }) | |
4d5f8138 | 147 | }) |
9f10b292 | 148 | }) |
4d5f8138 | 149 | |
9f10b292 | 150 | it('Should not find a search', function (done) { |
0c1cbbfe | 151 | utils.searchVideo(server.url, 'hello', function (err, res) { |
9f10b292 | 152 | if (err) throw err |
4d5f8138 | 153 | |
9f10b292 C |
154 | expect(res.body).to.be.an('array') |
155 | expect(res.body.length).to.equal(0) | |
4d5f8138 | 156 | |
9f10b292 | 157 | done() |
4d5f8138 | 158 | }) |
9f10b292 | 159 | }) |
4d5f8138 | 160 | |
9f10b292 | 161 | it('Should remove the video', function (done) { |
bc503c2a | 162 | utils.removeVideo(server.url, server.accessToken, videoId, function (err) { |
9f10b292 | 163 | if (err) throw err |
f5a60a51 | 164 | |
3d446a26 | 165 | fs.readdir(pathUtils.join(__dirname, '../../../test1/uploads/'), function (err, files) { |
9f10b292 | 166 | if (err) throw err |
f5a60a51 | 167 | |
9f10b292 C |
168 | expect(files.length).to.equal(0) |
169 | done() | |
876d1bcf | 170 | }) |
8c308c2b | 171 | }) |
9f10b292 | 172 | }) |
8c308c2b | 173 | |
9f10b292 | 174 | it('Should not have videos', function (done) { |
0c1cbbfe | 175 | utils.getVideosList(server.url, function (err, res) { |
9f10b292 | 176 | if (err) throw err |
8c308c2b | 177 | |
9f10b292 C |
178 | expect(res.body).to.be.an('array') |
179 | expect(res.body.length).to.equal(0) | |
8c308c2b | 180 | |
9f10b292 | 181 | done() |
8c308c2b | 182 | }) |
9f10b292 | 183 | }) |
8c308c2b | 184 | |
3a8a8b51 C |
185 | it('Should upload 6 videos', function (done) { |
186 | this.timeout(25000) | |
187 | const videos = [ | |
188 | 'video_short.mp4', 'video_short.ogv', 'video_short.webm', | |
189 | 'video_short1.webm', 'video_short2.webm', 'video_short3.webm' | |
190 | ] | |
bc503c2a C |
191 | async.each(videos, function (video, callbackEach) { |
192 | utils.uploadVideo(server.url, server.accessToken, video + ' name', video + ' description', video, callbackEach) | |
3a8a8b51 C |
193 | }, done) |
194 | }) | |
195 | ||
196 | it('Should have the correct durations', function (done) { | |
197 | utils.getVideosList(server.url, function (err, res) { | |
198 | if (err) throw err | |
199 | ||
200 | const videos = res.body | |
201 | expect(videos).to.be.an('array') | |
202 | expect(videos.length).to.equal(6) | |
203 | ||
bc503c2a C |
204 | const videosByName = keyBy(videos, 'name') |
205 | expect(videosByName['video_short.mp4 name'].duration).to.equal(5) | |
206 | expect(videosByName['video_short.ogv name'].duration).to.equal(5) | |
207 | expect(videosByName['video_short.webm name'].duration).to.equal(5) | |
208 | expect(videosByName['video_short1.webm name'].duration).to.equal(10) | |
209 | expect(videosByName['video_short2.webm name'].duration).to.equal(5) | |
210 | expect(videosByName['video_short3.webm name'].duration).to.equal(5) | |
3a8a8b51 C |
211 | |
212 | done() | |
213 | }) | |
214 | }) | |
215 | ||
9e5f3740 C |
216 | it('Should have the correct thumbnails', function (done) { |
217 | utils.getVideosList(server.url, function (err, res) { | |
218 | const videos = res.body | |
219 | ||
bc503c2a | 220 | async.each(videos, function (video, callbackEach) { |
9e5f3740 | 221 | if (err) throw err |
bc503c2a | 222 | const videoName = video.name.replace(' name', '') |
9e5f3740 | 223 | |
bc503c2a | 224 | utils.testImage(server.url, videoName, video.thumbnailPath, function (err, test) { |
9e5f3740 C |
225 | if (err) throw err |
226 | ||
227 | expect(test).to.equal(true) | |
bc503c2a | 228 | callbackEach() |
9e5f3740 C |
229 | }) |
230 | }, done) | |
231 | }) | |
232 | }) | |
233 | ||
9f10b292 | 234 | after(function (done) { |
0c1cbbfe | 235 | process.kill(-server.app.pid) |
9f10b292 | 236 | process.kill(-webtorrent.app.pid) |
8c308c2b | 237 | |
9f10b292 C |
238 | // Keep the logs if the test failed |
239 | if (this.ok) { | |
240 | utils.flushTests(done) | |
241 | } else { | |
242 | done() | |
243 | } | |
8c308c2b | 244 | }) |
9f10b292 | 245 | }) |