]>
Commit | Line | Data |
---|---|---|
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 | expect(video.author).to.equal('root') | |
76 | expect(video.isLocal).to.be.true | |
77 | ||
78 | video_id = video.id | |
79 | ||
80 | webtorrent.add(video.magnetUri, function (torrent) { | |
81 | expect(torrent.files).to.exist | |
82 | expect(torrent.files.length).to.equal(1) | |
83 | expect(torrent.files[0].path).to.exist.and.to.not.equal('') | |
84 | ||
85 | done() | |
86 | }) | |
87 | }) | |
88 | }) | |
89 | ||
90 | it('Should get the video', function (done) { | |
91 | // Yes, this could be long | |
92 | this.timeout(60000) | |
93 | ||
94 | utils.getVideo(server.url, video_id, function (err, res) { | |
95 | if (err) throw err | |
96 | ||
97 | const video = res.body | |
98 | expect(video.name).to.equal('my super name') | |
99 | expect(video.description).to.equal('my super description') | |
100 | expect(video.podUrl).to.equal('http://localhost:9001') | |
101 | expect(video.magnetUri).to.exist | |
102 | expect(video.author).to.equal('root') | |
103 | expect(video.isLocal).to.be.true | |
104 | ||
105 | webtorrent.add(video.magnetUri, function (torrent) { | |
106 | expect(torrent.files).to.exist | |
107 | expect(torrent.files.length).to.equal(1) | |
108 | expect(torrent.files[0].path).to.exist.and.to.not.equal('') | |
109 | ||
110 | done() | |
111 | }) | |
112 | }) | |
113 | }) | |
114 | ||
115 | it('Should search the video', function (done) { | |
116 | utils.searchVideo(server.url, 'my', function (err, res) { | |
117 | if (err) throw err | |
118 | ||
119 | expect(res.body).to.be.an('array') | |
120 | expect(res.body.length).to.equal(1) | |
121 | ||
122 | const video = res.body[0] | |
123 | expect(video.name).to.equal('my super name') | |
124 | expect(video.description).to.equal('my super description') | |
125 | expect(video.podUrl).to.equal('http://localhost:9001') | |
126 | expect(video.author).to.equal('root') | |
127 | expect(video.isLocal).to.be.true | |
128 | ||
129 | done() | |
130 | }) | |
131 | }) | |
132 | ||
133 | it('Should not find a search', function (done) { | |
134 | utils.searchVideo(server.url, 'hello', function (err, res) { | |
135 | if (err) throw err | |
136 | ||
137 | expect(res.body).to.be.an('array') | |
138 | expect(res.body.length).to.equal(0) | |
139 | ||
140 | done() | |
141 | }) | |
142 | }) | |
143 | ||
144 | it('Should remove the video', function (done) { | |
145 | utils.removeVideo(server.url, server.access_token, video_id, function (err) { | |
146 | if (err) throw err | |
147 | ||
148 | fs.readdir(pathUtils.join(__dirname, '../../../test1/uploads/'), function (err, files) { | |
149 | if (err) throw err | |
150 | ||
151 | expect(files.length).to.equal(0) | |
152 | done() | |
153 | }) | |
154 | }) | |
155 | }) | |
156 | ||
157 | it('Should not have videos', function (done) { | |
158 | utils.getVideosList(server.url, function (err, res) { | |
159 | if (err) throw err | |
160 | ||
161 | expect(res.body).to.be.an('array') | |
162 | expect(res.body.length).to.equal(0) | |
163 | ||
164 | done() | |
165 | }) | |
166 | }) | |
167 | ||
168 | after(function (done) { | |
169 | process.kill(-server.app.pid) | |
170 | process.kill(-webtorrent.app.pid) | |
171 | ||
172 | // Keep the logs if the test failed | |
173 | if (this.ok) { | |
174 | utils.flushTests(done) | |
175 | } else { | |
176 | done() | |
177 | } | |
178 | }) | |
179 | }) |