]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/api/videos/video-channels.ts
Fix tests
[github/Chocobozzz/PeerTube.git] / server / tests / api / videos / video-channels.ts
index bbb9b12d6bc170a611cb919d6db56f8ced6e8610..f7cf84618d32304f52adc27a05652c268ce993c9 100644 (file)
@@ -1,10 +1,9 @@
 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
 
-import 'mocha'
-import * as chai from 'chai'
+import { expect } from 'chai'
 import { basename } from 'path'
 import { ACTOR_IMAGES_SIZE } from '@server/initializers/constants'
-import { testFileExistsOrNot, testImage } from '@server/tests/shared'
+import { SQLCommand, testFileExistsOrNot, testImage } from '@server/tests/shared'
 import { wait } from '@shared/core-utils'
 import { ActorImageType, User, VideoChannel } from '@shared/models'
 import {
@@ -18,8 +17,6 @@ import {
   waitJobs
 } from '@shared/server-commands'
 
-const expect = chai.expect
-
 async function findChannel (server: PeerTubeServer, channelId: number) {
   const body = await server.channels.list({ sort: '-name' })
 
@@ -28,6 +25,8 @@ async function findChannel (server: PeerTubeServer, channelId: number) {
 
 describe('Test video channels', function () {
   let servers: PeerTubeServer[]
+  let sqlCommands: SQLCommand[] = []
+
   let userInfo: User
   let secondVideoChannelId: number
   let totoChannel: number
@@ -48,6 +47,8 @@ describe('Test video channels', function () {
     await setDefaultAccountAvatar(servers)
 
     await doubleFollow(servers[0], servers[1])
+
+    sqlCommands = servers.map(s => new SQLCommand(s))
   })
 
   it('Should have one video channel (created with root)', async () => {
@@ -281,7 +282,9 @@ describe('Test video channels', function () {
 
     await waitJobs(servers)
 
-    for (const server of servers) {
+    for (let i = 0; i < servers.length; i++) {
+      const server = servers[i]
+
       const videoChannel = await findChannel(server, secondVideoChannelId)
       const expectedSizes = ACTOR_IMAGES_SIZE[ActorImageType.AVATAR]
 
@@ -292,7 +295,7 @@ describe('Test video channels', function () {
         await testImage(server.url, `avatar-resized-${avatar.width}x${avatar.width}`, avatarPaths[server.port], '.png')
         await testFileExistsOrNot(server, 'avatars', basename(avatarPaths[server.port]), true)
 
-        const row = await server.sql.getActorImage(basename(avatarPaths[server.port]))
+        const row = await sqlCommands[i].getActorImage(basename(avatarPaths[server.port]))
 
         expect(expectedSizes.some(({ height, width }) => row.height === height && row.width === width)).to.equal(true)
       }
@@ -312,14 +315,16 @@ describe('Test video channels', function () {
 
     await waitJobs(servers)
 
-    for (const server of servers) {
+    for (let i = 0; i < servers.length; i++) {
+      const server = servers[i]
+
       const videoChannel = await server.channels.get({ channelName: 'second_video_channel@' + servers[0].host })
 
       bannerPaths[server.port] = videoChannel.banners[0].path
       await testImage(server.url, 'banner-resized', bannerPaths[server.port])
       await testFileExistsOrNot(server, 'avatars', basename(bannerPaths[server.port]), true)
 
-      const row = await server.sql.getActorImage(basename(bannerPaths[server.port]))
+      const row = await sqlCommands[i].getActorImage(basename(bannerPaths[server.port]))
       expect(row.height).to.equal(ACTOR_IMAGES_SIZE[ActorImageType.BANNER][0].height)
       expect(row.width).to.equal(ACTOR_IMAGES_SIZE[ActorImageType.BANNER][0].width)
     }
@@ -373,10 +378,8 @@ describe('Test video channels', function () {
   })
 
   it('Should list the second video channel videos', async function () {
-    this.timeout(10000)
-
     for (const server of servers) {
-      const channelURI = 'second_video_channel@localhost:' + servers[0].port
+      const channelURI = 'second_video_channel@' + servers[0].host
       const { total, data } = await server.videos.listByChannel({ handle: channelURI })
 
       expect(total).to.equal(1)
@@ -387,25 +390,21 @@ describe('Test video channels', function () {
   })
 
   it('Should change the video channel of a video', async function () {
-    this.timeout(10000)
-
     await servers[0].videos.update({ id: videoUUID, attributes: { channelId: servers[0].store.channel.id } })
 
     await waitJobs(servers)
   })
 
   it('Should list the first video channel videos', async function () {
-    this.timeout(10000)
-
     for (const server of servers) {
       {
-        const secondChannelURI = 'second_video_channel@localhost:' + servers[0].port
+        const secondChannelURI = 'second_video_channel@' + servers[0].host
         const { total } = await server.videos.listByChannel({ handle: secondChannelURI })
         expect(total).to.equal(0)
       }
 
       {
-        const channelURI = 'root_channel@localhost:' + servers[0].port
+        const channelURI = 'root_channel@' + servers[0].host
         const { total, data } = await server.videos.listByChannel({ handle: channelURI })
         expect(total).to.equal(1)
 
@@ -430,7 +429,7 @@ describe('Test video channels', function () {
     expect(body.data[1].displayName).to.equal('video channel updated')
   })
 
-  it('Should create the main channel with an uuid if there is a conflict', async function () {
+  it('Should create the main channel with a suffix if there is a conflict', async function () {
     {
       const videoChannel = { name: 'toto_channel', displayName: 'My toto channel' }
       const created = await servers[0].channels.create({ attributes: videoChannel })
@@ -442,14 +441,11 @@ describe('Test video channels', function () {
       const accessToken = await servers[0].login.getAccessToken({ username: 'toto', password: 'password' })
 
       const { videoChannels } = await servers[0].users.getMyInfo({ token: accessToken })
-      const videoChannel = videoChannels[0]
-      expect(videoChannel.name).to.match(/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/)
+      expect(videoChannels[0].name).to.equal('toto_channel-1')
     }
   })
 
   it('Should report correct channel views per days', async function () {
-    this.timeout(10000)
-
     {
       const { data } = await servers[0].channels.listByAccount({ accountName, withStats: true })
 
@@ -550,6 +546,10 @@ describe('Test video channels', function () {
   })
 
   after(async function () {
+    for (const sqlCommand of sqlCommands) {
+      await sqlCommand.cleanup()
+    }
+
     await cleanupTests(servers)
   })
 })