]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/api/videos/videos-overview.ts
Merge branch 'release/4.3.0' into develop
[github/Chocobozzz/PeerTube.git] / server / tests / api / videos / videos-overview.ts
index d38bcb6eb012e445dfacee45390a6736c327db6b..c012d47c3fd6b1010bce894f1d1599b0c291b97d 100644 (file)
@@ -1,78 +1,77 @@
 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
 
-import * as chai from 'chai'
-import 'mocha'
-import { cleanupTests, flushAndRunServer, ServerInfo, setAccessTokensToServers, uploadVideo, wait } from '../../../../shared/extra-utils'
-import { getVideosOverview } from '../../../../shared/extra-utils/overviews/overviews'
-import { VideosOverview } from '../../../../shared/models/overviews'
-
-const expect = chai.expect
+import { expect } from 'chai'
+import { wait } from '@shared/core-utils'
+import { VideosOverview } from '@shared/models'
+import { cleanupTests, createSingleServer, PeerTubeServer, setAccessTokensToServers } from '@shared/server-commands'
 
 describe('Test a videos overview', function () {
-  let server: ServerInfo = null
+  let server: PeerTubeServer = null
+
+  function testOverviewCount (overview: VideosOverview, expected: number) {
+    expect(overview.tags).to.have.lengthOf(expected)
+    expect(overview.categories).to.have.lengthOf(expected)
+    expect(overview.channels).to.have.lengthOf(expected)
+  }
 
   before(async function () {
     this.timeout(30000)
 
-    server = await flushAndRunServer(1)
+    server = await createSingleServer(1)
 
     await setAccessTokensToServers([ server ])
   })
 
   it('Should send empty overview', async function () {
-    const res = await getVideosOverview(server.url, 1)
+    const body = await server.overviews.getVideos({ page: 1 })
 
-    const overview: VideosOverview = res.body
-    expect(overview.tags).to.have.lengthOf(0)
-    expect(overview.categories).to.have.lengthOf(0)
-    expect(overview.channels).to.have.lengthOf(0)
+    testOverviewCount(body, 0)
   })
 
   it('Should upload 5 videos in a specific category, tag and channel but not include them in overview', async function () {
-    this.timeout(15000)
+    this.timeout(30000)
 
     await wait(3000)
 
-    await uploadVideo(server.url, server.accessToken, {
-      name: 'video 0',
-      category: 3,
-      tags: [ 'coucou1', 'coucou2' ]
+    await server.videos.upload({
+      attributes: {
+        name: 'video 0',
+        category: 3,
+        tags: [ 'coucou1', 'coucou2' ]
+      }
     })
 
-    const res = await getVideosOverview(server.url, 1)
+    const body = await server.overviews.getVideos({ page: 1 })
 
-    const overview: VideosOverview = res.body
-    expect(overview.tags).to.have.lengthOf(0)
-    expect(overview.categories).to.have.lengthOf(0)
-    expect(overview.channels).to.have.lengthOf(0)
+    testOverviewCount(body, 0)
   })
 
   it('Should upload another video and include all videos in the overview', async function () {
-    this.timeout(15000)
+    this.timeout(30000)
 
-    for (let i = 1; i < 6; i++) {
-      await uploadVideo(server.url, server.accessToken, {
-        name: 'video ' + i,
-        category: 3,
-        tags: [ 'coucou1', 'coucou2' ]
-      })
+    {
+      for (let i = 1; i < 6; i++) {
+        await server.videos.upload({
+          attributes: {
+            name: 'video ' + i,
+            category: 3,
+            tags: [ 'coucou1', 'coucou2' ]
+          }
+        })
+      }
+
+      await wait(3000)
     }
 
-    await wait(3000)
-
     {
-      const res = await getVideosOverview(server.url, 1)
+      const body = await server.overviews.getVideos({ page: 1 })
 
-      const overview: VideosOverview = res.body
-      expect(overview.tags).to.have.lengthOf(1)
-      expect(overview.categories).to.have.lengthOf(1)
-      expect(overview.channels).to.have.lengthOf(1)
+      testOverviewCount(body, 1)
     }
 
     {
-      const res = await getVideosOverview(server.url, 2)
+      const overview = await server.overviews.getVideos({ page: 2 })
 
-      const overview: VideosOverview = res.body
       expect(overview.tags).to.have.lengthOf(1)
       expect(overview.categories).to.have.lengthOf(0)
       expect(overview.channels).to.have.lengthOf(0)
@@ -80,20 +79,10 @@ describe('Test a videos overview', function () {
   })
 
   it('Should have the correct overview', async function () {
-    const res1 = await getVideosOverview(server.url, 1)
-    const res2 = await getVideosOverview(server.url, 2)
-
-    const overview1: VideosOverview = res1.body
-    const overview2: VideosOverview = res2.body
+    const overview1 = await server.overviews.getVideos({ page: 1 })
+    const overview2 = await server.overviews.getVideos({ page: 2 })
 
-    const tmp = [
-      overview1.tags,
-      overview1.categories,
-      overview1.channels,
-      overview2.tags
-    ]
-
-    for (const arr of tmp) {
+    for (const arr of [ overview1.tags, overview1.categories, overview1.channels, overview2.tags ]) {
       expect(arr).to.have.lengthOf(1)
 
       const obj = arr[0]
@@ -116,6 +105,24 @@ describe('Test a videos overview', function () {
     expect(overview1.channels[0].channel.name).to.equal('root_channel')
   })
 
+  it('Should hide muted accounts', async function () {
+    const token = await server.users.generateUserAndToken('choco')
+
+    await server.blocklist.addToMyBlocklist({ token, account: 'root@' + server.host })
+
+    {
+      const body = await server.overviews.getVideos({ page: 1 })
+
+      testOverviewCount(body, 1)
+    }
+
+    {
+      const body = await server.overviews.getVideos({ page: 1, token })
+
+      testOverviewCount(body, 0)
+    }
+  })
+
   after(async function () {
     await cleanupTests([ server ])
   })