aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-12-05 17:46:33 +0100
committerChocobozzz <florian.bigard@gmail.com>2017-12-05 18:25:29 +0100
commitf3aaa9a95cc2b61f1f255472d7014d08faa66561 (patch)
tree95e70c8d0ed5b6f1c71c32a77cb7d6cf8478c9d4 /server/tests
parentd235f6b0d1054a2a3451dacade927caefce8f30c (diff)
downloadPeerTube-f3aaa9a95cc2b61f1f255472d7014d08faa66561.tar.gz
PeerTube-f3aaa9a95cc2b61f1f255472d7014d08faa66561.tar.zst
PeerTube-f3aaa9a95cc2b61f1f255472d7014d08faa66561.zip
Fix client search
Diffstat (limited to 'server/tests')
-rw-r--r--server/tests/api/single-server.ts112
-rw-r--r--server/tests/utils/videos.ts20
2 files changed, 68 insertions, 64 deletions
diff --git a/server/tests/api/single-server.ts b/server/tests/api/single-server.ts
index 041d13225..fe192d391 100644
--- a/server/tests/api/single-server.ts
+++ b/server/tests/api/single-server.ts
@@ -225,7 +225,7 @@ describe('Test a single server', function () {
225 expect(video.views).to.equal(3) 225 expect(video.views).to.equal(3)
226 }) 226 })
227 227
228 it('Should search the video by name by default', async function () { 228 it('Should search the video by name', async function () {
229 const res = await searchVideo(server.url, 'my') 229 const res = await searchVideo(server.url, 'my')
230 230
231 expect(res.body.total).to.equal(1) 231 expect(res.body.total).to.equal(1)
@@ -279,35 +279,36 @@ describe('Test a single server', function () {
279 // }) 279 // })
280 // }) 280 // })
281 281
282 it('Should search the video by tag', async function () { 282 // Not implemented yet
283 const res = await searchVideo(server.url, 'tag1', 'tags') 283 // it('Should search the video by tag', async function () {
284 284 // const res = await searchVideo(server.url, 'tag1')
285 expect(res.body.total).to.equal(1) 285 //
286 expect(res.body.data).to.be.an('array') 286 // expect(res.body.total).to.equal(1)
287 expect(res.body.data.length).to.equal(1) 287 // expect(res.body.data).to.be.an('array')
288 288 // expect(res.body.data.length).to.equal(1)
289 const video = res.body.data[0] 289 //
290 expect(video.name).to.equal('my super name') 290 // const video = res.body.data[0]
291 expect(video.category).to.equal(2) 291 // expect(video.name).to.equal('my super name')
292 expect(video.categoryLabel).to.equal('Films') 292 // expect(video.category).to.equal(2)
293 expect(video.licence).to.equal(6) 293 // expect(video.categoryLabel).to.equal('Films')
294 expect(video.licenceLabel).to.equal('Attribution - Non Commercial - No Derivatives') 294 // expect(video.licence).to.equal(6)
295 expect(video.language).to.equal(3) 295 // expect(video.licenceLabel).to.equal('Attribution - Non Commercial - No Derivatives')
296 expect(video.languageLabel).to.equal('Mandarin') 296 // expect(video.language).to.equal(3)
297 expect(video.nsfw).to.be.ok 297 // expect(video.languageLabel).to.equal('Mandarin')
298 expect(video.description).to.equal('my super description') 298 // expect(video.nsfw).to.be.ok
299 expect(video.serverHost).to.equal('localhost:9001') 299 // expect(video.description).to.equal('my super description')
300 expect(video.account).to.equal('root') 300 // expect(video.serverHost).to.equal('localhost:9001')
301 expect(video.isLocal).to.be.true 301 // expect(video.account).to.equal('root')
302 expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ]) 302 // expect(video.isLocal).to.be.true
303 expect(dateIsValid(video.createdAt)).to.be.true 303 // expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
304 expect(dateIsValid(video.updatedAt)).to.be.true 304 // expect(dateIsValid(video.createdAt)).to.be.true
305 305 // expect(dateIsValid(video.updatedAt)).to.be.true
306 const test = await testVideoImage(server.url, 'video_short.webm', video.thumbnailPath) 306 //
307 expect(test).to.equal(true) 307 // const test = await testVideoImage(server.url, 'video_short.webm', video.thumbnailPath)
308 }) 308 // expect(test).to.equal(true)
309 // })
309 310
310 it('Should not find a search by name by default', async function () { 311 it('Should not find a search by name', async function () {
311 const res = await searchVideo(server.url, 'hello') 312 const res = await searchVideo(server.url, 'hello')
312 313
313 expect(res.body.total).to.equal(0) 314 expect(res.body.total).to.equal(0)
@@ -315,21 +316,23 @@ describe('Test a single server', function () {
315 expect(res.body.data.length).to.equal(0) 316 expect(res.body.data.length).to.equal(0)
316 }) 317 })
317 318
318 it('Should not find a search by author', async function () { 319 // Not implemented yet
319 const res = await searchVideo(server.url, 'hello', 'account') 320 // it('Should not find a search by author', async function () {
320 321 // const res = await searchVideo(server.url, 'hello')
321 expect(res.body.total).to.equal(0) 322 //
322 expect(res.body.data).to.be.an('array') 323 // expect(res.body.total).to.equal(0)
323 expect(res.body.data.length).to.equal(0) 324 // expect(res.body.data).to.be.an('array')
324 }) 325 // expect(res.body.data.length).to.equal(0)
325 326 // })
326 it('Should not find a search by tag', async function () { 327 //
327 const res = await searchVideo(server.url, 'hello', 'tags') 328 // Not implemented yet
328 329 // it('Should not find a search by tag', async function () {
329 expect(res.body.total).to.equal(0) 330 // const res = await searchVideo(server.url, 'hello')
330 expect(res.body.data).to.be.an('array') 331 //
331 expect(res.body.data.length).to.equal(0) 332 // expect(res.body.total).to.equal(0)
332 }) 333 // expect(res.body.data).to.be.an('array')
334 // expect(res.body.data.length).to.equal(0)
335 // })
333 336
334 it('Should remove the video', async function () { 337 it('Should remove the video', async function () {
335 await removeVideo(server.url, server.accessToken, videoId) 338 await removeVideo(server.url, server.accessToken, videoId)
@@ -443,7 +446,7 @@ describe('Test a single server', function () {
443 }) 446 })
444 447
445 it('Should search the first video', async function () { 448 it('Should search the first video', async function () {
446 const res = await searchVideoWithPagination(server.url, 'webm', 'name', 0, 1, 'name') 449 const res = await searchVideoWithPagination(server.url, 'webm', 0, 1, 'name')
447 450
448 const videos = res.body.data 451 const videos = res.body.data
449 expect(res.body.total).to.equal(4) 452 expect(res.body.total).to.equal(4)
@@ -452,7 +455,7 @@ describe('Test a single server', function () {
452 }) 455 })
453 456
454 it('Should search the last two videos', async function () { 457 it('Should search the last two videos', async function () {
455 const res = await searchVideoWithPagination(server.url, 'webm', 'name', 2, 2, 'name') 458 const res = await searchVideoWithPagination(server.url, 'webm', 2, 2, 'name')
456 459
457 const videos = res.body.data 460 const videos = res.body.data
458 expect(res.body.total).to.equal(4) 461 expect(res.body.total).to.equal(4)
@@ -462,20 +465,21 @@ describe('Test a single server', function () {
462 }) 465 })
463 466
464 it('Should search all the webm videos', async function () { 467 it('Should search all the webm videos', async function () {
465 const res = await searchVideoWithPagination(server.url, 'webm', 'name', 0, 15) 468 const res = await searchVideoWithPagination(server.url, 'webm', 0, 15)
466 469
467 const videos = res.body.data 470 const videos = res.body.data
468 expect(res.body.total).to.equal(4) 471 expect(res.body.total).to.equal(4)
469 expect(videos.length).to.equal(4) 472 expect(videos.length).to.equal(4)
470 }) 473 })
471 474
472 it('Should search all the root author videos', async function () { 475 // Not implemented yet
473 const res = await searchVideoWithPagination(server.url, 'root', 'account', 0, 15) 476 // it('Should search all the root author videos', async function () {
474 477 // const res = await searchVideoWithPagination(server.url, 'root', 0, 15)
475 const videos = res.body.data 478 //
476 expect(res.body.total).to.equal(6) 479 // const videos = res.body.data
477 expect(videos.length).to.equal(6) 480 // expect(res.body.total).to.equal(6)
478 }) 481 // expect(videos.length).to.equal(6)
482 // })
479 483
480 // Not implemented yet 484 // Not implemented yet
481 // it('Should search all the 9001 port videos', async function () { 485 // it('Should search all the 9001 port videos', async function () {
diff --git a/server/tests/utils/videos.ts b/server/tests/utils/videos.ts
index 73a9f1a0a..ff7da9bb2 100644
--- a/server/tests/utils/videos.ts
+++ b/server/tests/utils/videos.ts
@@ -145,26 +145,25 @@ function removeVideo (url: string, token: string, id: number, expectedStatus = 2
145 .expect(expectedStatus) 145 .expect(expectedStatus)
146} 146}
147 147
148function searchVideo (url: string, search: string, field?: string) { 148function searchVideo (url: string, search: string) {
149 const path = '/api/v1/videos' 149 const path = '/api/v1/videos'
150 const req = request(url) 150 const req = request(url)
151 .get(path + '/search/' + search) 151 .get(path + '/search')
152 .set('Accept', 'application/json') 152 .query({ search })
153 153 .set('Accept', 'application/json')
154 if (field) req.query({ field })
155 154
156 return req.expect(200) 155 return req.expect(200)
157 .expect('Content-Type', /json/) 156 .expect('Content-Type', /json/)
158} 157}
159 158
160function searchVideoWithPagination (url: string, search: string, field: string, start: number, count: number, sort?: string) { 159function searchVideoWithPagination (url: string, search: string, start: number, count: number, sort?: string) {
161 const path = '/api/v1/videos' 160 const path = '/api/v1/videos'
162 161
163 const req = request(url) 162 const req = request(url)
164 .get(path + '/search/' + search) 163 .get(path + '/search')
165 .query({ start }) 164 .query({ start })
165 .query({ search })
166 .query({ count }) 166 .query({ count })
167 .query({ field })
168 167
169 if (sort) req.query({ sort }) 168 if (sort) req.query({ sort })
170 169
@@ -177,7 +176,8 @@ function searchVideoWithSort (url: string, search: string, sort: string) {
177 const path = '/api/v1/videos' 176 const path = '/api/v1/videos'
178 177
179 return request(url) 178 return request(url)
180 .get(path + '/search/' + search) 179 .get(path + '/search')
180 .query({ search })
181 .query({ sort }) 181 .query({ sort })
182 .set('Accept', 'application/json') 182 .set('Accept', 'application/json')
183 .expect(200) 183 .expect(200)