]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/api/check-params/videos-filter.ts
emit more specific status codes on video upload (#3423)
[github/Chocobozzz/PeerTube.git] / server / tests / api / check-params / videos-filter.ts
index e998c8a3dafcbb445f0eb2c1abfe1f26c9120353..2391584a7ba78bf81509cfe1344f1ac163a23dfd 100644 (file)
@@ -1,22 +1,20 @@
-/* tslint:disable:no-unused-expression */
+/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
 
-import * as chai from 'chai'
 import 'mocha'
 import {
+  cleanupTests,
   createUser,
-  flushTests,
-  killallServers,
+  flushAndRunServer,
   makeGetRequest,
-  runServer,
   ServerInfo,
   setAccessTokensToServers,
+  setDefaultVideoChannel,
   userLogin
-} from '../../../../shared/utils'
+} from '../../../../shared/extra-utils'
 import { UserRole } from '../../../../shared/models/users'
+import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
 
-const expect = chai.expect
-
-async function testEndpoints (server: ServerInfo, token: string, filter: string, statusCodeExpected: number) {
+async function testEndpoints (server: ServerInfo, token: string, filter: string, statusCodeExpected: HttpStatusCode) {
   const paths = [
     '/api/v1/video-channels/root_channel/videos',
     '/api/v1/accounts/root/videos',
@@ -47,25 +45,26 @@ describe('Test videos filters', function () {
   before(async function () {
     this.timeout(30000)
 
-    await flushTests()
-
-    server = await runServer(1)
+    server = await flushAndRunServer(1)
 
     await setAccessTokensToServers([ server ])
+    await setDefaultVideoChannel([ server ])
 
     const user = { username: 'user1', password: 'my super password' }
-    await createUser(server.url, server.accessToken, user.username, user.password)
+    await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
     userAccessToken = await userLogin(server, user)
 
     const moderator = { username: 'moderator', password: 'my super password' }
     await createUser(
-      server.url,
-      server.accessToken,
-      moderator.username,
-      moderator.password,
-      undefined,
-      undefined,
-      UserRole.MODERATOR
+      {
+        url: server.url,
+        accessToken: server.accessToken,
+        username: moderator.username,
+        password: moderator.password,
+        videoQuota: undefined,
+        videoQuotaDaily: undefined,
+        role: UserRole.MODERATOR
+      }
     )
     moderatorAccessToken = await userLogin(server, moderator)
   })
@@ -73,42 +72,47 @@ describe('Test videos filters', function () {
   describe('When setting a video filter', function () {
 
     it('Should fail with a bad filter', async function () {
-      await testEndpoints(server, server.accessToken, 'bad-filter', 400)
+      await testEndpoints(server, server.accessToken, 'bad-filter', HttpStatusCode.BAD_REQUEST_400)
     })
 
     it('Should succeed with a good filter', async function () {
-      await testEndpoints(server, server.accessToken,'local', 200)
+      await testEndpoints(server, server.accessToken, 'local', HttpStatusCode.OK_200)
     })
 
-    it('Should fail to list all-local with a simple user', async function () {
-      await testEndpoints(server, userAccessToken, 'all-local', 401)
+    it('Should fail to list all-local/all with a simple user', async function () {
+      await testEndpoints(server, userAccessToken, 'all-local', HttpStatusCode.UNAUTHORIZED_401)
+      await testEndpoints(server, userAccessToken, 'all', HttpStatusCode.UNAUTHORIZED_401)
     })
 
-    it('Should succeed to list all-local with a moderator', async function () {
-      await testEndpoints(server, moderatorAccessToken, 'all-local', 200)
+    it('Should succeed to list all-local/all with a moderator', async function () {
+      await testEndpoints(server, moderatorAccessToken, 'all-local', HttpStatusCode.OK_200)
+      await testEndpoints(server, moderatorAccessToken, 'all', HttpStatusCode.OK_200)
     })
 
-    it('Should succeed to list all-local with an admin', async function () {
-      await testEndpoints(server, server.accessToken, 'all-local', 200)
+    it('Should succeed to list all-local/all with an admin', async function () {
+      await testEndpoints(server, server.accessToken, 'all-local', HttpStatusCode.OK_200)
+      await testEndpoints(server, server.accessToken, 'all', HttpStatusCode.OK_200)
     })
 
     // Because we cannot authenticate the user on the RSS endpoint
-    it('Should fail on the feeds endpoint with the all-local filter', async function () {
-      await makeGetRequest({
-        url: server.url,
-        path: '/feeds/videos.json',
-        statusCodeExpected: 401,
-        query: {
-          filter: 'all-local'
-        }
-      })
+    it('Should fail on the feeds endpoint with the all-local/all filter', async function () {
+      for (const filter of [ 'all', 'all-local' ]) {
+        await makeGetRequest({
+          url: server.url,
+          path: '/feeds/videos.json',
+          statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401,
+          query: {
+            filter
+          }
+        })
+      }
     })
 
-    it('Should succed on the feeds endpoint with the local filter', async function () {
+    it('Should succeed on the feeds endpoint with the local filter', async function () {
       await makeGetRequest({
         url: server.url,
         path: '/feeds/videos.json',
-        statusCodeExpected: 200,
+        statusCodeExpected: HttpStatusCode.OK_200,
         query: {
           filter: 'local'
         }
@@ -117,11 +121,6 @@ describe('Test videos filters', function () {
   })
 
   after(async function () {
-    killallServers([ server ])
-
-    // Keep the logs if the test failed
-    if (this['ok']) {
-      await flushTests()
-    }
+    await cleanupTests([ server ])
   })
 })