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