aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2016-05-21 19:30:22 +0200
committerChocobozzz <florian.bigard@gmail.com>2016-05-21 19:30:22 +0200
commit68ce3ae021c9bc11b155044df6d23ba60e91eee4 (patch)
tree7cb162a57994f96703ef8387babdeda17d3b58bc /server/tests/api
parent501bc6c2b186f6a724a5b619d15aa44791f13995 (diff)
downloadPeerTube-68ce3ae021c9bc11b155044df6d23ba60e91eee4.tar.gz
PeerTube-68ce3ae021c9bc11b155044df6d23ba60e91eee4.tar.zst
PeerTube-68ce3ae021c9bc11b155044df6d23ba60e91eee4.zip
Add total results field and wrap videos in data field when listing
videos
Diffstat (limited to 'server/tests/api')
-rw-r--r--server/tests/api/checkParams.js4
-rw-r--r--server/tests/api/friendsAdvanced.js17
-rw-r--r--server/tests/api/multiplePods.js33
-rw-r--r--server/tests/api/singlePod.js64
-rw-r--r--server/tests/api/users.js2
5 files changed, 70 insertions, 50 deletions
diff --git a/server/tests/api/checkParams.js b/server/tests/api/checkParams.js
index a109aba47..e02fd0da5 100644
--- a/server/tests/api/checkParams.js
+++ b/server/tests/api/checkParams.js
@@ -299,8 +299,8 @@ describe('Test parameters validator', function () {
299 .end(function (err, res) { 299 .end(function (err, res) {
300 if (err) throw err 300 if (err) throw err
301 301
302 expect(res.body).to.be.an('array') 302 expect(res.body.data).to.be.an('array')
303 expect(res.body.length).to.equal(3) 303 expect(res.body.data.length).to.equal(3)
304 304
305 done() 305 done()
306 }) 306 })
diff --git a/server/tests/api/friendsAdvanced.js b/server/tests/api/friendsAdvanced.js
index f3d5cd4a0..7b895b6b5 100644
--- a/server/tests/api/friendsAdvanced.js
+++ b/server/tests/api/friendsAdvanced.js
@@ -210,8 +210,10 @@ describe('Test advanced friends', function () {
210 function (next) { 210 function (next) {
211 getVideos(1, function (err, res) { 211 getVideos(1, function (err, res) {
212 if (err) throw err 212 if (err) throw err
213 expect(res.body).to.be.an('array') 213
214 expect(res.body.length).to.equal(2) 214 const videos = res.body.data
215 expect(videos).to.be.an('array')
216 expect(videos.length).to.equal(2)
215 217
216 next() 218 next()
217 }) 219 })
@@ -221,8 +223,10 @@ describe('Test advanced friends', function () {
221 223
222 getVideos(2, function (err, res) { 224 getVideos(2, function (err, res) {
223 if (err) throw err 225 if (err) throw err
224 expect(res.body).to.be.an('array') 226
225 expect(res.body.length).to.equal(3) 227 const videos = res.body.data
228 expect(videos).to.be.an('array')
229 expect(videos.length).to.equal(3)
226 done() 230 done()
227 }) 231 })
228 } 232 }
@@ -236,8 +240,9 @@ describe('Test advanced friends', function () {
236 getVideos(1, function (err, res) { 240 getVideos(1, function (err, res) {
237 if (err) throw err 241 if (err) throw err
238 242
239 expect(res.body).to.be.an('array') 243 const videos = res.body.data
240 expect(res.body.length).to.equal(5) 244 expect(videos).to.be.an('array')
245 expect(videos.length).to.equal(5)
241 246
242 done() 247 done()
243 }) 248 })
diff --git a/server/tests/api/multiplePods.js b/server/tests/api/multiplePods.js
index c31c18b02..dac6dd410 100644
--- a/server/tests/api/multiplePods.js
+++ b/server/tests/api/multiplePods.js
@@ -60,8 +60,9 @@ describe('Test multiple pods', function () {
60 utils.getVideosList(server.url, function (err, res) { 60 utils.getVideosList(server.url, function (err, res) {
61 if (err) throw err 61 if (err) throw err
62 62
63 expect(res.body).to.be.an('array') 63 const videos = res.body.data
64 expect(res.body.length).to.equal(0) 64 expect(videos).to.be.an('array')
65 expect(videos.length).to.equal(0)
65 66
66 callback() 67 callback()
67 }) 68 })
@@ -89,13 +90,13 @@ describe('Test multiple pods', function () {
89 utils.getVideosList(server.url, function (err, res) { 90 utils.getVideosList(server.url, function (err, res) {
90 if (err) throw err 91 if (err) throw err
91 92
92 const videos = res.body 93 const videos = res.body.data
93 expect(videos).to.be.an('array') 94 expect(videos).to.be.an('array')
94 expect(videos.length).to.equal(1) 95 expect(videos.length).to.equal(1)
95 const video = videos[0] 96 const video = videos[0]
96 expect(video.name).to.equal('my super name for pod 1') 97 expect(video.name).to.equal('my super name for pod 1')
97 expect(video.description).to.equal('my super description for pod 1') 98 expect(video.description).to.equal('my super description for pod 1')
98 expect(video.podUrl).to.equal('http://localhost:9001') 99 expect(video.podUrl).to.equal('localhost:9001')
99 expect(video.magnetUri).to.exist 100 expect(video.magnetUri).to.exist
100 expect(video.duration).to.equal(10) 101 expect(video.duration).to.equal(10)
101 expect(utils.dateIsValid(video.createdDate)).to.be.true 102 expect(utils.dateIsValid(video.createdDate)).to.be.true
@@ -145,13 +146,13 @@ describe('Test multiple pods', function () {
145 utils.getVideosList(server.url, function (err, res) { 146 utils.getVideosList(server.url, function (err, res) {
146 if (err) throw err 147 if (err) throw err
147 148
148 const videos = res.body 149 const videos = res.body.data
149 expect(videos).to.be.an('array') 150 expect(videos).to.be.an('array')
150 expect(videos.length).to.equal(2) 151 expect(videos.length).to.equal(2)
151 const video = videos[1] 152 const video = videos[1]
152 expect(video.name).to.equal('my super name for pod 2') 153 expect(video.name).to.equal('my super name for pod 2')
153 expect(video.description).to.equal('my super description for pod 2') 154 expect(video.description).to.equal('my super description for pod 2')
154 expect(video.podUrl).to.equal('http://localhost:9002') 155 expect(video.podUrl).to.equal('localhost:9002')
155 expect(video.magnetUri).to.exist 156 expect(video.magnetUri).to.exist
156 expect(video.duration).to.equal(5) 157 expect(video.duration).to.equal(5)
157 expect(utils.dateIsValid(video.createdDate)).to.be.true 158 expect(utils.dateIsValid(video.createdDate)).to.be.true
@@ -203,7 +204,7 @@ describe('Test multiple pods', function () {
203 utils.getVideosList(server.url, function (err, res) { 204 utils.getVideosList(server.url, function (err, res) {
204 if (err) throw err 205 if (err) throw err
205 206
206 const videos = res.body 207 const videos = res.body.data
207 expect(videos).to.be.an('array') 208 expect(videos).to.be.an('array')
208 expect(videos.length).to.equal(4) 209 expect(videos.length).to.equal(4)
209 210
@@ -220,14 +221,14 @@ describe('Test multiple pods', function () {
220 221
221 expect(video1.name).to.equal('my super name for pod 3') 222 expect(video1.name).to.equal('my super name for pod 3')
222 expect(video1.description).to.equal('my super description for pod 3') 223 expect(video1.description).to.equal('my super description for pod 3')
223 expect(video1.podUrl).to.equal('http://localhost:9003') 224 expect(video1.podUrl).to.equal('localhost:9003')
224 expect(video1.magnetUri).to.exist 225 expect(video1.magnetUri).to.exist
225 expect(video1.duration).to.equal(5) 226 expect(video1.duration).to.equal(5)
226 expect(utils.dateIsValid(video1.createdDate)).to.be.true 227 expect(utils.dateIsValid(video1.createdDate)).to.be.true
227 228
228 expect(video2.name).to.equal('my super name for pod 3-2') 229 expect(video2.name).to.equal('my super name for pod 3-2')
229 expect(video2.description).to.equal('my super description for pod 3-2') 230 expect(video2.description).to.equal('my super description for pod 3-2')
230 expect(video2.podUrl).to.equal('http://localhost:9003') 231 expect(video2.podUrl).to.equal('localhost:9003')
231 expect(video2.magnetUri).to.exist 232 expect(video2.magnetUri).to.exist
232 expect(video2.duration).to.equal(5) 233 expect(video2.duration).to.equal(5)
233 expect(utils.dateIsValid(video2.createdDate)).to.be.true 234 expect(utils.dateIsValid(video2.createdDate)).to.be.true
@@ -273,9 +274,9 @@ describe('Test multiple pods', function () {
273 utils.getVideosList(servers[2].url, function (err, res) { 274 utils.getVideosList(servers[2].url, function (err, res) {
274 if (err) throw err 275 if (err) throw err
275 276
276 const video = res.body[0] 277 const video = res.body.data[0]
277 toRemove.push(res.body[2].id) 278 toRemove.push(res.body.data[2].id)
278 toRemove.push(res.body[3].id) 279 toRemove.push(res.body.data[3].id)
279 280
280 webtorrent.add(video.magnetUri, function (torrent) { 281 webtorrent.add(video.magnetUri, function (torrent) {
281 expect(torrent.files).to.exist 282 expect(torrent.files).to.exist
@@ -294,7 +295,7 @@ describe('Test multiple pods', function () {
294 utils.getVideosList(servers[0].url, function (err, res) { 295 utils.getVideosList(servers[0].url, function (err, res) {
295 if (err) throw err 296 if (err) throw err
296 297
297 const video = res.body[1] 298 const video = res.body.data[1]
298 299
299 webtorrent.add(video.magnetUri, function (torrent) { 300 webtorrent.add(video.magnetUri, function (torrent) {
300 expect(torrent.files).to.exist 301 expect(torrent.files).to.exist
@@ -313,7 +314,7 @@ describe('Test multiple pods', function () {
313 utils.getVideosList(servers[1].url, function (err, res) { 314 utils.getVideosList(servers[1].url, function (err, res) {
314 if (err) throw err 315 if (err) throw err
315 316
316 const video = res.body[2] 317 const video = res.body.data[2]
317 318
318 webtorrent.add(video.magnetUri, function (torrent) { 319 webtorrent.add(video.magnetUri, function (torrent) {
319 expect(torrent.files).to.exist 320 expect(torrent.files).to.exist
@@ -332,7 +333,7 @@ describe('Test multiple pods', function () {
332 utils.getVideosList(servers[0].url, function (err, res) { 333 utils.getVideosList(servers[0].url, function (err, res) {
333 if (err) throw err 334 if (err) throw err
334 335
335 const video = res.body[3] 336 const video = res.body.data[3]
336 337
337 webtorrent.add(video.magnetUri, function (torrent) { 338 webtorrent.add(video.magnetUri, function (torrent) {
338 expect(torrent.files).to.exist 339 expect(torrent.files).to.exist
@@ -366,7 +367,7 @@ describe('Test multiple pods', function () {
366 utils.getVideosList(server.url, function (err, res) { 367 utils.getVideosList(server.url, function (err, res) {
367 if (err) throw err 368 if (err) throw err
368 369
369 const videos = res.body 370 const videos = res.body.data
370 expect(videos).to.be.an('array') 371 expect(videos).to.be.an('array')
371 expect(videos.length).to.equal(2) 372 expect(videos.length).to.equal(2)
372 expect(videos[0].id).not.to.equal(videos[1].id) 373 expect(videos[0].id).not.to.equal(videos[1].id)
diff --git a/server/tests/api/singlePod.js b/server/tests/api/singlePod.js
index 1a53ada3a..884a83032 100644
--- a/server/tests/api/singlePod.js
+++ b/server/tests/api/singlePod.js
@@ -47,8 +47,9 @@ describe('Test a single pod', function () {
47 utils.getVideosList(server.url, function (err, res) { 47 utils.getVideosList(server.url, function (err, res) {
48 if (err) throw err 48 if (err) throw err
49 49
50 expect(res.body).to.be.an('array') 50 expect(res.body.total).to.equal(0)
51 expect(res.body.length).to.equal(0) 51 expect(res.body.data).to.be.an('array')
52 expect(res.body.data.length).to.equal(0)
52 53
53 done() 54 done()
54 }) 55 })
@@ -66,13 +67,14 @@ describe('Test a single pod', function () {
66 utils.getVideosList(server.url, function (err, res) { 67 utils.getVideosList(server.url, function (err, res) {
67 if (err) throw err 68 if (err) throw err
68 69
69 expect(res.body).to.be.an('array') 70 expect(res.body.total).to.equal(1)
70 expect(res.body.length).to.equal(1) 71 expect(res.body.data).to.be.an('array')
72 expect(res.body.data.length).to.equal(1)
71 73
72 const video = res.body[0] 74 const video = res.body.data[0]
73 expect(video.name).to.equal('my super name') 75 expect(video.name).to.equal('my super name')
74 expect(video.description).to.equal('my super description') 76 expect(video.description).to.equal('my super description')
75 expect(video.podUrl).to.equal('http://localhost:9001') 77 expect(video.podUrl).to.equal('localhost:9001')
76 expect(video.magnetUri).to.exist 78 expect(video.magnetUri).to.exist
77 expect(video.author).to.equal('root') 79 expect(video.author).to.equal('root')
78 expect(video.isLocal).to.be.true 80 expect(video.isLocal).to.be.true
@@ -106,7 +108,7 @@ describe('Test a single pod', function () {
106 const video = res.body 108 const video = res.body
107 expect(video.name).to.equal('my super name') 109 expect(video.name).to.equal('my super name')
108 expect(video.description).to.equal('my super description') 110 expect(video.description).to.equal('my super description')
109 expect(video.podUrl).to.equal('http://localhost:9001') 111 expect(video.podUrl).to.equal('localhost:9001')
110 expect(video.magnetUri).to.exist 112 expect(video.magnetUri).to.exist
111 expect(video.author).to.equal('root') 113 expect(video.author).to.equal('root')
112 expect(video.isLocal).to.be.true 114 expect(video.isLocal).to.be.true
@@ -131,13 +133,14 @@ describe('Test a single pod', function () {
131 utils.searchVideo(server.url, 'my', function (err, res) { 133 utils.searchVideo(server.url, 'my', function (err, res) {
132 if (err) throw err 134 if (err) throw err
133 135
134 expect(res.body).to.be.an('array') 136 expect(res.body.total).to.equal(1)
135 expect(res.body.length).to.equal(1) 137 expect(res.body.data).to.be.an('array')
138 expect(res.body.data.length).to.equal(1)
136 139
137 const video = res.body[0] 140 const video = res.body.data[0]
138 expect(video.name).to.equal('my super name') 141 expect(video.name).to.equal('my super name')
139 expect(video.description).to.equal('my super description') 142 expect(video.description).to.equal('my super description')
140 expect(video.podUrl).to.equal('http://localhost:9001') 143 expect(video.podUrl).to.equal('localhost:9001')
141 expect(video.author).to.equal('root') 144 expect(video.author).to.equal('root')
142 expect(video.isLocal).to.be.true 145 expect(video.isLocal).to.be.true
143 expect(utils.dateIsValid(video.createdDate)).to.be.true 146 expect(utils.dateIsValid(video.createdDate)).to.be.true
@@ -155,8 +158,9 @@ describe('Test a single pod', function () {
155 utils.searchVideo(server.url, 'hello', function (err, res) { 158 utils.searchVideo(server.url, 'hello', function (err, res) {
156 if (err) throw err 159 if (err) throw err
157 160
158 expect(res.body).to.be.an('array') 161 expect(res.body.total).to.equal(0)
159 expect(res.body.length).to.equal(0) 162 expect(res.body.data).to.be.an('array')
163 expect(res.body.data.length).to.equal(0)
160 164
161 done() 165 done()
162 }) 166 })
@@ -179,8 +183,9 @@ describe('Test a single pod', function () {
179 utils.getVideosList(server.url, function (err, res) { 183 utils.getVideosList(server.url, function (err, res) {
180 if (err) throw err 184 if (err) throw err
181 185
182 expect(res.body).to.be.an('array') 186 expect(res.body.total).to.equal(0)
183 expect(res.body.length).to.equal(0) 187 expect(res.body.data).to.be.an('array')
188 expect(res.body.data.length).to.equal(0)
184 189
185 done() 190 done()
186 }) 191 })
@@ -201,7 +206,8 @@ describe('Test a single pod', function () {
201 utils.getVideosList(server.url, function (err, res) { 206 utils.getVideosList(server.url, function (err, res) {
202 if (err) throw err 207 if (err) throw err
203 208
204 const videos = res.body 209 expect(res.body.total).to.equal(6)
210 const videos = res.body.data
205 expect(videos).to.be.an('array') 211 expect(videos).to.be.an('array')
206 expect(videos.length).to.equal(6) 212 expect(videos.length).to.equal(6)
207 213
@@ -221,7 +227,7 @@ describe('Test a single pod', function () {
221 utils.getVideosList(server.url, function (err, res) { 227 utils.getVideosList(server.url, function (err, res) {
222 if (err) throw err 228 if (err) throw err
223 229
224 const videos = res.body 230 const videos = res.body.data
225 // For the next test 231 // For the next test
226 videosListBase = videos 232 videosListBase = videos
227 233
@@ -243,7 +249,8 @@ describe('Test a single pod', function () {
243 utils.getVideosListPagination(server.url, 0, 2, function (err, res) { 249 utils.getVideosListPagination(server.url, 0, 2, function (err, res) {
244 if (err) throw err 250 if (err) throw err
245 251
246 const videos = res.body 252 const videos = res.body.data
253 expect(res.body.total).to.equal(6)
247 expect(videos.length).to.equal(2) 254 expect(videos.length).to.equal(2)
248 expect(videos[0].name === videosListBase[0].name) 255 expect(videos[0].name === videosListBase[0].name)
249 expect(videos[1].name === videosListBase[1].name) 256 expect(videos[1].name === videosListBase[1].name)
@@ -256,7 +263,8 @@ describe('Test a single pod', function () {
256 utils.getVideosListPagination(server.url, 2, 3, function (err, res) { 263 utils.getVideosListPagination(server.url, 2, 3, function (err, res) {
257 if (err) throw err 264 if (err) throw err
258 265
259 const videos = res.body 266 const videos = res.body.data
267 expect(res.body.total).to.equal(6)
260 expect(videos.length).to.equal(4) 268 expect(videos.length).to.equal(4)
261 expect(videos[0].name === videosListBase[2].name) 269 expect(videos[0].name === videosListBase[2].name)
262 expect(videos[1].name === videosListBase[3].name) 270 expect(videos[1].name === videosListBase[3].name)
@@ -270,7 +278,8 @@ describe('Test a single pod', function () {
270 utils.getVideosListPagination(server.url, 5, 6, function (err, res) { 278 utils.getVideosListPagination(server.url, 5, 6, function (err, res) {
271 if (err) throw err 279 if (err) throw err
272 280
273 const videos = res.body 281 const videos = res.body.data
282 expect(res.body.total).to.equal(6)
274 expect(videos.length).to.equal(1) 283 expect(videos.length).to.equal(1)
275 expect(videos[0].name === videosListBase[5].name) 284 expect(videos[0].name === videosListBase[5].name)
276 285
@@ -282,7 +291,8 @@ describe('Test a single pod', function () {
282 utils.searchVideoWithPagination(server.url, 'webm', 0, 1, function (err, res) { 291 utils.searchVideoWithPagination(server.url, 'webm', 0, 1, function (err, res) {
283 if (err) throw err 292 if (err) throw err
284 293
285 const videos = res.body 294 const videos = res.body.data
295 expect(res.body.total).to.equal(4)
286 expect(videos.length).to.equal(1) 296 expect(videos.length).to.equal(1)
287 expect(videos[0].name === 'video_short.webm name') 297 expect(videos[0].name === 'video_short.webm name')
288 298
@@ -294,7 +304,8 @@ describe('Test a single pod', function () {
294 utils.searchVideoWithPagination(server.url, 'webm', 2, 2, function (err, res) { 304 utils.searchVideoWithPagination(server.url, 'webm', 2, 2, function (err, res) {
295 if (err) throw err 305 if (err) throw err
296 306
297 const videos = res.body 307 const videos = res.body.data
308 expect(res.body.total).to.equal(4)
298 expect(videos.length).to.equal(2) 309 expect(videos.length).to.equal(2)
299 expect(videos[0].name === 'video_short2.webm name') 310 expect(videos[0].name === 'video_short2.webm name')
300 expect(videos[1].name === 'video_short3.webm name') 311 expect(videos[1].name === 'video_short3.webm name')
@@ -307,7 +318,8 @@ describe('Test a single pod', function () {
307 utils.searchVideoWithPagination(server.url, 'webm', 0, 15, function (err, res) { 318 utils.searchVideoWithPagination(server.url, 'webm', 0, 15, function (err, res) {
308 if (err) throw err 319 if (err) throw err
309 320
310 const videos = res.body 321 const videos = res.body.data
322 expect(res.body.total).to.equal(4)
311 expect(videos.length).to.equal(4) 323 expect(videos.length).to.equal(4)
312 324
313 done() 325 done()
@@ -318,7 +330,8 @@ describe('Test a single pod', function () {
318 utils.getVideosListSort(server.url, '-name', function (err, res) { 330 utils.getVideosListSort(server.url, '-name', function (err, res) {
319 if (err) throw err 331 if (err) throw err
320 332
321 const videos = res.body 333 const videos = res.body.data
334 expect(res.body.total).to.equal(6)
322 expect(videos.length).to.equal(6) 335 expect(videos.length).to.equal(6)
323 expect(videos[5].name === 'video_short.mp4 name') 336 expect(videos[5].name === 'video_short.mp4 name')
324 expect(videos[4].name === 'video_short.ogv name') 337 expect(videos[4].name === 'video_short.ogv name')
@@ -335,7 +348,8 @@ describe('Test a single pod', function () {
335 utils.searchVideoWithSort(server.url, 'webm', 'name', function (err, res) { 348 utils.searchVideoWithSort(server.url, 'webm', 'name', function (err, res) {
336 if (err) throw err 349 if (err) throw err
337 350
338 const videos = res.body 351 const videos = res.body.data
352 expect(res.body.total).to.equal(4)
339 expect(videos.length).to.equal(4) 353 expect(videos.length).to.equal(4)
340 354
341 expect(videos[0].name === 'video_short.webm name') 355 expect(videos[0].name === 'video_short.webm name')
diff --git a/server/tests/api/users.js b/server/tests/api/users.js
index cb44d2611..9ab5083a0 100644
--- a/server/tests/api/users.js
+++ b/server/tests/api/users.js
@@ -108,7 +108,7 @@ describe('Test users', function () {
108 utils.getVideosList(server.url, function (err, res) { 108 utils.getVideosList(server.url, function (err, res) {
109 if (err) throw err 109 if (err) throw err
110 110
111 const video = res.body[0] 111 const video = res.body.data[0]
112 expect(video.author).to.equal('root') 112 expect(video.author).to.equal('root')
113 113
114 videoId = video.id 114 videoId = video.id