]>
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 () { | |
f0f5567b C |
15 | let app = null |
16 | let url = '' | |
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) { | |
27 | utils.runServer(1, function (app1, url1) { | |
28 | app = app1 | |
29 | url = url1 | |
30 | next() | |
31 | }) | |
32 | }, | |
33 | function (next) { | |
34 | webtorrent.create({ host: 'client', port: '1' }, next) | |
35 | } | |
36 | ], done) | |
37 | }) | |
8c308c2b | 38 | |
9f10b292 C |
39 | it('Should not have videos', function (done) { |
40 | utils.getVideosList(url, function (err, res) { | |
41 | if (err) throw err | |
8c308c2b | 42 | |
9f10b292 C |
43 | expect(res.body).to.be.an('array') |
44 | expect(res.body.length).to.equal(0) | |
8c308c2b | 45 | |
9f10b292 | 46 | done() |
8c308c2b | 47 | }) |
9f10b292 | 48 | }) |
8c308c2b | 49 | |
9f10b292 C |
50 | it('Should upload the video', function (done) { |
51 | this.timeout(5000) | |
52 | utils.uploadVideo(url, 'my super name', 'my super description', 'video_short.webm', done) | |
53 | }) | |
8c308c2b | 54 | |
9f10b292 C |
55 | it('Should seed the uploaded video', function (done) { |
56 | // Yes, this could be long | |
57 | this.timeout(60000) | |
8c308c2b | 58 | |
9f10b292 C |
59 | utils.getVideosList(url, function (err, res) { |
60 | if (err) throw err | |
8c308c2b | 61 | |
9f10b292 C |
62 | expect(res.body).to.be.an('array') |
63 | expect(res.body.length).to.equal(1) | |
8c308c2b | 64 | |
f0f5567b | 65 | const video = res.body[0] |
9f10b292 C |
66 | expect(video.name).to.equal('my super name') |
67 | expect(video.description).to.equal('my super description') | |
68 | expect(video.podUrl).to.equal('http://localhost:9001') | |
69 | expect(video.magnetUri).to.exist | |
8c308c2b | 70 | |
9f10b292 | 71 | video_id = video._id |
8c308c2b | 72 | |
9f10b292 C |
73 | webtorrent.add(video.magnetUri, function (torrent) { |
74 | expect(torrent.files).to.exist | |
75 | expect(torrent.files.length).to.equal(1) | |
76 | expect(torrent.files[0].path).to.exist.and.to.not.equal('') | |
8c308c2b | 77 | |
9f10b292 | 78 | done() |
876d1bcf | 79 | }) |
8c308c2b | 80 | }) |
9f10b292 | 81 | }) |
8c308c2b | 82 | |
9f10b292 C |
83 | it('Should search the video', function (done) { |
84 | utils.searchVideo(url, 'my', function (err, res) { | |
85 | if (err) throw err | |
4d5f8138 | 86 | |
9f10b292 C |
87 | expect(res.body).to.be.an('array') |
88 | expect(res.body.length).to.equal(1) | |
4d5f8138 | 89 | |
f0f5567b | 90 | const video = res.body[0] |
9f10b292 C |
91 | expect(video.name).to.equal('my super name') |
92 | expect(video.description).to.equal('my super description') | |
93 | expect(video.podUrl).to.equal('http://localhost:9001') | |
94 | expect(video.magnetUri).to.exist | |
4d5f8138 | 95 | |
9f10b292 | 96 | done() |
4d5f8138 | 97 | }) |
9f10b292 | 98 | }) |
4d5f8138 | 99 | |
9f10b292 C |
100 | it('Should not find a search', function (done) { |
101 | utils.searchVideo(url, 'hello', function (err, res) { | |
102 | if (err) throw err | |
4d5f8138 | 103 | |
9f10b292 C |
104 | expect(res.body).to.be.an('array') |
105 | expect(res.body.length).to.equal(0) | |
4d5f8138 | 106 | |
9f10b292 | 107 | done() |
4d5f8138 | 108 | }) |
9f10b292 | 109 | }) |
4d5f8138 | 110 | |
9f10b292 C |
111 | it('Should remove the video', function (done) { |
112 | utils.removeVideo(url, video_id, function (err) { | |
113 | if (err) throw err | |
f5a60a51 | 114 | |
3d446a26 | 115 | fs.readdir(pathUtils.join(__dirname, '../../../test1/uploads/'), function (err, files) { |
9f10b292 | 116 | if (err) throw err |
f5a60a51 | 117 | |
9f10b292 C |
118 | expect(files.length).to.equal(0) |
119 | done() | |
876d1bcf | 120 | }) |
8c308c2b | 121 | }) |
9f10b292 | 122 | }) |
8c308c2b | 123 | |
9f10b292 C |
124 | it('Should not have videos', function (done) { |
125 | utils.getVideosList(url, function (err, res) { | |
126 | if (err) throw err | |
8c308c2b | 127 | |
9f10b292 C |
128 | expect(res.body).to.be.an('array') |
129 | expect(res.body.length).to.equal(0) | |
8c308c2b | 130 | |
9f10b292 | 131 | done() |
8c308c2b | 132 | }) |
9f10b292 | 133 | }) |
8c308c2b | 134 | |
9f10b292 C |
135 | after(function (done) { |
136 | process.kill(-app.pid) | |
137 | process.kill(-webtorrent.app.pid) | |
8c308c2b | 138 | |
9f10b292 C |
139 | // Keep the logs if the test failed |
140 | if (this.ok) { | |
141 | utils.flushTests(done) | |
142 | } else { | |
143 | done() | |
144 | } | |
8c308c2b | 145 | }) |
9f10b292 | 146 | }) |