]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - test/api/singlePod.js
Add API versionning
[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 fs = require('fs')
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 () {
14 var path = '/api/v1/videos'
15 var app = null
16 var url = ''
17 var video_id = -1
18
19 before(function (done) {
20 this.timeout(20000)
21
22 utils.flushTests(function () {
23 utils.runServer(1, function (app1, url1) {
24 app = app1
25 url = url1
26
27 webtorrent.create({ host: 'client', port: '1' }, function () {
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
95 it('Should remove the video', function (done) {
96 request(url)
97 .delete(path + '/' + video_id)
98 .set('Accept', 'application/json')
99 .expect(204)
100 .end(function (err, res) {
101 if (err) throw err
102
103 fs.readdir(__dirname + '/../../test1/uploads/', function (err, files) {
104 if (err) throw err
105
106 expect(files.length).to.equal(0)
107 done()
108 })
109 })
110 })
111
112 it('Should not have videos', function (done) {
113 request(url)
114 .get(path)
115 .set('Accept', 'application/json')
116 .expect(200)
117 .expect('Content-Type', /json/)
118 .end(function (err, res) {
119 if (err) throw err
120
121 expect(res.body).to.be.an('array')
122 expect(res.body.length).to.equal(0)
123
124 done()
125 })
126 })
127
128 after(function (done) {
129 process.kill(-app.pid)
130 process.kill(-webtorrent.app.pid)
131
132 // Keep the logs if the test failed
133 if (this.ok) {
134 utils.flushTests(function () {
135 done()
136 })
137 } else {
138 done()
139 }
140 })
141 })
142 })()