]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - test/api/singlePod.js
Add tests for searching a video
[github/Chocobozzz/PeerTube.git] / test / api / singlePod.js
CommitLineData
8c308c2b
C
1;(function () {
2 'use strict'
3
4 var request = require('supertest')
5 var chai = require('chai')
f5a60a51 6 var fs = require('fs')
8c308c2b
C
7 var expect = chai.expect
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 () {
f5a60a51 14 var path = '/api/v1/videos'
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
C
21
22 utils.flushTests(function () {
23 utils.runServer(1, function (app1, url1) {
24 app = app1
25 url = url1
26
77c2df95 27 webtorrent.create({ host: 'client', port: '1' }, function () {
8c308c2b
C
28 done()
29 })
30 })
31 })
32 })
33
34 it('Should not have videos', function (done) {
35 request(url)
36 .get(path)
37 .set('Accept', 'application/json')
38 .expect(200)
39 .expect('Content-Type', /json/)
40 .end(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
53 request(url)
54 .post(path)
55 .set('Accept', 'application/json')
56 .field('name', 'my super name')
57 .field('description', 'my super description')
58 .attach('input_video', __dirname + '/../fixtures/video_short.webm')
59 .expect(201, done)
60 })
61
62 it('Should seed the uploaded video', function (done) {
63 // Yes, this could be long
64 this.timeout(60000)
65
66 request(url)
67 .get(path)
68 .set('Accept', 'application/json')
69 .expect(200)
70 .expect('Content-Type', /json/)
71 .end(function (err, res) {
72 if (err) throw err
73
74 expect(res.body).to.be.an('array')
75 expect(res.body.length).to.equal(1)
76
77 var video = res.body[0]
78 expect(video.name).to.equal('my super name')
79 expect(video.description).to.equal('my super description')
80 expect(video.podUrl).to.equal('http://localhost:9001')
81 expect(video.magnetUri).to.exist
82
83 video_id = video._id
84
85 webtorrent.add(video.magnetUri, function (torrent) {
86 expect(torrent.files).to.exist
87 expect(torrent.files.length).to.equal(1)
88 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
89
90 done()
91 })
92 })
93 })
94
4d5f8138
C
95 it('Should search the video', function (done) {
96 request(url)
97 .get(path + '/search/my')
98 .set('Accept', 'application/json')
99 .expect(200)
100 .expect('Content-Type', /json/)
101 .end(function (err, res) {
102 if (err) throw err
103
104 expect(res.body).to.be.an('array')
105 expect(res.body.length).to.equal(1)
106
107 var video = res.body[0]
108 expect(video.name).to.equal('my super name')
109 expect(video.description).to.equal('my super description')
110 expect(video.podUrl).to.equal('http://localhost:9001')
111 expect(video.magnetUri).to.exist
112
113 done()
114 })
115 })
116
117 it('Should not find a search', function (done) {
118 request(url)
119 .get(path + '/search/hello')
120 .set('Accept', 'application/json')
121 .expect(200)
122 .expect('Content-Type', /json/)
123 .end(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
8c308c2b
C
133 it('Should remove the video', function (done) {
134 request(url)
135 .delete(path + '/' + video_id)
136 .set('Accept', 'application/json')
137 .expect(204)
138 .end(function (err, res) {
139 if (err) throw err
f5a60a51
C
140
141 fs.readdir(__dirname + '/../../test1/uploads/', function (err, files) {
142 if (err) throw err
143
144 expect(files.length).to.equal(0)
145 done()
146 })
8c308c2b
C
147 })
148 })
149
150 it('Should not have videos', function (done) {
151 request(url)
152 .get(path)
153 .set('Accept', 'application/json')
154 .expect(200)
155 .expect('Content-Type', /json/)
156 .end(function (err, res) {
157 if (err) throw err
158
159 expect(res.body).to.be.an('array')
160 expect(res.body.length).to.equal(0)
161
162 done()
163 })
164 })
165
166 after(function (done) {
167 process.kill(-app.pid)
168 process.kill(-webtorrent.app.pid)
169
170 // Keep the logs if the test failed
171 if (this.ok) {
172 utils.flushTests(function () {
173 done()
174 })
175 } else {
176 done()
177 }
178 })
179 })
180})()