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