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