]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/api/users/users-multiple-servers.ts
Remove low timeouts
[github/Chocobozzz/PeerTube.git] / server / tests / api / users / users-multiple-servers.ts
index e304e5d67f6d5331dd87da64f0f5ebc75bbc187b..3823b74eff6a713c11b1d7dc38a3f75e178f03e7 100644 (file)
@@ -1,30 +1,33 @@
 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
 
-import 'mocha'
-import * as chai from 'chai'
+import { expect } from 'chai'
 import {
   checkActorFilesWereRemoved,
   checkTmpIsEmpty,
   checkVideoFilesWereRemoved,
+  saveVideoInServers,
+  testImage
+} from '@server/tests/shared'
+import { MyUser } from '@shared/models'
+import {
   cleanupTests,
-  doubleFollow,
   createMultipleServers,
+  doubleFollow,
   PeerTubeServer,
   setAccessTokensToServers,
-  testImage,
+  setDefaultChannelAvatar,
   waitJobs
-} from '@shared/extra-utils'
-import { User } from '@shared/models'
-
-const expect = chai.expect
+} from '@shared/server-commands'
 
 describe('Test users with multiple servers', function () {
   let servers: PeerTubeServer[] = []
-  let user: User
+
+  let user: MyUser
   let userId: number
+
   let videoUUID: string
   let userAccessToken: string
-  let userAvatarFilename: string
+  let userAvatarFilenames: string[]
 
   before(async function () {
     this.timeout(120_000)
@@ -33,6 +36,7 @@ describe('Test users with multiple servers', function () {
 
     // Get the access tokens
     await setAccessTokensToServers(servers)
+    await setDefaultChannelAvatar(servers)
 
     // Server 1 and server 2 follow each other
     await doubleFollow(servers[0], servers[1])
@@ -45,26 +49,23 @@ describe('Test users with multiple servers', function () {
     await servers[0].videos.upload()
 
     {
-      const user = {
-        username: 'user1',
-        password: 'password'
-      }
-      const created = await servers[0].users.create(user)
+      const username = 'user1'
+      const created = await servers[0].users.create({ username })
       userId = created.id
-      userAccessToken = await servers[0].login.getAccessToken(user)
+      userAccessToken = await servers[0].login.getAccessToken(username)
     }
 
     {
       const { uuid } = await servers[0].videos.upload({ token: userAccessToken })
       videoUUID = uuid
-    }
 
-    await waitJobs(servers)
+      await waitJobs(servers)
+
+      await saveVideoInServers(servers, videoUUID)
+    }
   })
 
   it('Should be able to update my display name', async function () {
-    this.timeout(10000)
-
     await servers[0].users.updateMe({ displayName: 'my super display name' })
 
     user = await servers[0].users.getMyInfo()
@@ -93,9 +94,11 @@ describe('Test users with multiple servers', function () {
     await servers[0].users.updateMyAvatar({ fixture })
 
     user = await servers[0].users.getMyInfo()
-    userAvatarFilename = user.account.avatar.path
+    userAvatarFilenames = user.account.avatars.map(({ path }) => path)
 
-    await testImage(servers[0].url, 'avatar2-resized', userAvatarFilename, '.png')
+    for (const avatar of user.account.avatars) {
+      await testImage(servers[0].url, `avatar2-resized-${avatar.width}x${avatar.width}`, avatar.path, '.png')
+    }
 
     await waitJobs(servers)
   })
@@ -106,7 +109,7 @@ describe('Test users with multiple servers', function () {
     for (const server of servers) {
       const body = await server.accounts.list({ sort: '-createdAt' })
 
-      const resList = body.data.find(a => a.name === 'root' && a.host === 'localhost:' + servers[0].port)
+      const resList = body.data.find(a => a.name === 'root' && a.host === servers[0].host)
       expect(resList).not.to.be.undefined
 
       const account = await server.accounts.get({ accountName: resList.name + '@' + resList.host })
@@ -114,7 +117,7 @@ describe('Test users with multiple servers', function () {
       if (!createdAt) createdAt = account.createdAt
 
       expect(account.name).to.equal('root')
-      expect(account.host).to.equal('localhost:' + servers[0].port)
+      expect(account.host).to.equal(servers[0].host)
       expect(account.displayName).to.equal('my super display name')
       expect(account.description).to.equal('my super description updated')
       expect(createdAt).to.equal(account.createdAt)
@@ -125,13 +128,15 @@ describe('Test users with multiple servers', function () {
         expect(account.userId).to.be.undefined
       }
 
-      await testImage(server.url, 'avatar2-resized', account.avatar.path, '.png')
+      for (const avatar of account.avatars) {
+        await testImage(server.url, `avatar2-resized-${avatar.width}x${avatar.width}`, avatar.path, '.png')
+      }
     }
   })
 
   it('Should list account videos', async function () {
     for (const server of servers) {
-      const { total, data } = await server.videos.listByAccount({ handle: 'user1@localhost:' + servers[0].port })
+      const { total, data } = await server.videos.listByAccount({ handle: 'user1@' + servers[0].host })
 
       expect(total).to.equal(1)
       expect(data).to.be.an('array')
@@ -141,14 +146,12 @@ describe('Test users with multiple servers', function () {
   })
 
   it('Should search through account videos', async function () {
-    this.timeout(10_000)
-
     const created = await servers[0].videos.upload({ token: userAccessToken, attributes: { name: 'Kami no chikara' } })
 
     await waitJobs(servers)
 
     for (const server of servers) {
-      const { total, data } = await server.videos.listByAccount({ handle: 'user1@localhost:' + servers[0].port, search: 'Kami' })
+      const { total, data } = await server.videos.listByAccount({ handle: 'user1@' + servers[0].host, search: 'Kami' })
 
       expect(total).to.equal(1)
       expect(data).to.be.an('array')
@@ -163,11 +166,11 @@ describe('Test users with multiple servers', function () {
     for (const server of servers) {
       const body = await server.accounts.list({ sort: '-createdAt' })
 
-      const accountDeleted = body.data.find(a => a.name === 'user1' && a.host === 'localhost:' + servers[0].port)
+      const accountDeleted = body.data.find(a => a.name === 'user1' && a.host === servers[0].host)
       expect(accountDeleted).not.to.be.undefined
 
       const { data } = await server.channels.list()
-      const videoChannelDeleted = data.find(a => a.displayName === 'Main user1 channel' && a.host === 'localhost:' + servers[0].port)
+      const videoChannelDeleted = data.find(a => a.displayName === 'Main user1 channel' && a.host === servers[0].host)
       expect(videoChannelDeleted).not.to.be.undefined
     }
 
@@ -178,24 +181,26 @@ describe('Test users with multiple servers', function () {
     for (const server of servers) {
       const body = await server.accounts.list({ sort: '-createdAt' })
 
-      const accountDeleted = body.data.find(a => a.name === 'user1' && a.host === 'localhost:' + servers[0].port)
+      const accountDeleted = body.data.find(a => a.name === 'user1' && a.host === servers[0].host)
       expect(accountDeleted).to.be.undefined
 
       const { data } = await server.channels.list()
-      const videoChannelDeleted = data.find(a => a.name === 'Main user1 channel' && a.host === 'localhost:' + servers[0].port)
+      const videoChannelDeleted = data.find(a => a.name === 'Main user1 channel' && a.host === servers[0].host)
       expect(videoChannelDeleted).to.be.undefined
     }
   })
 
   it('Should not have actor files', async () => {
     for (const server of servers) {
-      await checkActorFilesWereRemoved(userAvatarFilename, server.internalServerNumber)
+      for (const userAvatarFilename of userAvatarFilenames) {
+        await checkActorFilesWereRemoved(userAvatarFilename, server)
+      }
     }
   })
 
   it('Should not have video files', async () => {
     for (const server of servers) {
-      await checkVideoFilesWereRemoved(videoUUID, server)
+      await checkVideoFilesWereRemoved({ server, video: server.store.videoDetails })
     }
   })