]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/api/utils.js
Extends the search feature by customizing the search field (name,
[github/Chocobozzz/PeerTube.git] / server / tests / api / utils.js
index d505cb5d9d5728e0a1a5ca913551f887ef0c8659..c6430c930612cd020b3f1e5f57f0a7bf1db7e941 100644 (file)
@@ -14,6 +14,7 @@ const testUtils = {
   getVideo: getVideo,
   getVideosList: getVideosList,
   getVideosListPagination: getVideosListPagination,
+  getVideosListSort: getVideosListSort,
   login: login,
   loginAndGetAccessToken: loginAndGetAccessToken,
   makeFriends: makeFriends,
@@ -23,6 +24,7 @@ const testUtils = {
   runServer: runServer,
   searchVideo: searchVideo,
   searchVideoWithPagination: searchVideoWithPagination,
+  searchVideoWithSort: searchVideoWithSort,
   testImage: testImage,
   uploadVideo: uploadVideo
 }
@@ -70,6 +72,7 @@ function getVideosList (url, end) {
 
   request(url)
     .get(path)
+    .query({ sort: 'name' })
     .set('Accept', 'application/json')
     .expect(200)
     .expect('Content-Type', /json/)
@@ -89,6 +92,18 @@ function getVideosListPagination (url, start, count, end) {
     .end(end)
 }
 
+function getVideosListSort (url, sort, end) {
+  const path = '/api/v1/videos'
+
+  request(url)
+    .get(path)
+    .query({ sort: sort })
+    .set('Accept', 'application/json')
+    .expect(200)
+    .expect('Content-Type', /json/)
+    .end(end)
+}
+
 function login (url, client, user, expectedStatus, end) {
   if (!end) {
     end = expectedStatus
@@ -276,24 +291,43 @@ function runServer (number, callback) {
   })
 }
 
-function searchVideo (url, search, end) {
+function searchVideo (url, search, field, end) {
+  if (!end) {
+    end = field
+    field = null
+  }
+
+  const path = '/api/v1/videos'
+  const req = request(url)
+              .get(path + '/search/' + search)
+              .set('Accept', 'application/json')
+
+  if (field) req.query({ field: field })
+  req.expect(200)
+     .expect('Content-Type', /json/)
+     .end(end)
+}
+
+function searchVideoWithPagination (url, search, field, start, count, end) {
   const path = '/api/v1/videos'
 
   request(url)
     .get(path + '/search/' + search)
+    .query({ start: start })
+    .query({ count: count })
+    .query({ field: field })
     .set('Accept', 'application/json')
     .expect(200)
     .expect('Content-Type', /json/)
     .end(end)
 }
 
-function searchVideoWithPagination (url, search, start, count, end) {
+function searchVideoWithSort (url, search, sort, end) {
   const path = '/api/v1/videos'
 
   request(url)
     .get(path + '/search/' + search)
-    .query({ start: start })
-    .query({ count: count })
+    .query({ sort: sort })
     .set('Accept', 'application/json')
     .expect(200)
     .expect('Content-Type', /json/)