diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2015-12-06 17:09:07 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2015-12-07 17:22:36 +0100 |
commit | 876d1bcfd07b14d47ba377474e3bb680872d1f7a (patch) | |
tree | 4400850a7e4e6b7140ef9cea289784eb21f972b3 /test/api/singlePod.js | |
parent | 4d5f813870683c29af6b9959efa9fd4c4ea5e3b7 (diff) | |
download | PeerTube-876d1bcfd07b14d47ba377474e3bb680872d1f7a.tar.gz PeerTube-876d1bcfd07b14d47ba377474e3bb680872d1f7a.tar.zst PeerTube-876d1bcfd07b14d47ba377474e3bb680872d1f7a.zip |
Tests refractoring
Diffstat (limited to 'test/api/singlePod.js')
-rw-r--r-- | test/api/singlePod.js | 147 |
1 files changed, 55 insertions, 92 deletions
diff --git a/test/api/singlePod.js b/test/api/singlePod.js index 301065f39..be944d8da 100644 --- a/test/api/singlePod.js +++ b/test/api/singlePod.js | |||
@@ -1,17 +1,16 @@ | |||
1 | ;(function () { | 1 | ;(function () { |
2 | 'use strict' | 2 | 'use strict' |
3 | 3 | ||
4 | var request = require('supertest') | ||
5 | var chai = require('chai') | 4 | var chai = require('chai') |
6 | var fs = require('fs') | 5 | var fs = require('fs') |
7 | var expect = chai.expect | 6 | var expect = chai.expect |
7 | |||
8 | var webtorrent = require(__dirname + '/../../src/webTorrentNode') | 8 | var webtorrent = require(__dirname + '/../../src/webTorrentNode') |
9 | webtorrent.silent = true | 9 | webtorrent.silent = true |
10 | 10 | ||
11 | var utils = require('../utils') | 11 | var utils = require('./utils') |
12 | 12 | ||
13 | describe('Test a single pod', function () { | 13 | describe('Test a single pod', function () { |
14 | var path = '/api/v1/videos' | ||
15 | var app = null | 14 | var app = null |
16 | var url = '' | 15 | var url = '' |
17 | var video_id = -1 | 16 | var video_id = -1 |
@@ -32,135 +31,99 @@ | |||
32 | }) | 31 | }) |
33 | 32 | ||
34 | it('Should not have videos', function (done) { | 33 | it('Should not have videos', function (done) { |
35 | request(url) | 34 | utils.getVideosList(url, function (err, res) { |
36 | .get(path) | 35 | if (err) throw err |
37 | .set('Accept', 'application/json') | ||
38 | .expect(200) | ||
39 | .expect('Content-Type', /json/) | ||
40 | .end(function (err, res) { | ||
41 | if (err) throw err | ||
42 | 36 | ||
43 | expect(res.body).to.be.an('array') | 37 | expect(res.body).to.be.an('array') |
44 | expect(res.body.length).to.equal(0) | 38 | expect(res.body.length).to.equal(0) |
45 | 39 | ||
46 | done() | 40 | done() |
47 | }) | 41 | }) |
48 | }) | 42 | }) |
49 | 43 | ||
50 | it('Should upload the video', function (done) { | 44 | it('Should upload the video', function (done) { |
51 | this.timeout(5000) | 45 | this.timeout(5000) |
52 | 46 | utils.uploadVideo(url, 'my super name', 'my super description', 'video_short.webm', done) | |
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 | }) | 47 | }) |
61 | 48 | ||
62 | it('Should seed the uploaded video', function (done) { | 49 | it('Should seed the uploaded video', function (done) { |
63 | // Yes, this could be long | 50 | // Yes, this could be long |
64 | this.timeout(60000) | 51 | this.timeout(60000) |
65 | 52 | ||
66 | request(url) | 53 | utils.getVideosList(url, function (err, res) { |
67 | .get(path) | 54 | if (err) throw err |
68 | .set('Accept', 'application/json') | ||
69 | .expect(200) | ||
70 | .expect('Content-Type', /json/) | ||
71 | .end(function (err, res) { | ||
72 | if (err) throw err | ||
73 | 55 | ||
74 | expect(res.body).to.be.an('array') | 56 | expect(res.body).to.be.an('array') |
75 | expect(res.body.length).to.equal(1) | 57 | expect(res.body.length).to.equal(1) |
76 | 58 | ||
77 | var video = res.body[0] | 59 | var video = res.body[0] |
78 | expect(video.name).to.equal('my super name') | 60 | expect(video.name).to.equal('my super name') |
79 | expect(video.description).to.equal('my super description') | 61 | expect(video.description).to.equal('my super description') |
80 | expect(video.podUrl).to.equal('http://localhost:9001') | 62 | expect(video.podUrl).to.equal('http://localhost:9001') |
81 | expect(video.magnetUri).to.exist | 63 | expect(video.magnetUri).to.exist |
82 | 64 | ||
83 | video_id = video._id | 65 | video_id = video._id |
84 | 66 | ||
85 | webtorrent.add(video.magnetUri, function (torrent) { | 67 | webtorrent.add(video.magnetUri, function (torrent) { |
86 | expect(torrent.files).to.exist | 68 | expect(torrent.files).to.exist |
87 | expect(torrent.files.length).to.equal(1) | 69 | expect(torrent.files.length).to.equal(1) |
88 | expect(torrent.files[0].path).to.exist.and.to.not.equal('') | 70 | expect(torrent.files[0].path).to.exist.and.to.not.equal('') |
89 | 71 | ||
90 | done() | 72 | done() |
91 | }) | ||
92 | }) | 73 | }) |
74 | }) | ||
93 | }) | 75 | }) |
94 | 76 | ||
95 | it('Should search the video', function (done) { | 77 | it('Should search the video', function (done) { |
96 | request(url) | 78 | utils.searchVideo(url, 'my', function (err, res) { |
97 | .get(path + '/search/my') | 79 | if (err) throw err |
98 | .set('Accept', 'application/json') | ||
99 | .expect(200) | ||
100 | .expect('Content-Type', /json/) | ||
101 | .end(function (err, res) { | ||
102 | if (err) throw err | ||
103 | 80 | ||
104 | expect(res.body).to.be.an('array') | 81 | expect(res.body).to.be.an('array') |
105 | expect(res.body.length).to.equal(1) | 82 | expect(res.body.length).to.equal(1) |
106 | 83 | ||
107 | var video = res.body[0] | 84 | var video = res.body[0] |
108 | expect(video.name).to.equal('my super name') | 85 | expect(video.name).to.equal('my super name') |
109 | expect(video.description).to.equal('my super description') | 86 | expect(video.description).to.equal('my super description') |
110 | expect(video.podUrl).to.equal('http://localhost:9001') | 87 | expect(video.podUrl).to.equal('http://localhost:9001') |
111 | expect(video.magnetUri).to.exist | 88 | expect(video.magnetUri).to.exist |
112 | 89 | ||
113 | done() | 90 | done() |
114 | }) | 91 | }) |
115 | }) | 92 | }) |
116 | 93 | ||
117 | it('Should not find a search', function (done) { | 94 | it('Should not find a search', function (done) { |
118 | request(url) | 95 | utils.searchVideo(url, 'hello', function (err, res) { |
119 | .get(path + '/search/hello') | 96 | if (err) throw err |
120 | .set('Accept', 'application/json') | ||
121 | .expect(200) | ||
122 | .expect('Content-Type', /json/) | ||
123 | .end(function (err, res) { | ||
124 | if (err) throw err | ||
125 | 97 | ||
126 | expect(res.body).to.be.an('array') | 98 | expect(res.body).to.be.an('array') |
127 | expect(res.body.length).to.equal(0) | 99 | expect(res.body.length).to.equal(0) |
128 | 100 | ||
129 | done() | 101 | done() |
130 | }) | 102 | }) |
131 | }) | 103 | }) |
132 | 104 | ||
133 | it('Should remove the video', function (done) { | 105 | it('Should remove the video', function (done) { |
134 | request(url) | 106 | utils.removeVideo(url, video_id, function (err) { |
135 | .delete(path + '/' + video_id) | 107 | if (err) throw err |
136 | .set('Accept', 'application/json') | ||
137 | .expect(204) | ||
138 | .end(function (err, res) { | ||
139 | if (err) throw err | ||
140 | 108 | ||
141 | fs.readdir(__dirname + '/../../test1/uploads/', function (err, files) { | 109 | fs.readdir(__dirname + '/../../test1/uploads/', function (err, files) { |
142 | if (err) throw err | 110 | if (err) throw err |
143 | 111 | ||
144 | expect(files.length).to.equal(0) | 112 | expect(files.length).to.equal(0) |
145 | done() | 113 | done() |
146 | }) | ||
147 | }) | 114 | }) |
115 | }) | ||
148 | }) | 116 | }) |
149 | 117 | ||
150 | it('Should not have videos', function (done) { | 118 | it('Should not have videos', function (done) { |
151 | request(url) | 119 | utils.getVideosList(url, function (err, res) { |
152 | .get(path) | 120 | if (err) throw err |
153 | .set('Accept', 'application/json') | ||
154 | .expect(200) | ||
155 | .expect('Content-Type', /json/) | ||
156 | .end(function (err, res) { | ||
157 | if (err) throw err | ||
158 | 121 | ||
159 | expect(res.body).to.be.an('array') | 122 | expect(res.body).to.be.an('array') |
160 | expect(res.body.length).to.equal(0) | 123 | expect(res.body.length).to.equal(0) |
161 | 124 | ||
162 | done() | 125 | done() |
163 | }) | 126 | }) |
164 | }) | 127 | }) |
165 | 128 | ||
166 | after(function (done) { | 129 | after(function (done) { |