]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - test/api/singlePod.js
Tests refractoring
[github/Chocobozzz/PeerTube.git] / test / api / singlePod.js
1 ;(function () {
2 'use strict'
3
4 var chai = require('chai')
5 var fs = require('fs')
6 var expect = chai.expect
7
8 var webtorrent = require(__dirname + '/../../src/webTorrentNode')
9 webtorrent.silent = true
10
11 var utils = require('./utils')
12
13 describe('Test a single pod', function () {
14 var app = null
15 var url = ''
16 var video_id = -1
17
18 before(function (done) {
19 this.timeout(20000)
20
21 utils.flushTests(function () {
22 utils.runServer(1, function (app1, url1) {
23 app = app1
24 url = url1
25
26 webtorrent.create({ host: 'client', port: '1' }, function () {
27 done()
28 })
29 })
30 })
31 })
32
33 it('Should not have videos', function (done) {
34 utils.getVideosList(url, function (err, res) {
35 if (err) throw err
36
37 expect(res.body).to.be.an('array')
38 expect(res.body.length).to.equal(0)
39
40 done()
41 })
42 })
43
44 it('Should upload the video', function (done) {
45 this.timeout(5000)
46 utils.uploadVideo(url, 'my super name', 'my super description', 'video_short.webm', done)
47 })
48
49 it('Should seed the uploaded video', function (done) {
50 // Yes, this could be long
51 this.timeout(60000)
52
53 utils.getVideosList(url, function (err, res) {
54 if (err) throw err
55
56 expect(res.body).to.be.an('array')
57 expect(res.body.length).to.equal(1)
58
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
64
65 video_id = video._id
66
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('')
71
72 done()
73 })
74 })
75 })
76
77 it('Should search the video', function (done) {
78 utils.searchVideo(url, 'my', function (err, res) {
79 if (err) throw err
80
81 expect(res.body).to.be.an('array')
82 expect(res.body.length).to.equal(1)
83
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
89
90 done()
91 })
92 })
93
94 it('Should not find a search', function (done) {
95 utils.searchVideo(url, 'hello', function (err, res) {
96 if (err) throw err
97
98 expect(res.body).to.be.an('array')
99 expect(res.body.length).to.equal(0)
100
101 done()
102 })
103 })
104
105 it('Should remove the video', function (done) {
106 utils.removeVideo(url, video_id, function (err) {
107 if (err) throw err
108
109 fs.readdir(__dirname + '/../../test1/uploads/', function (err, files) {
110 if (err) throw err
111
112 expect(files.length).to.equal(0)
113 done()
114 })
115 })
116 })
117
118 it('Should not have videos', function (done) {
119 utils.getVideosList(url, function (err, res) {
120 if (err) throw err
121
122 expect(res.body).to.be.an('array')
123 expect(res.body.length).to.equal(0)
124
125 done()
126 })
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 })()