]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/api/server/follow-constraints.ts
Refactor live manager
[github/Chocobozzz/PeerTube.git] / server / tests / api / server / follow-constraints.ts
index 46663bf7cb6e844bbf3ea3070e4a7da6de78a690..3f2f71f46762a32b54635025ef5aa7b10d9daac6 100644 (file)
@@ -1,4 +1,4 @@
-/* tslint:disable:no-unused-expression */
+/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
 
 import * as chai from 'chai'
 import 'mocha'
@@ -17,6 +17,8 @@ import {
 import { unfollow } from '../../../../shared/extra-utils/server/follows'
 import { userLogin } from '../../../../shared/extra-utils/users/login'
 import { createUser } from '../../../../shared/extra-utils/users/users'
+import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
+import { PeerTubeProblemDocument, ServerErrorCode } from '@shared/models'
 
 const expect = chai.expect
 
@@ -27,7 +29,7 @@ describe('Test follow constraints', function () {
   let userAccessToken: string
 
   before(async function () {
-    this.timeout(60000)
+    this.timeout(90000)
 
     servers = await flushAndRunMultipleServers(2)
 
@@ -35,11 +37,11 @@ describe('Test follow constraints', function () {
     await setAccessTokensToServers(servers)
 
     {
-      const res = await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, { name: 'video server 1' })
+      const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video server 1' })
       video1UUID = res.body.video.uuid
     }
     {
-      const res = await uploadVideo(servers[ 1 ].url, servers[ 1 ].accessToken, { name: 'video server 2' })
+      const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video server 2' })
       video2UUID = res.body.video.uuid
     }
 
@@ -47,7 +49,7 @@ describe('Test follow constraints', function () {
       username: 'user1',
       password: 'super_password'
     }
-    await createUser({ url: servers[ 0 ].url, accessToken: servers[ 0 ].accessToken, username: user.username, password: user.password })
+    await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password })
     userAccessToken = await userLogin(servers[0], user)
 
     await doubleFollow(servers[0], servers[1])
@@ -58,11 +60,11 @@ describe('Test follow constraints', function () {
     describe('With an unlogged user', function () {
 
       it('Should get the local video', async function () {
-        await getVideo(servers[0].url, video1UUID, 200)
+        await getVideo(servers[0].url, video1UUID, HttpStatusCode.OK_200)
       })
 
       it('Should get the remote video', async function () {
-        await getVideo(servers[0].url, video2UUID, 200)
+        await getVideo(servers[0].url, video2UUID, HttpStatusCode.OK_200)
       })
 
       it('Should list local account videos', async function () {
@@ -98,11 +100,11 @@ describe('Test follow constraints', function () {
 
     describe('With a logged user', function () {
       it('Should get the local video', async function () {
-        await getVideoWithToken(servers[0].url, userAccessToken, video1UUID, 200)
+        await getVideoWithToken(servers[0].url, userAccessToken, video1UUID, HttpStatusCode.OK_200)
       })
 
       it('Should get the remote video', async function () {
-        await getVideoWithToken(servers[0].url, userAccessToken, video2UUID, 200)
+        await getVideoWithToken(servers[0].url, userAccessToken, video2UUID, HttpStatusCode.OK_200)
       })
 
       it('Should list local account videos', async function () {
@@ -148,11 +150,24 @@ describe('Test follow constraints', function () {
     describe('With an unlogged user', function () {
 
       it('Should get the local video', async function () {
-        await getVideo(servers[0].url, video1UUID, 200)
+        await getVideo(servers[0].url, video1UUID, HttpStatusCode.OK_200)
       })
 
       it('Should not get the remote video', async function () {
-        await getVideo(servers[0].url, video2UUID, 403)
+        const res = await getVideo(servers[0].url, video2UUID, HttpStatusCode.FORBIDDEN_403)
+
+        const error = res.body as PeerTubeProblemDocument
+
+        const doc = 'https://docs.joinpeertube.org/api-rest-reference.html#section/Errors/does_not_respect_follow_constraints'
+        expect(error.type).to.equal(doc)
+        expect(error.code).to.equal(ServerErrorCode.DOES_NOT_RESPECT_FOLLOW_CONSTRAINTS)
+
+        expect(error.detail).to.equal('Cannot get this video regarding follow constraints')
+        expect(error.error).to.equal(error.detail)
+
+        expect(error.status).to.equal(HttpStatusCode.FORBIDDEN_403)
+
+        expect(error.originUrl).to.contains(servers[1].url)
       })
 
       it('Should list local account videos', async function () {
@@ -188,11 +203,11 @@ describe('Test follow constraints', function () {
 
     describe('With a logged user', function () {
       it('Should get the local video', async function () {
-        await getVideoWithToken(servers[0].url, userAccessToken, video1UUID, 200)
+        await getVideoWithToken(servers[0].url, userAccessToken, video1UUID, HttpStatusCode.OK_200)
       })
 
       it('Should get the remote video', async function () {
-        await getVideoWithToken(servers[0].url, userAccessToken, video2UUID, 200)
+        await getVideoWithToken(servers[0].url, userAccessToken, video2UUID, HttpStatusCode.OK_200)
       })
 
       it('Should list local account videos', async function () {