]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/api/users/user-subscriptions.ts
Fix tests
[github/Chocobozzz/PeerTube.git] / server / tests / api / users / user-subscriptions.ts
index 622cddb7db0b45cf26596eeacbf8609d1f3a0994..d1d19223853dbe3632335dc59508aca6084305de 100644 (file)
@@ -4,9 +4,9 @@ import 'mocha'
 import * as chai from 'chai'
 import {
   cleanupTests,
+  createMultipleServers,
   doubleFollow,
-  flushAndRunMultipleServers,
-  ServerInfo,
+  PeerTubeServer,
   setAccessTokensToServers,
   SubscriptionsCommand,
   waitJobs
@@ -15,16 +15,16 @@ import {
 const expect = chai.expect
 
 describe('Test users subscriptions', function () {
-  let servers: ServerInfo[] = []
+  let servers: PeerTubeServer[] = []
   const users: { accessToken: string }[] = []
   let video3UUID: string
 
   let command: SubscriptionsCommand
 
   before(async function () {
-    this.timeout(120000)
+    this.timeout(240000)
 
-    servers = await flushAndRunMultipleServers(3)
+    servers = await createMultipleServers(3)
 
     // Get the access tokens
     await setAccessTokensToServers(servers)
@@ -35,26 +35,26 @@ 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 server.videosCommand.upload({ token: accessToken, attributes: { name: videoName1 } })
+        await server.videos.upload({ token: accessToken, attributes: { name: videoName1 } })
 
         const videoName2 = 'video 2-' + server.serverNumber
-        await server.videosCommand.upload({ token: accessToken, attributes: { 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 { total } = await servers[0].videosCommand.list()
+    const { total } = await servers[0].videos.list()
 
     expect(total).to.equal(4)
   })
@@ -67,14 +67,15 @@ describe('Test users subscriptions', function () {
 
     await waitJobs(servers)
 
-    const { uuid } = await servers[2].videosCommand.upload({ attributes: { name: 'video server 3 added after follow' } })
+    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 { total, data } = await servers[0].videosCommand.list()
+    const { total, data } = await servers[0].videos.list()
     expect(total).to.equal(4)
 
     for (const video of data) {
@@ -183,7 +184,7 @@ describe('Test users subscriptions', function () {
     this.timeout(60000)
 
     const videoName = 'video server 1 added after follow'
-    await servers[0].videosCommand.upload({ attributes: { name: videoName } })
+    await servers[0].videos.upload({ attributes: { name: videoName } })
 
     await waitJobs(servers)
 
@@ -209,7 +210,7 @@ describe('Test users subscriptions', function () {
     }
 
     {
-      const { data, total } = await servers[0].videosCommand.list()
+      const { data, total } = await servers[0].videos.list()
       expect(total).to.equal(5)
 
       for (const video of data) {
@@ -223,11 +224,11 @@ 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 { data, total } = await servers[0].videosCommand.list()
+    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' ]
@@ -240,11 +241,11 @@ 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 { total, data } = await servers[0].videosCommand.list()
+    const { total, data } = await servers[0].videos.list()
     expect(total).to.equal(5)
 
     for (const video of data) {
@@ -280,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 servers[2].videosCommand.update({ id: video3UUID, attributes: { 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)
 
@@ -325,7 +326,7 @@ describe('Test users subscriptions', function () {
   })
 
   it('Should correctly display public videos on server 1', async function () {
-    const { total, data } = await servers[0].videosCommand.list()
+    const { total, data } = await servers[0].videos.list()
     expect(total).to.equal(5)
 
     for (const video of data) {
@@ -356,7 +357,7 @@ describe('Test users subscriptions', function () {
     }
 
     {
-      const { total, data } = await servers[0].videosCommand.list()
+      const { total, data } = await servers[0].videos.list()
       expect(total).to.equal(5)
 
       for (const video of data) {
@@ -367,6 +368,178 @@ describe('Test users subscriptions', function () {
     }
   })
 
+  it('Should follow user channels of server 3 by root of server 3', async function () {
+    this.timeout(60000)
+
+    await servers[2].channels.create({ token: users[2].accessToken, attributes: { name: 'user3_channel2' } })
+
+    await servers[2].subscriptions.add({ token: servers[2].accessToken, targetUri: 'user3_channel@localhost:' + servers[2].port })
+    await servers[2].subscriptions.add({ token: servers[2].accessToken, targetUri: 'user3_channel2@localhost:' + servers[2].port })
+
+    await waitJobs(servers)
+  })
+
+  it('Should list user 3 followers', async function () {
+    {
+      const { total, data } = await servers[2].accounts.listFollowers({
+        token: users[2].accessToken,
+        accountName: 'user3',
+        start: 0,
+        count: 5,
+        sort: 'createdAt'
+      })
+
+      expect(total).to.equal(3)
+      expect(data).to.have.lengthOf(3)
+
+      expect(data[0].following.host).to.equal(servers[2].host)
+      expect(data[0].following.name).to.equal('user3_channel')
+      expect(data[0].follower.host).to.equal(servers[0].host)
+      expect(data[0].follower.name).to.equal('user1')
+
+      expect(data[1].following.host).to.equal(servers[2].host)
+      expect(data[1].following.name).to.equal('user3_channel')
+      expect(data[1].follower.host).to.equal(servers[2].host)
+      expect(data[1].follower.name).to.equal('root')
+
+      expect(data[2].following.host).to.equal(servers[2].host)
+      expect(data[2].following.name).to.equal('user3_channel2')
+      expect(data[2].follower.host).to.equal(servers[2].host)
+      expect(data[2].follower.name).to.equal('root')
+    }
+
+    {
+      const { total, data } = await servers[2].accounts.listFollowers({
+        token: users[2].accessToken,
+        accountName: 'user3',
+        start: 0,
+        count: 1,
+        sort: '-createdAt'
+      })
+
+      expect(total).to.equal(3)
+      expect(data).to.have.lengthOf(1)
+
+      expect(data[0].following.host).to.equal(servers[2].host)
+      expect(data[0].following.name).to.equal('user3_channel2')
+      expect(data[0].follower.host).to.equal(servers[2].host)
+      expect(data[0].follower.name).to.equal('root')
+    }
+
+    {
+      const { total, data } = await servers[2].accounts.listFollowers({
+        token: users[2].accessToken,
+        accountName: 'user3',
+        start: 1,
+        count: 1,
+        sort: '-createdAt'
+      })
+
+      expect(total).to.equal(3)
+      expect(data).to.have.lengthOf(1)
+
+      expect(data[0].following.host).to.equal(servers[2].host)
+      expect(data[0].following.name).to.equal('user3_channel')
+      expect(data[0].follower.host).to.equal(servers[2].host)
+      expect(data[0].follower.name).to.equal('root')
+    }
+
+    {
+      const { total, data } = await servers[2].accounts.listFollowers({
+        token: users[2].accessToken,
+        accountName: 'user3',
+        search: 'user1',
+        sort: '-createdAt'
+      })
+
+      expect(total).to.equal(1)
+      expect(data).to.have.lengthOf(1)
+
+      expect(data[0].following.host).to.equal(servers[2].host)
+      expect(data[0].following.name).to.equal('user3_channel')
+      expect(data[0].follower.host).to.equal(servers[0].host)
+      expect(data[0].follower.name).to.equal('user1')
+    }
+  })
+
+  it('Should list user3_channel followers', async function () {
+    {
+      const { total, data } = await servers[2].channels.listFollowers({
+        token: users[2].accessToken,
+        channelName: 'user3_channel',
+        start: 0,
+        count: 5,
+        sort: 'createdAt'
+      })
+
+      expect(total).to.equal(2)
+      expect(data).to.have.lengthOf(2)
+
+      expect(data[0].following.host).to.equal(servers[2].host)
+      expect(data[0].following.name).to.equal('user3_channel')
+      expect(data[0].follower.host).to.equal(servers[0].host)
+      expect(data[0].follower.name).to.equal('user1')
+
+      expect(data[1].following.host).to.equal(servers[2].host)
+      expect(data[1].following.name).to.equal('user3_channel')
+      expect(data[1].follower.host).to.equal(servers[2].host)
+      expect(data[1].follower.name).to.equal('root')
+    }
+
+    {
+      const { total, data } = await servers[2].channels.listFollowers({
+        token: users[2].accessToken,
+        channelName: 'user3_channel',
+        start: 0,
+        count: 1,
+        sort: '-createdAt'
+      })
+
+      expect(total).to.equal(2)
+      expect(data).to.have.lengthOf(1)
+
+      expect(data[0].following.host).to.equal(servers[2].host)
+      expect(data[0].following.name).to.equal('user3_channel')
+      expect(data[0].follower.host).to.equal(servers[2].host)
+      expect(data[0].follower.name).to.equal('root')
+    }
+
+    {
+      const { total, data } = await servers[2].channels.listFollowers({
+        token: users[2].accessToken,
+        channelName: 'user3_channel',
+        start: 1,
+        count: 1,
+        sort: '-createdAt'
+      })
+
+      expect(total).to.equal(2)
+      expect(data).to.have.lengthOf(1)
+
+      expect(data[0].following.host).to.equal(servers[2].host)
+      expect(data[0].following.name).to.equal('user3_channel')
+      expect(data[0].follower.host).to.equal(servers[0].host)
+      expect(data[0].follower.name).to.equal('user1')
+    }
+
+    {
+      const { total, data } = await servers[2].channels.listFollowers({
+        token: users[2].accessToken,
+        channelName: 'user3_channel',
+        search: 'user1',
+        sort: '-createdAt'
+      })
+
+      expect(total).to.equal(1)
+      expect(data).to.have.lengthOf(1)
+
+      expect(data[0].following.host).to.equal(servers[2].host)
+      expect(data[0].following.name).to.equal('user3_channel')
+      expect(data[0].follower.host).to.equal(servers[0].host)
+      expect(data[0].follower.name).to.equal('user1')
+    }
+  })
+
   after(async function () {
     await cleanupTests(servers)
   })