]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/api/check-params/jobs.ts
Add check params account ratings tests
[github/Chocobozzz/PeerTube.git] / server / tests / api / check-params / jobs.ts
index 3795d1d64d8dbfea0dfebebb9dedda6891d8f808..89760ff98b097891117ef4eef653d358b28f3ba7 100644 (file)
@@ -1,12 +1,25 @@
 /* tslint:disable:no-unused-expression */
 
 import 'mocha'
-import * as request from 'supertest'
 
-import { createUser, flushTests, userLogin, killallServers, runServer, ServerInfo, setAccessTokensToServers } from '../../utils'
+import {
+  createUser,
+  flushTests,
+  killallServers,
+  runServer,
+  ServerInfo,
+  setAccessTokensToServers,
+  userLogin
+} from '../../../../shared/utils'
+import {
+  checkBadCountPagination,
+  checkBadSortPagination,
+  checkBadStartPagination
+} from '../../../../shared/utils/requests/check-api-params'
+import { makeGetRequest } from '../../../../shared/utils/requests/requests'
 
 describe('Test jobs API validators', function () {
-  const path = '/api/v1/jobs/'
+  const path = '/api/v1/jobs/failed'
   let server: ServerInfo
   let userAccessToken = ''
 
@@ -30,46 +43,42 @@ describe('Test jobs API validators', function () {
   })
 
   describe('When listing jobs', function () {
+
+    it('Should fail with a bad state', async function () {
+      await makeGetRequest({
+        url: server.url,
+        token: server.accessToken,
+        path: path + 'ade'
+      })
+    })
+
     it('Should fail with a bad start pagination', async function () {
-      await request(server.url)
-              .get(path)
-              .query({ start: 'hello' })
-              .set('Accept', 'application/json')
-              .set('Authorization', 'Bearer ' + server.accessToken)
-              .expect(400)
+      await checkBadStartPagination(server.url, path, server.accessToken)
     })
 
     it('Should fail with a bad count pagination', async function () {
-      await request(server.url)
-              .get(path)
-              .query({ count: 'hello' })
-              .set('Accept', 'application/json')
-              .set('Authorization', 'Bearer ' + server.accessToken)
-              .expect(400)
+      await checkBadCountPagination(server.url, path, server.accessToken)
     })
 
     it('Should fail with an incorrect sort', async function () {
-      await request(server.url)
-              .get(path)
-              .query({ sort: 'hello' })
-              .set('Accept', 'application/json')
-              .set('Authorization', 'Bearer ' + server.accessToken)
-              .expect(400)
+      await checkBadSortPagination(server.url, path, server.accessToken)
     })
 
     it('Should fail with a non authenticated user', async function () {
-      await request(server.url)
-        .get(path)
-        .set('Accept', 'application/json')
-        .expect(401)
+      await makeGetRequest({
+        url: server.url,
+        path,
+        statusCodeExpected: 401
+      })
     })
 
     it('Should fail with a non admin user', async function () {
-      await request(server.url)
-        .get(path)
-        .set('Accept', 'application/json')
-        .set('Authorization', 'Bearer ' + userAccessToken)
-        .expect(403)
+      await makeGetRequest({
+        url: server.url,
+        path,
+        token: userAccessToken,
+        statusCodeExpected: 403
+      })
     })
   })