]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/singlePod.js
Change api output for videos
[github/Chocobozzz/PeerTube.git] / server / tests / api / singlePod.js
1 'use strict'
2
3 const async = require('async')
4 const chai = require('chai')
5 const expect = chai.expect
6 const fs = require('fs')
7 const pathUtils = require('path')
8
9 const webtorrent = require(pathUtils.join(__dirname, '../../lib/webtorrent'))
10 webtorrent.silent = true
11
12 const utils = require('./utils')
13
14 describe('Test a single pod', function () {
15 let app = null
16 let url = ''
17 let video_id = -1
18
19 before(function (done) {
20 this.timeout(20000)
21
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()
31 })
32 },
33 function (next) {
34 webtorrent.create({ host: 'client', port: '1' }, next)
35 }
36 ], done)
37 })
38
39 it('Should not have videos', function (done) {
40 utils.getVideosList(url, function (err, res) {
41 if (err) throw err
42
43 expect(res.body).to.be.an('array')
44 expect(res.body.length).to.equal(0)
45
46 done()
47 })
48 })
49
50 it('Should upload the video', function (done) {
51 this.timeout(5000)
52 utils.uploadVideo(url, 'my super name', 'my super description', 'video_short.webm', done)
53 })
54
55 it('Should seed the uploaded video', function (done) {
56 // Yes, this could be long
57 this.timeout(60000)
58
59 utils.getVideosList(url, function (err, res) {
60 if (err) throw err
61
62 expect(res.body).to.be.an('array')
63 expect(res.body.length).to.equal(1)
64
65 const 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
70
71 video_id = video.id
72
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('')
77
78 done()
79 })
80 })
81 })
82
83 it('Should get the video', function (done) {
84 // Yes, this could be long
85 this.timeout(60000)
86
87 utils.getVideo(url, video_id, function (err, res) {
88 if (err) throw err
89
90 const video = res.body
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
95
96 webtorrent.add(video.magnetUri, function (torrent) {
97 expect(torrent.files).to.exist
98 expect(torrent.files.length).to.equal(1)
99 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
100
101 done()
102 })
103 })
104 })
105
106 it('Should search the video', function (done) {
107 utils.searchVideo(url, 'my', function (err, res) {
108 if (err) throw err
109
110 expect(res.body).to.be.an('array')
111 expect(res.body.length).to.equal(1)
112
113 const video = res.body[0]
114 expect(video.name).to.equal('my super name')
115 expect(video.description).to.equal('my super description')
116 expect(video.podUrl).to.equal('http://localhost:9001')
117
118 done()
119 })
120 })
121
122 it('Should not find a search', function (done) {
123 utils.searchVideo(url, 'hello', function (err, res) {
124 if (err) throw err
125
126 expect(res.body).to.be.an('array')
127 expect(res.body.length).to.equal(0)
128
129 done()
130 })
131 })
132
133 it('Should remove the video', function (done) {
134 utils.removeVideo(url, video_id, function (err) {
135 if (err) throw err
136
137 fs.readdir(pathUtils.join(__dirname, '../../../test1/uploads/'), function (err, files) {
138 if (err) throw err
139
140 expect(files.length).to.equal(0)
141 done()
142 })
143 })
144 })
145
146 it('Should not have videos', function (done) {
147 utils.getVideosList(url, function (err, res) {
148 if (err) throw err
149
150 expect(res.body).to.be.an('array')
151 expect(res.body.length).to.equal(0)
152
153 done()
154 })
155 })
156
157 after(function (done) {
158 process.kill(-app.pid)
159 process.kill(-webtorrent.app.pid)
160
161 // Keep the logs if the test failed
162 if (this.ok) {
163 utils.flushTests(done)
164 } else {
165 done()
166 }
167 })
168 })