]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/api/server/follow-constraints.ts
Merge branch 'release/4.2.0' into develop
[github/Chocobozzz/PeerTube.git] / server / tests / api / server / follow-constraints.ts
index f9014aeeee8f5af8dbf4a2eebe393e2a52767f93..455fbc76298c12f9961c7b6b04583c3e82c35d7a 100644 (file)
@@ -2,32 +2,31 @@
 
 import 'mocha'
 import * as chai from 'chai'
-import { HttpStatusCode } from '@shared/core-utils'
-import { cleanupTests, doubleFollow, flushAndRunMultipleServers, ServerInfo, setAccessTokensToServers } from '@shared/extra-utils'
-import { PeerTubeProblemDocument, ServerErrorCode } from '@shared/models'
+import { cleanupTests, createMultipleServers, doubleFollow, PeerTubeServer, setAccessTokensToServers } from '@shared/server-commands'
+import { HttpStatusCode, PeerTubeProblemDocument, ServerErrorCode } from '@shared/models'
 
 const expect = chai.expect
 
 describe('Test follow constraints', function () {
-  let servers: ServerInfo[] = []
+  let servers: PeerTubeServer[] = []
   let video1UUID: string
   let video2UUID: string
   let userToken: string
 
   before(async function () {
-    this.timeout(90000)
+    this.timeout(240000)
 
-    servers = await flushAndRunMultipleServers(2)
+    servers = await createMultipleServers(2)
 
     // Get the access tokens
     await setAccessTokensToServers(servers)
 
     {
-      const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'video server 1' } })
+      const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video server 1' } })
       video1UUID = uuid
     }
     {
-      const { uuid } = await servers[1].videosCommand.upload({ attributes: { name: 'video server 2' } })
+      const { uuid } = await servers[1].videos.upload({ attributes: { name: 'video server 2' } })
       video2UUID = uuid
     }
 
@@ -35,8 +34,8 @@ describe('Test follow constraints', function () {
       username: 'user1',
       password: 'super_password'
     }
-    await servers[0].usersCommand.create({ username: user.username, password: user.password })
-    userToken = await servers[0].loginCommand.getAccessToken(user)
+    await servers[0].users.create({ username: user.username, password: user.password })
+    userToken = await servers[0].login.getAccessToken(user)
 
     await doubleFollow(servers[0], servers[1])
   })
@@ -46,38 +45,38 @@ describe('Test follow constraints', function () {
     describe('With an unlogged user', function () {
 
       it('Should get the local video', async function () {
-        await servers[0].videosCommand.get({ id: video1UUID })
+        await servers[0].videos.get({ id: video1UUID })
       })
 
       it('Should get the remote video', async function () {
-        await servers[0].videosCommand.get({ id: video2UUID })
+        await servers[0].videos.get({ id: video2UUID })
       })
 
       it('Should list local account videos', async function () {
-        const { total, data } = await servers[0].videosCommand.listByAccount({ accountName: 'root@localhost:' + servers[0].port })
+        const { total, data } = await servers[0].videos.listByAccount({ handle: 'root@localhost:' + servers[0].port })
 
         expect(total).to.equal(1)
         expect(data).to.have.lengthOf(1)
       })
 
       it('Should list remote account videos', async function () {
-        const { total, data } = await servers[0].videosCommand.listByAccount({ accountName: 'root@localhost:' + servers[1].port })
+        const { total, data } = await servers[0].videos.listByAccount({ handle: 'root@localhost:' + servers[1].port })
 
         expect(total).to.equal(1)
         expect(data).to.have.lengthOf(1)
       })
 
       it('Should list local channel videos', async function () {
-        const videoChannelName = 'root_channel@localhost:' + servers[0].port
-        const { total, data } = await servers[0].videosCommand.listByChannel({ videoChannelName })
+        const handle = 'root_channel@localhost:' + servers[0].port
+        const { total, data } = await servers[0].videos.listByChannel({ handle })
 
         expect(total).to.equal(1)
         expect(data).to.have.lengthOf(1)
       })
 
       it('Should list remote channel videos', async function () {
-        const videoChannelName = 'root_channel@localhost:' + servers[1].port
-        const { total, data } = await servers[0].videosCommand.listByChannel({ videoChannelName })
+        const handle = 'root_channel@localhost:' + servers[1].port
+        const { total, data } = await servers[0].videos.listByChannel({ handle })
 
         expect(total).to.equal(1)
         expect(data).to.have.lengthOf(1)
@@ -86,38 +85,38 @@ describe('Test follow constraints', function () {
 
     describe('With a logged user', function () {
       it('Should get the local video', async function () {
-        await servers[0].videosCommand.getWithToken({ token: userToken, id: video1UUID })
+        await servers[0].videos.getWithToken({ token: userToken, id: video1UUID })
       })
 
       it('Should get the remote video', async function () {
-        await servers[0].videosCommand.getWithToken({ token: userToken, id: video2UUID })
+        await servers[0].videos.getWithToken({ token: userToken, id: video2UUID })
       })
 
       it('Should list local account videos', async function () {
-        const { total, data } = await servers[0].videosCommand.listByAccount({ token: userToken, accountName: 'root@localhost:' + servers[0].port })
+        const { total, data } = await servers[0].videos.listByAccount({ token: userToken, handle: 'root@localhost:' + servers[0].port })
 
         expect(total).to.equal(1)
         expect(data).to.have.lengthOf(1)
       })
 
       it('Should list remote account videos', async function () {
-        const { total, data } = await servers[0].videosCommand.listByAccount({ token: userToken, accountName: 'root@localhost:' + servers[1].port })
+        const { total, data } = await servers[0].videos.listByAccount({ token: userToken, handle: 'root@localhost:' + servers[1].port })
 
         expect(total).to.equal(1)
         expect(data).to.have.lengthOf(1)
       })
 
       it('Should list local channel videos', async function () {
-        const videoChannelName = 'root_channel@localhost:' + servers[0].port
-        const { total, data } = await servers[0].videosCommand.listByChannel({ token: userToken, videoChannelName })
+        const handle = 'root_channel@localhost:' + servers[0].port
+        const { total, data } = await servers[0].videos.listByChannel({ token: userToken, handle })
 
         expect(total).to.equal(1)
         expect(data).to.have.lengthOf(1)
       })
 
       it('Should list remote channel videos', async function () {
-        const videoChannelName = 'root_channel@localhost:' + servers[1].port
-        const { total, data } = await servers[0].videosCommand.listByChannel({ token: userToken, videoChannelName })
+        const handle = 'root_channel@localhost:' + servers[1].port
+        const { total, data } = await servers[0].videos.listByChannel({ token: userToken, handle })
 
         expect(total).to.equal(1)
         expect(data).to.have.lengthOf(1)
@@ -130,17 +129,17 @@ describe('Test follow constraints', function () {
     before(async function () {
       this.timeout(30000)
 
-      await servers[0].followsCommand.unfollow({ target: servers[1] })
+      await servers[0].follows.unfollow({ target: servers[1] })
     })
 
     describe('With an unlogged user', function () {
 
       it('Should get the local video', async function () {
-        await servers[0].videosCommand.get({ id: video1UUID })
+        await servers[0].videos.get({ id: video1UUID })
       })
 
       it('Should not get the remote video', async function () {
-        const body = await servers[0].videosCommand.get({ id: video2UUID, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
+        const body = await servers[0].videos.get({ id: video2UUID, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
         const error = body as unknown as PeerTubeProblemDocument
 
         const doc = 'https://docs.joinpeertube.org/api-rest-reference.html#section/Errors/does_not_respect_follow_constraints'
@@ -156,9 +155,9 @@ describe('Test follow constraints', function () {
       })
 
       it('Should list local account videos', async function () {
-        const { total, data } = await servers[0].videosCommand.listByAccount({
-          token: undefined,
-          accountName: 'root@localhost:' + servers[0].port
+        const { total, data } = await servers[0].videos.listByAccount({
+          token: null,
+          handle: 'root@localhost:' + servers[0].port
         })
 
         expect(total).to.equal(1)
@@ -166,9 +165,9 @@ describe('Test follow constraints', function () {
       })
 
       it('Should not list remote account videos', async function () {
-        const { total, data } = await servers[0].videosCommand.listByAccount({
-          token: undefined,
-          accountName: 'root@localhost:' + servers[1].port
+        const { total, data } = await servers[0].videos.listByAccount({
+          token: null,
+          handle: 'root@localhost:' + servers[1].port
         })
 
         expect(total).to.equal(0)
@@ -176,16 +175,16 @@ describe('Test follow constraints', function () {
       })
 
       it('Should list local channel videos', async function () {
-        const videoChannelName = 'root_channel@localhost:' + servers[0].port
-        const { total, data } = await servers[0].videosCommand.listByChannel({ token: undefined, videoChannelName })
+        const handle = 'root_channel@localhost:' + servers[0].port
+        const { total, data } = await servers[0].videos.listByChannel({ token: null, handle })
 
         expect(total).to.equal(1)
         expect(data).to.have.lengthOf(1)
       })
 
       it('Should not list remote channel videos', async function () {
-        const videoChannelName = 'root_channel@localhost:' + servers[1].port
-        const { total, data } = await servers[0].videosCommand.listByChannel({ token: undefined, videoChannelName })
+        const handle = 'root_channel@localhost:' + servers[1].port
+        const { total, data } = await servers[0].videos.listByChannel({ token: null, handle })
 
         expect(total).to.equal(0)
         expect(data).to.have.lengthOf(0)
@@ -194,38 +193,38 @@ describe('Test follow constraints', function () {
 
     describe('With a logged user', function () {
       it('Should get the local video', async function () {
-        await servers[0].videosCommand.getWithToken({ token: userToken, id: video1UUID })
+        await servers[0].videos.getWithToken({ token: userToken, id: video1UUID })
       })
 
       it('Should get the remote video', async function () {
-        await servers[0].videosCommand.getWithToken({ token: userToken, id: video2UUID })
+        await servers[0].videos.getWithToken({ token: userToken, id: video2UUID })
       })
 
       it('Should list local account videos', async function () {
-        const { total, data } = await servers[0].videosCommand.listByAccount({ token: userToken, accountName: 'root@localhost:' + servers[0].port })
+        const { total, data } = await servers[0].videos.listByAccount({ token: userToken, handle: 'root@localhost:' + servers[0].port })
 
         expect(total).to.equal(1)
         expect(data).to.have.lengthOf(1)
       })
 
       it('Should list remote account videos', async function () {
-        const { total, data } = await servers[0].videosCommand.listByAccount({ token: userToken, accountName: 'root@localhost:' + servers[1].port })
+        const { total, data } = await servers[0].videos.listByAccount({ token: userToken, handle: 'root@localhost:' + servers[1].port })
 
         expect(total).to.equal(1)
         expect(data).to.have.lengthOf(1)
       })
 
       it('Should list local channel videos', async function () {
-        const videoChannelName = 'root_channel@localhost:' + servers[0].port
-        const { total, data } = await servers[0].videosCommand.listByChannel({ token: userToken, videoChannelName })
+        const handle = 'root_channel@localhost:' + servers[0].port
+        const { total, data } = await servers[0].videos.listByChannel({ token: userToken, handle })
 
         expect(total).to.equal(1)
         expect(data).to.have.lengthOf(1)
       })
 
       it('Should list remote channel videos', async function () {
-        const videoChannelName = 'root_channel@localhost:' + servers[1].port
-        const { total, data } = await servers[0].videosCommand.listByChannel({ token: userToken, videoChannelName })
+        const handle = 'root_channel@localhost:' + servers[1].port
+        const { total, data } = await servers[0].videos.listByChannel({ token: userToken, handle })
 
         expect(total).to.equal(1)
         expect(data).to.have.lengthOf(1)