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