]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/api/users/user-subscriptions.ts
Add ability for instances to follow any actor
[github/Chocobozzz/PeerTube.git] / server / tests / api / users / user-subscriptions.ts
index c09a85a323a208e6eaa4cd909063ed1b4d1a5b6d..77b99886d24208a976d63f782ae25c2edd564ea6 100644 (file)
@@ -4,21 +4,18 @@ import 'mocha'
 import * as chai from 'chai'
 import {
   cleanupTests,
+  createMultipleServers,
   doubleFollow,
-  flushAndRunMultipleServers,
-  getVideosList,
-  ServerInfo,
+  PeerTubeServer,
   setAccessTokensToServers,
   SubscriptionsCommand,
-  updateVideo,
-  uploadVideo,
   waitJobs
 } from '@shared/extra-utils'
 
 const expect = chai.expect
 
 describe('Test users subscriptions', function () {
-  let servers: ServerInfo[] = []
+  let servers: PeerTubeServer[] = []
   const users: { accessToken: string }[] = []
   let video3UUID: string
 
@@ -27,7 +24,7 @@ describe('Test users subscriptions', function () {
   before(async function () {
     this.timeout(120000)
 
-    servers = await flushAndRunMultipleServers(3)
+    servers = await createMultipleServers(3)
 
     // Get the access tokens
     await setAccessTokensToServers(servers)
@@ -38,28 +35,28 @@ describe('Test users subscriptions', function () {
     {
       for (const server of servers) {
         const user = { username: 'user' + server.serverNumber, password: 'password' }
-        await server.usersCommand.create({ username: user.username, password: user.password })
+        await server.users.create({ username: user.username, password: user.password })
 
-        const accessToken = await server.loginCommand.getAccessToken(user)
+        const accessToken = await server.login.getAccessToken(user)
         users.push({ accessToken })
 
         const videoName1 = 'video 1-' + server.serverNumber
-        await uploadVideo(server.url, accessToken, { name: videoName1 })
+        await server.videos.upload({ token: accessToken, attributes: { name: videoName1 } })
 
         const videoName2 = 'video 2-' + server.serverNumber
-        await uploadVideo(server.url, accessToken, { name: videoName2 })
+        await server.videos.upload({ token: accessToken, attributes: { name: videoName2 } })
       }
     }
 
     await waitJobs(servers)
 
-    command = servers[0].subscriptionsCommand
+    command = servers[0].subscriptions
   })
 
   it('Should display videos of server 2 on server 1', async function () {
-    const res = await getVideosList(servers[0].url)
+    const { total } = await servers[0].videos.list()
 
-    expect(res.body.total).to.equal(4)
+    expect(total).to.equal(4)
   })
 
   it('User of server 1 should follow user of server 3 and root of server 1', async function () {
@@ -70,17 +67,18 @@ describe('Test users subscriptions', function () {
 
     await waitJobs(servers)
 
-    const res = await uploadVideo(servers[2].url, users[2].accessToken, { name: 'video server 3 added after follow' })
-    video3UUID = res.body.video.uuid
+    const attributes = { name: 'video server 3 added after follow' }
+    const { uuid } = await servers[2].videos.upload({ token: users[2].accessToken, attributes })
+    video3UUID = uuid
 
     await waitJobs(servers)
   })
 
   it('Should not display videos of server 3 on server 1', async function () {
-    const res = await getVideosList(servers[0].url)
+    const { total, data } = await servers[0].videos.list()
+    expect(total).to.equal(4)
 
-    expect(res.body.total).to.equal(4)
-    for (const video of res.body.data) {
+    for (const video of data) {
       expect(video.name).to.not.contain('1-3')
       expect(video.name).to.not.contain('2-3')
       expect(video.name).to.not.contain('video server 3 added after follow')
@@ -186,7 +184,7 @@ describe('Test users subscriptions', function () {
     this.timeout(60000)
 
     const videoName = 'video server 1 added after follow'
-    await uploadVideo(servers[0].url, servers[0].accessToken, { name: videoName })
+    await servers[0].videos.upload({ attributes: { name: videoName } })
 
     await waitJobs(servers)
 
@@ -212,10 +210,10 @@ describe('Test users subscriptions', function () {
     }
 
     {
-      const res = await getVideosList(servers[0].url)
+      const { data, total } = await servers[0].videos.list()
+      expect(total).to.equal(5)
 
-      expect(res.body.total).to.equal(5)
-      for (const video of res.body.data) {
+      for (const video of data) {
         expect(video.name).to.not.contain('1-3')
         expect(video.name).to.not.contain('2-3')
         expect(video.name).to.not.contain('video server 3 added after follow')
@@ -226,17 +224,16 @@ describe('Test users subscriptions', function () {
   it('Should have server 1 follow server 3 and display server 3 videos', async function () {
     this.timeout(60000)
 
-    await servers[0].followsCommand.follow({ targets: [ servers[2].url ] })
+    await servers[0].follows.follow({ hosts: [ servers[2].url ] })
 
     await waitJobs(servers)
 
-    const res = await getVideosList(servers[0].url)
-
-    expect(res.body.total).to.equal(8)
+    const { data, total } = await servers[0].videos.list()
+    expect(total).to.equal(8)
 
     const names = [ '1-3', '2-3', 'video server 3 added after follow' ]
     for (const name of names) {
-      const video = res.body.data.find(v => v.name.indexOf(name) === -1)
+      const video = data.find(v => v.name.includes(name))
       expect(video).to.not.be.undefined
     }
   })
@@ -244,14 +241,14 @@ describe('Test users subscriptions', function () {
   it('Should remove follow server 1 -> server 3 and hide server 3 videos', async function () {
     this.timeout(60000)
 
-    await servers[0].followsCommand.unfollow({ target: servers[2] })
+    await servers[0].follows.unfollow({ target: servers[2] })
 
     await waitJobs(servers)
 
-    const res = await getVideosList(servers[0].url)
+    const { total, data } = await servers[0].videos.list()
+    expect(total).to.equal(5)
 
-    expect(res.body.total).to.equal(5)
-    for (const video of res.body.data) {
+    for (const video of data) {
       expect(video.name).to.not.contain('1-3')
       expect(video.name).to.not.contain('2-3')
       expect(video.name).to.not.contain('video server 3 added after follow')
@@ -284,7 +281,7 @@ describe('Test users subscriptions', function () {
   it('Should update a video of server 3 and see the updated video on server 1', async function () {
     this.timeout(30000)
 
-    await updateVideo(servers[2].url, users[2].accessToken, video3UUID, { name: 'video server 3 added after follow updated' })
+    await servers[2].videos.update({ id: video3UUID, attributes: { name: 'video server 3 added after follow updated' } })
 
     await waitJobs(servers)
 
@@ -329,10 +326,10 @@ describe('Test users subscriptions', function () {
   })
 
   it('Should correctly display public videos on server 1', async function () {
-    const res = await getVideosList(servers[0].url)
+    const { total, data } = await servers[0].videos.list()
+    expect(total).to.equal(5)
 
-    expect(res.body.total).to.equal(5)
-    for (const video of res.body.data) {
+    for (const video of data) {
       expect(video.name).to.not.contain('1-3')
       expect(video.name).to.not.contain('2-3')
       expect(video.name).to.not.contain('video server 3 added after follow updated')
@@ -360,10 +357,10 @@ describe('Test users subscriptions', function () {
     }
 
     {
-      const res = await getVideosList(servers[0].url)
+      const { total, data } = await servers[0].videos.list()
+      expect(total).to.equal(5)
 
-      expect(res.body.total).to.equal(5)
-      for (const video of res.body.data) {
+      for (const video of data) {
         expect(video.name).to.not.contain('1-3')
         expect(video.name).to.not.contain('2-3')
         expect(video.name).to.not.contain('video server 3 added after follow updated')