diff options
Diffstat (limited to 'tests/api/singlePod.js')
-rw-r--r-- | tests/api/singlePod.js | 224 |
1 files changed, 111 insertions, 113 deletions
diff --git a/tests/api/singlePod.js b/tests/api/singlePod.js index f33aa8c7a..3dd72c01b 100644 --- a/tests/api/singlePod.js +++ b/tests/api/singlePod.js | |||
@@ -1,148 +1,146 @@ | |||
1 | ;(function () { | 1 | 'use strict' |
2 | 'use strict' | 2 | |
3 | 3 | var async = require('async') | |
4 | var async = require('async') | 4 | var chai = require('chai') |
5 | var chai = require('chai') | 5 | var expect = chai.expect |
6 | var expect = chai.expect | 6 | var fs = require('fs') |
7 | var fs = require('fs') | 7 | var pathUtils = require('path') |
8 | var pathUtils = require('path') | 8 | |
9 | 9 | var webtorrent = require(pathUtils.join(__dirname, '../../lib/webtorrent')) | |
10 | var webtorrent = require(pathUtils.join(__dirname, '../../lib/webtorrent')) | 10 | webtorrent.silent = true |
11 | webtorrent.silent = true | 11 | |
12 | 12 | var utils = require('./utils') | |
13 | var utils = require('./utils') | 13 | |
14 | 14 | describe('Test a single pod', function () { | |
15 | describe('Test a single pod', function () { | 15 | var app = null |
16 | var app = null | 16 | var url = '' |
17 | var url = '' | 17 | var video_id = -1 |
18 | var video_id = -1 | 18 | |
19 | 19 | before(function (done) { | |
20 | before(function (done) { | 20 | this.timeout(20000) |
21 | this.timeout(20000) | 21 | |
22 | 22 | async.series([ | |
23 | async.series([ | 23 | function (next) { |
24 | function (next) { | 24 | utils.flushTests(next) |
25 | utils.flushTests(next) | 25 | }, |
26 | }, | 26 | function (next) { |
27 | function (next) { | 27 | utils.runServer(1, function (app1, url1) { |
28 | utils.runServer(1, function (app1, url1) { | 28 | app = app1 |
29 | app = app1 | 29 | url = url1 |
30 | url = url1 | 30 | next() |
31 | next() | 31 | }) |
32 | }) | 32 | }, |
33 | }, | 33 | function (next) { |
34 | function (next) { | 34 | webtorrent.create({ host: 'client', port: '1' }, next) |
35 | webtorrent.create({ host: 'client', port: '1' }, next) | 35 | } |
36 | } | 36 | ], done) |
37 | ], done) | 37 | }) |
38 | }) | ||
39 | 38 | ||
40 | it('Should not have videos', function (done) { | 39 | it('Should not have videos', function (done) { |
41 | utils.getVideosList(url, function (err, res) { | 40 | utils.getVideosList(url, function (err, res) { |
42 | if (err) throw err | 41 | if (err) throw err |
43 | 42 | ||
44 | expect(res.body).to.be.an('array') | 43 | expect(res.body).to.be.an('array') |
45 | expect(res.body.length).to.equal(0) | 44 | expect(res.body.length).to.equal(0) |
46 | 45 | ||
47 | done() | 46 | done() |
48 | }) | ||
49 | }) | 47 | }) |
48 | }) | ||
50 | 49 | ||
51 | it('Should upload the video', function (done) { | 50 | it('Should upload the video', function (done) { |
52 | this.timeout(5000) | 51 | this.timeout(5000) |
53 | utils.uploadVideo(url, 'my super name', 'my super description', 'video_short.webm', done) | 52 | utils.uploadVideo(url, 'my super name', 'my super description', 'video_short.webm', done) |
54 | }) | 53 | }) |
55 | 54 | ||
56 | it('Should seed the uploaded video', function (done) { | 55 | it('Should seed the uploaded video', function (done) { |
57 | // Yes, this could be long | 56 | // Yes, this could be long |
58 | this.timeout(60000) | 57 | this.timeout(60000) |
59 | 58 | ||
60 | utils.getVideosList(url, function (err, res) { | 59 | utils.getVideosList(url, function (err, res) { |
61 | if (err) throw err | 60 | if (err) throw err |
62 | 61 | ||
63 | expect(res.body).to.be.an('array') | 62 | expect(res.body).to.be.an('array') |
64 | expect(res.body.length).to.equal(1) | 63 | expect(res.body.length).to.equal(1) |
65 | 64 | ||
66 | var video = res.body[0] | 65 | var video = res.body[0] |
67 | expect(video.name).to.equal('my super name') | 66 | expect(video.name).to.equal('my super name') |
68 | expect(video.description).to.equal('my super description') | 67 | expect(video.description).to.equal('my super description') |
69 | expect(video.podUrl).to.equal('http://localhost:9001') | 68 | expect(video.podUrl).to.equal('http://localhost:9001') |
70 | expect(video.magnetUri).to.exist | 69 | expect(video.magnetUri).to.exist |
71 | 70 | ||
72 | video_id = video._id | 71 | video_id = video._id |
73 | 72 | ||
74 | webtorrent.add(video.magnetUri, function (torrent) { | 73 | webtorrent.add(video.magnetUri, function (torrent) { |
75 | expect(torrent.files).to.exist | 74 | expect(torrent.files).to.exist |
76 | expect(torrent.files.length).to.equal(1) | 75 | expect(torrent.files.length).to.equal(1) |
77 | expect(torrent.files[0].path).to.exist.and.to.not.equal('') | 76 | expect(torrent.files[0].path).to.exist.and.to.not.equal('') |
78 | 77 | ||
79 | done() | 78 | done() |
80 | }) | ||
81 | }) | 79 | }) |
82 | }) | 80 | }) |
81 | }) | ||
83 | 82 | ||
84 | it('Should search the video', function (done) { | 83 | it('Should search the video', function (done) { |
85 | utils.searchVideo(url, 'my', function (err, res) { | 84 | utils.searchVideo(url, 'my', function (err, res) { |
86 | if (err) throw err | 85 | if (err) throw err |
87 | 86 | ||
88 | expect(res.body).to.be.an('array') | 87 | expect(res.body).to.be.an('array') |
89 | expect(res.body.length).to.equal(1) | 88 | expect(res.body.length).to.equal(1) |
90 | 89 | ||
91 | var video = res.body[0] | 90 | var video = res.body[0] |
92 | expect(video.name).to.equal('my super name') | 91 | expect(video.name).to.equal('my super name') |
93 | expect(video.description).to.equal('my super description') | 92 | expect(video.description).to.equal('my super description') |
94 | expect(video.podUrl).to.equal('http://localhost:9001') | 93 | expect(video.podUrl).to.equal('http://localhost:9001') |
95 | expect(video.magnetUri).to.exist | 94 | expect(video.magnetUri).to.exist |
96 | 95 | ||
97 | done() | 96 | done() |
98 | }) | ||
99 | }) | 97 | }) |
98 | }) | ||
100 | 99 | ||
101 | it('Should not find a search', function (done) { | 100 | it('Should not find a search', function (done) { |
102 | utils.searchVideo(url, 'hello', function (err, res) { | 101 | utils.searchVideo(url, 'hello', function (err, res) { |
103 | if (err) throw err | 102 | if (err) throw err |
104 | 103 | ||
105 | expect(res.body).to.be.an('array') | 104 | expect(res.body).to.be.an('array') |
106 | expect(res.body.length).to.equal(0) | 105 | expect(res.body.length).to.equal(0) |
107 | 106 | ||
108 | done() | 107 | done() |
109 | }) | ||
110 | }) | 108 | }) |
109 | }) | ||
111 | 110 | ||
112 | it('Should remove the video', function (done) { | 111 | it('Should remove the video', function (done) { |
113 | utils.removeVideo(url, video_id, function (err) { | 112 | utils.removeVideo(url, video_id, function (err) { |
114 | if (err) throw err | 113 | if (err) throw err |
115 | 114 | ||
116 | fs.readdir(pathUtils.join(__dirname, '../../test1/uploads/'), function (err, files) { | 115 | fs.readdir(pathUtils.join(__dirname, '../../test1/uploads/'), function (err, files) { |
117 | if (err) throw err | 116 | if (err) throw err |
118 | 117 | ||
119 | expect(files.length).to.equal(0) | 118 | expect(files.length).to.equal(0) |
120 | done() | 119 | done() |
121 | }) | ||
122 | }) | 120 | }) |
123 | }) | 121 | }) |
122 | }) | ||
124 | 123 | ||
125 | it('Should not have videos', function (done) { | 124 | it('Should not have videos', function (done) { |
126 | utils.getVideosList(url, function (err, res) { | 125 | utils.getVideosList(url, function (err, res) { |
127 | if (err) throw err | 126 | if (err) throw err |
128 | 127 | ||
129 | expect(res.body).to.be.an('array') | 128 | expect(res.body).to.be.an('array') |
130 | expect(res.body.length).to.equal(0) | 129 | expect(res.body.length).to.equal(0) |
131 | 130 | ||
132 | done() | 131 | done() |
133 | }) | ||
134 | }) | 132 | }) |
133 | }) | ||
135 | 134 | ||
136 | after(function (done) { | 135 | after(function (done) { |
137 | process.kill(-app.pid) | 136 | process.kill(-app.pid) |
138 | process.kill(-webtorrent.app.pid) | 137 | process.kill(-webtorrent.app.pid) |
139 | 138 | ||
140 | // Keep the logs if the test failed | 139 | // Keep the logs if the test failed |
141 | if (this.ok) { | 140 | if (this.ok) { |
142 | utils.flushTests(done) | 141 | utils.flushTests(done) |
143 | } else { | 142 | } else { |
144 | done() | 143 | done() |
145 | } | 144 | } |
146 | }) | ||
147 | }) | 145 | }) |
148 | })() | 146 | }) |