]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - shared/extra-utils/search/videos.ts
Add ability for plugins to specify scale filter
[github/Chocobozzz/PeerTube.git] / shared / extra-utils / search / videos.ts
index ba46270175f45edc395deb80a450b38c9f83897a..db6edbd58ad0de24c08d602f490ccb234d5ac075 100644 (file)
@@ -1,17 +1,20 @@
-/* tslint:disable:no-unused-expression */
+/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
 
 import * as request from 'supertest'
 import { VideosSearchQuery } from '../../models/search'
 import { immutableAssign } from '../miscs/miscs'
+import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
 
-function searchVideo (url: string, search: string) {
+function searchVideo (url: string, search: string, sort = '-publishedAt') {
   const path = '/api/v1/search/videos'
+
+  const query = { sort, search: search }
   const req = request(url)
     .get(path)
-    .query({ sort: '-publishedAt', search })
+    .query(query)
     .set('Accept', 'application/json')
 
-  return req.expect(200)
+  return req.expect(HttpStatusCode.OK_200)
             .expect('Content-Type', /json/)
 }
 
@@ -23,35 +26,20 @@ function searchVideoWithToken (url: string, search: string, token: string, query
     .query(immutableAssign(query, { sort: '-publishedAt', search }))
     .set('Accept', 'application/json')
 
-  return req.expect(200)
-            .expect('Content-Type', /json/)
-}
-
-function searchVideoWithPagination (url: string, search: string, start: number, count: number, sort?: string) {
-  const path = '/api/v1/search/videos'
-
-  const req = request(url)
-    .get(path)
-    .query({ start })
-    .query({ search })
-    .query({ count })
-
-  if (sort) req.query({ sort })
-
-  return req.set('Accept', 'application/json')
-            .expect(200)
+  return req.expect(HttpStatusCode.OK_200)
             .expect('Content-Type', /json/)
 }
 
 function searchVideoWithSort (url: string, search: string, sort: string) {
   const path = '/api/v1/search/videos'
 
+  const query = { search, sort }
+
   return request(url)
     .get(path)
-    .query({ search })
-    .query({ sort })
+    .query(query)
     .set('Accept', 'application/json')
-    .expect(200)
+    .expect(HttpStatusCode.OK_200)
     .expect('Content-Type', /json/)
 }
 
@@ -62,7 +50,7 @@ function advancedVideosSearch (url: string, options: VideosSearchQuery) {
     .get(path)
     .query(options)
     .set('Accept', 'application/json')
-    .expect(200)
+    .expect(HttpStatusCode.OK_200)
     .expect('Content-Type', /json/)
 }
 
@@ -72,6 +60,5 @@ export {
   searchVideo,
   advancedVideosSearch,
   searchVideoWithToken,
-  searchVideoWithPagination,
   searchVideoWithSort
 }