]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - tests/api/singlePod.js
Rename webtorrent files (process/node)
[github/Chocobozzz/PeerTube.git] / tests / api / singlePod.js
CommitLineData
8c308c2b
C
1;(function () {
2 'use strict'
3
ee66c593 4 var async = require('async')
8c308c2b
C
5 var chai = require('chai')
6 var expect = chai.expect
c45f7f84 7 var fs = require('fs')
876d1bcf 8
c5a8be2b 9 var webtorrent = require(__dirname + '/../../lib/webtorrent')
8c308c2b
C
10 webtorrent.silent = true
11
876d1bcf 12 var utils = require('./utils')
8c308c2b
C
13
14 describe('Test a single pod', function () {
8c308c2b
C
15 var app = null
16 var url = ''
17 var video_id = -1
18
19 before(function (done) {
ce5e7538 20 this.timeout(20000)
8c308c2b 21
ee66c593
C
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()
8c308c2b 31 })
ee66c593
C
32 },
33 function (next) {
34 webtorrent.create({ host: 'client', port: '1' }, next)
35 }
36 ], done)
8c308c2b
C
37 })
38
39 it('Should not have videos', function (done) {
876d1bcf
C
40 utils.getVideosList(url, function (err, res) {
41 if (err) throw err
8c308c2b 42
876d1bcf
C
43 expect(res.body).to.be.an('array')
44 expect(res.body.length).to.equal(0)
8c308c2b 45
876d1bcf
C
46 done()
47 })
8c308c2b
C
48 })
49
50 it('Should upload the video', function (done) {
51 this.timeout(5000)
876d1bcf 52 utils.uploadVideo(url, 'my super name', 'my super description', 'video_short.webm', done)
8c308c2b
C
53 })
54
55 it('Should seed the uploaded video', function (done) {
56 // Yes, this could be long
57 this.timeout(60000)
58
876d1bcf
C
59 utils.getVideosList(url, function (err, res) {
60 if (err) throw err
8c308c2b 61
876d1bcf
C
62 expect(res.body).to.be.an('array')
63 expect(res.body.length).to.equal(1)
8c308c2b 64
876d1bcf
C
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
8c308c2b 70
876d1bcf 71 video_id = video._id
8c308c2b 72
876d1bcf
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
876d1bcf 78 done()
8c308c2b 79 })
876d1bcf 80 })
8c308c2b
C
81 })
82
4d5f8138 83 it('Should search the video', function (done) {
876d1bcf
C
84 utils.searchVideo(url, 'my', function (err, res) {
85 if (err) throw err
4d5f8138 86
876d1bcf
C
87 expect(res.body).to.be.an('array')
88 expect(res.body.length).to.equal(1)
4d5f8138 89
876d1bcf
C
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
4d5f8138 95
876d1bcf
C
96 done()
97 })
4d5f8138
C
98 })
99
100 it('Should not find a search', function (done) {
876d1bcf
C
101 utils.searchVideo(url, 'hello', function (err, res) {
102 if (err) throw err
4d5f8138 103
876d1bcf
C
104 expect(res.body).to.be.an('array')
105 expect(res.body.length).to.equal(0)
4d5f8138 106
876d1bcf
C
107 done()
108 })
4d5f8138
C
109 })
110
8c308c2b 111 it('Should remove the video', function (done) {
876d1bcf
C
112 utils.removeVideo(url, video_id, function (err) {
113 if (err) throw err
f5a60a51 114
876d1bcf
C
115 fs.readdir(__dirname + '/../../test1/uploads/', function (err, files) {
116 if (err) throw err
f5a60a51 117
876d1bcf
C
118 expect(files.length).to.equal(0)
119 done()
8c308c2b 120 })
876d1bcf 121 })
8c308c2b
C
122 })
123
124 it('Should not have videos', function (done) {
876d1bcf
C
125 utils.getVideosList(url, function (err, res) {
126 if (err) throw err
8c308c2b 127
876d1bcf
C
128 expect(res.body).to.be.an('array')
129 expect(res.body.length).to.equal(0)
8c308c2b 130
876d1bcf
C
131 done()
132 })
8c308c2b
C
133 })
134
135 after(function (done) {
136 process.kill(-app.pid)
137 process.kill(-webtorrent.app.pid)
138
139 // Keep the logs if the test failed
140 if (this.ok) {
ee66c593 141 utils.flushTests(done)
8c308c2b
C
142 } else {
143 done()
144 }
145 })
146 })
147})()