3 var async = require('async')
4 var chai = require('chai')
5 var expect = chai.expect
7 var pathUtils = require('path')
9 var webtorrent = require(pathUtils.join(__dirname, '../../lib/webtorrent'))
10 webtorrent.silent = true
12 var utils = require('./utils')
14 describe('Test a single pod', function () {
19 before(function (done) {
24 utils.flushTests(next)
27 utils.runServer(1, function (app1, url1) {
34 webtorrent.create({ host: 'client', port: '1' }, next)
39 it('Should not have videos', function (done) {
40 utils.getVideosList(url, function (err, res) {
43 expect(res.body).to.be.an('array')
44 expect(res.body.length).to.equal(0)
50 it('Should upload the video', function (done) {
52 utils.uploadVideo(url, 'my super name', 'my super description', 'video_short.webm', done)
55 it('Should seed the uploaded video', function (done) {
56 // Yes, this could be long
59 utils.getVideosList(url, function (err, res) {
62 expect(res.body).to.be.an('array')
63 expect(res.body.length).to.equal(1)
65 var video = res.body[0]
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
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('')
83 it('Should search the video', function (done) {
84 utils.searchVideo(url, 'my', function (err, res) {
87 expect(res.body).to.be.an('array')
88 expect(res.body.length).to.equal(1)
90 var video = res.body[0]
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
100 it('Should not find a search', function (done) {
101 utils.searchVideo(url, 'hello', function (err, res) {
104 expect(res.body).to.be.an('array')
105 expect(res.body.length).to.equal(0)
111 it('Should remove the video', function (done) {
112 utils.removeVideo(url, video_id, function (err) {
115 fs.readdir(pathUtils.join(__dirname, '../../test1/uploads/'), function (err, files) {
118 expect(files.length).to.equal(0)
124 it('Should not have videos', function (done) {
125 utils.getVideosList(url, function (err, res) {
128 expect(res.body).to.be.an('array')
129 expect(res.body.length).to.equal(0)
135 after(function (done) {
136 process.kill(-app.pid)
137 process.kill(-webtorrent.app.pid)
139 // Keep the logs if the test failed
141 utils.flushTests(done)