]>
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 |
f0f5567b | 17 | let video_id = -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 | |
2df82d42 C |
79 | video_id = video.id |
80 | ||
81 | webtorrent.add(video.magnetUri, function (torrent) { | |
82 | expect(torrent.files).to.exist | |
83 | expect(torrent.files.length).to.equal(1) | |
84 | expect(torrent.files[0].path).to.exist.and.to.not.equal('') | |
85 | ||
86 | done() | |
87 | }) | |
88 | }) | |
89 | }) | |
90 | ||
91 | it('Should get the video', function (done) { | |
92 | // Yes, this could be long | |
93 | this.timeout(60000) | |
94 | ||
0c1cbbfe | 95 | utils.getVideo(server.url, video_id, function (err, res) { |
2df82d42 C |
96 | if (err) throw err |
97 | ||
98 | const video = res.body | |
99 | expect(video.name).to.equal('my super name') | |
100 | expect(video.description).to.equal('my super description') | |
101 | expect(video.podUrl).to.equal('http://localhost:9001') | |
102 | expect(video.magnetUri).to.exist | |
6d8ada5f C |
103 | expect(video.author).to.equal('root') |
104 | expect(video.isLocal).to.be.true | |
8c308c2b | 105 | |
9f10b292 C |
106 | webtorrent.add(video.magnetUri, function (torrent) { |
107 | expect(torrent.files).to.exist | |
108 | expect(torrent.files.length).to.equal(1) | |
109 | expect(torrent.files[0].path).to.exist.and.to.not.equal('') | |
8c308c2b | 110 | |
9f10b292 | 111 | done() |
876d1bcf | 112 | }) |
8c308c2b | 113 | }) |
9f10b292 | 114 | }) |
8c308c2b | 115 | |
9f10b292 | 116 | it('Should search the video', function (done) { |
0c1cbbfe | 117 | utils.searchVideo(server.url, 'my', function (err, res) { |
9f10b292 | 118 | if (err) throw err |
4d5f8138 | 119 | |
9f10b292 C |
120 | expect(res.body).to.be.an('array') |
121 | expect(res.body.length).to.equal(1) | |
4d5f8138 | 122 | |
f0f5567b | 123 | const video = res.body[0] |
9f10b292 C |
124 | expect(video.name).to.equal('my super name') |
125 | expect(video.description).to.equal('my super description') | |
126 | expect(video.podUrl).to.equal('http://localhost:9001') | |
6d8ada5f C |
127 | expect(video.author).to.equal('root') |
128 | expect(video.isLocal).to.be.true | |
4d5f8138 | 129 | |
9f10b292 | 130 | done() |
4d5f8138 | 131 | }) |
9f10b292 | 132 | }) |
4d5f8138 | 133 | |
9f10b292 | 134 | it('Should not find a search', function (done) { |
0c1cbbfe | 135 | utils.searchVideo(server.url, 'hello', function (err, res) { |
9f10b292 | 136 | if (err) throw err |
4d5f8138 | 137 | |
9f10b292 C |
138 | expect(res.body).to.be.an('array') |
139 | expect(res.body.length).to.equal(0) | |
4d5f8138 | 140 | |
9f10b292 | 141 | done() |
4d5f8138 | 142 | }) |
9f10b292 | 143 | }) |
4d5f8138 | 144 | |
9f10b292 | 145 | it('Should remove the video', function (done) { |
0c1cbbfe | 146 | utils.removeVideo(server.url, server.access_token, video_id, function (err) { |
9f10b292 | 147 | if (err) throw err |
f5a60a51 | 148 | |
3d446a26 | 149 | fs.readdir(pathUtils.join(__dirname, '../../../test1/uploads/'), function (err, files) { |
9f10b292 | 150 | if (err) throw err |
f5a60a51 | 151 | |
9f10b292 C |
152 | expect(files.length).to.equal(0) |
153 | done() | |
876d1bcf | 154 | }) |
8c308c2b | 155 | }) |
9f10b292 | 156 | }) |
8c308c2b | 157 | |
9f10b292 | 158 | it('Should not have videos', function (done) { |
0c1cbbfe | 159 | utils.getVideosList(server.url, function (err, res) { |
9f10b292 | 160 | if (err) throw err |
8c308c2b | 161 | |
9f10b292 C |
162 | expect(res.body).to.be.an('array') |
163 | expect(res.body.length).to.equal(0) | |
8c308c2b | 164 | |
9f10b292 | 165 | done() |
8c308c2b | 166 | }) |
9f10b292 | 167 | }) |
8c308c2b | 168 | |
3a8a8b51 C |
169 | it('Should upload 6 videos', function (done) { |
170 | this.timeout(25000) | |
171 | const videos = [ | |
172 | 'video_short.mp4', 'video_short.ogv', 'video_short.webm', | |
173 | 'video_short1.webm', 'video_short2.webm', 'video_short3.webm' | |
174 | ] | |
175 | async.each(videos, function (video, callback_each) { | |
176 | utils.uploadVideo(server.url, server.access_token, video + ' name', video + ' description', video, callback_each) | |
177 | }, done) | |
178 | }) | |
179 | ||
180 | it('Should have the correct durations', function (done) { | |
181 | utils.getVideosList(server.url, function (err, res) { | |
182 | if (err) throw err | |
183 | ||
184 | const videos = res.body | |
185 | expect(videos).to.be.an('array') | |
186 | expect(videos.length).to.equal(6) | |
187 | ||
188 | const videos_by_name = keyBy(videos, 'name') | |
189 | expect(videos_by_name['video_short.mp4 name'].duration).to.equal(5) | |
190 | expect(videos_by_name['video_short.ogv name'].duration).to.equal(5) | |
191 | expect(videos_by_name['video_short.webm name'].duration).to.equal(5) | |
192 | expect(videos_by_name['video_short1.webm name'].duration).to.equal(10) | |
193 | expect(videos_by_name['video_short2.webm name'].duration).to.equal(5) | |
194 | expect(videos_by_name['video_short3.webm name'].duration).to.equal(5) | |
195 | ||
196 | done() | |
197 | }) | |
198 | }) | |
199 | ||
9f10b292 | 200 | after(function (done) { |
0c1cbbfe | 201 | process.kill(-server.app.pid) |
9f10b292 | 202 | process.kill(-webtorrent.app.pid) |
8c308c2b | 203 | |
9f10b292 C |
204 | // Keep the logs if the test failed |
205 | if (this.ok) { | |
206 | utils.flushTests(done) | |
207 | } else { | |
208 | done() | |
209 | } | |
8c308c2b | 210 | }) |
9f10b292 | 211 | }) |