]>
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') | |
7 | const pathUtils = require('path') | |
9f10b292 | 8 | |
f0f5567b | 9 | const webtorrent = require(pathUtils.join(__dirname, '../../lib/webtorrent')) |
9f10b292 C |
10 | webtorrent.silent = true |
11 | ||
f0f5567b | 12 | const utils = require('./utils') |
9f10b292 C |
13 | |
14 | describe('Test a single pod', function () { | |
0c1cbbfe | 15 | let server = null |
f0f5567b | 16 | let video_id = -1 |
9f10b292 C |
17 | |
18 | before(function (done) { | |
19 | this.timeout(20000) | |
20 | ||
21 | async.series([ | |
22 | function (next) { | |
23 | utils.flushTests(next) | |
24 | }, | |
25 | function (next) { | |
0c1cbbfe C |
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 | |
9f10b292 C |
35 | next() |
36 | }) | |
37 | }, | |
38 | function (next) { | |
39 | webtorrent.create({ host: 'client', port: '1' }, next) | |
40 | } | |
41 | ], done) | |
42 | }) | |
8c308c2b | 43 | |
9f10b292 | 44 | it('Should not have videos', function (done) { |
0c1cbbfe | 45 | utils.getVideosList(server.url, function (err, res) { |
9f10b292 | 46 | if (err) throw err |
8c308c2b | 47 | |
9f10b292 C |
48 | expect(res.body).to.be.an('array') |
49 | expect(res.body.length).to.equal(0) | |
8c308c2b | 50 | |
9f10b292 | 51 | done() |
8c308c2b | 52 | }) |
9f10b292 | 53 | }) |
8c308c2b | 54 | |
9f10b292 C |
55 | it('Should upload the video', function (done) { |
56 | this.timeout(5000) | |
0c1cbbfe | 57 | utils.uploadVideo(server.url, server.access_token, 'my super name', 'my super description', 'video_short.webm', done) |
9f10b292 | 58 | }) |
8c308c2b | 59 | |
9f10b292 C |
60 | it('Should seed the uploaded video', function (done) { |
61 | // Yes, this could be long | |
62 | this.timeout(60000) | |
8c308c2b | 63 | |
0c1cbbfe | 64 | utils.getVideosList(server.url, function (err, res) { |
9f10b292 | 65 | if (err) throw err |
8c308c2b | 66 | |
9f10b292 C |
67 | expect(res.body).to.be.an('array') |
68 | expect(res.body.length).to.equal(1) | |
8c308c2b | 69 | |
f0f5567b | 70 | const video = res.body[0] |
9f10b292 C |
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 | |
6d8ada5f C |
75 | expect(video.author).to.equal('root') |
76 | expect(video.isLocal).to.be.true | |
8c308c2b | 77 | |
2df82d42 C |
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 | ||
0c1cbbfe | 94 | utils.getVideo(server.url, video_id, function (err, res) { |
2df82d42 C |
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 | |
6d8ada5f C |
102 | expect(video.author).to.equal('root') |
103 | expect(video.isLocal).to.be.true | |
8c308c2b | 104 | |
9f10b292 C |
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('') | |
8c308c2b | 109 | |
9f10b292 | 110 | done() |
876d1bcf | 111 | }) |
8c308c2b | 112 | }) |
9f10b292 | 113 | }) |
8c308c2b | 114 | |
9f10b292 | 115 | it('Should search the video', function (done) { |
0c1cbbfe | 116 | utils.searchVideo(server.url, 'my', function (err, res) { |
9f10b292 | 117 | if (err) throw err |
4d5f8138 | 118 | |
9f10b292 C |
119 | expect(res.body).to.be.an('array') |
120 | expect(res.body.length).to.equal(1) | |
4d5f8138 | 121 | |
f0f5567b | 122 | const video = res.body[0] |
9f10b292 C |
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') | |
6d8ada5f C |
126 | expect(video.author).to.equal('root') |
127 | expect(video.isLocal).to.be.true | |
4d5f8138 | 128 | |
9f10b292 | 129 | done() |
4d5f8138 | 130 | }) |
9f10b292 | 131 | }) |
4d5f8138 | 132 | |
9f10b292 | 133 | it('Should not find a search', function (done) { |
0c1cbbfe | 134 | utils.searchVideo(server.url, 'hello', function (err, res) { |
9f10b292 | 135 | if (err) throw err |
4d5f8138 | 136 | |
9f10b292 C |
137 | expect(res.body).to.be.an('array') |
138 | expect(res.body.length).to.equal(0) | |
4d5f8138 | 139 | |
9f10b292 | 140 | done() |
4d5f8138 | 141 | }) |
9f10b292 | 142 | }) |
4d5f8138 | 143 | |
9f10b292 | 144 | it('Should remove the video', function (done) { |
0c1cbbfe | 145 | utils.removeVideo(server.url, server.access_token, video_id, function (err) { |
9f10b292 | 146 | if (err) throw err |
f5a60a51 | 147 | |
3d446a26 | 148 | fs.readdir(pathUtils.join(__dirname, '../../../test1/uploads/'), function (err, files) { |
9f10b292 | 149 | if (err) throw err |
f5a60a51 | 150 | |
9f10b292 C |
151 | expect(files.length).to.equal(0) |
152 | done() | |
876d1bcf | 153 | }) |
8c308c2b | 154 | }) |
9f10b292 | 155 | }) |
8c308c2b | 156 | |
9f10b292 | 157 | it('Should not have videos', function (done) { |
0c1cbbfe | 158 | utils.getVideosList(server.url, function (err, res) { |
9f10b292 | 159 | if (err) throw err |
8c308c2b | 160 | |
9f10b292 C |
161 | expect(res.body).to.be.an('array') |
162 | expect(res.body.length).to.equal(0) | |
8c308c2b | 163 | |
9f10b292 | 164 | done() |
8c308c2b | 165 | }) |
9f10b292 | 166 | }) |
8c308c2b | 167 | |
9f10b292 | 168 | after(function (done) { |
0c1cbbfe | 169 | process.kill(-server.app.pid) |
9f10b292 | 170 | process.kill(-webtorrent.app.pid) |
8c308c2b | 171 | |
9f10b292 C |
172 | // Keep the logs if the test failed |
173 | if (this.ok) { | |
174 | utils.flushTests(done) | |
175 | } else { | |
176 | done() | |
177 | } | |
8c308c2b | 178 | }) |
9f10b292 | 179 | }) |