]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/feeds/feeds.ts
Fix lint
[github/Chocobozzz/PeerTube.git] / server / tests / feeds / feeds.ts
index 4510177ccf0de942ae8f9d86d4bd76c07d72dafb..ba961cdba4278d9c4fe97135794a045aba8f6216 100644 (file)
@@ -1,7 +1,14 @@
 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
 
-import * as chai from 'chai'
 import 'mocha'
+import * as chai from 'chai'
+import * as libxmljs from 'libxmljs'
+import {
+  addAccountToAccountBlocklist,
+  addAccountToServerBlocklist,
+  removeAccountFromServerBlocklist
+} from '@shared/extra-utils/users/blocklist'
+import { VideoPrivacy } from '@shared/models'
 import {
   cleanupTests,
   createUser,
@@ -13,11 +20,11 @@ import {
   ServerInfo,
   setAccessTokensToServers,
   uploadVideo,
+  uploadVideoAndGetId,
   userLogin
 } from '../../../shared/extra-utils'
-import * as libxmljs from 'libxmljs'
-import { addVideoCommentThread } from '../../../shared/extra-utils/videos/video-comments'
 import { waitJobs } from '../../../shared/extra-utils/server/jobs'
+import { addVideoCommentThread } from '../../../shared/extra-utils/videos/video-comments'
 import { User } from '../../../shared/models/users'
 
 chai.use(require('chai-xml'))
@@ -77,6 +84,14 @@ describe('Test syndication feeds', () => {
       await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoId, 'super comment 2')
     }
 
+    {
+      const videoAttributes = { name: 'unlisted video', privacy: VideoPrivacy.UNLISTED }
+      const res = await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes)
+      const videoId = res.body.video.id
+
+      await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoId, 'comment on unlisted video')
+    }
+
     await waitJobs(servers)
   })
 
@@ -196,7 +211,8 @@ describe('Test syndication feeds', () => {
   })
 
   describe('Video comments feed', function () {
-    it('Should contain valid comments (covers JSON feed 1.0 endpoint)', async function () {
+
+    it('Should contain valid comments (covers JSON feed 1.0 endpoint) and not from unlisted videos', async function () {
       for (const server of servers) {
         const json = await getJSONfeed(server.url, 'video-comments')
 
@@ -206,6 +222,41 @@ describe('Test syndication feeds', () => {
         expect(jsonObj.items[1].html_content).to.equal('super comment 1')
       }
     })
+
+    it('Should not list comments from muted accounts or instances', async function () {
+      this.timeout(30000)
+
+      const remoteHandle = 'root@localhost:' + servers[0].port
+
+      await addAccountToServerBlocklist(servers[1].url, servers[1].accessToken, remoteHandle)
+
+      {
+        const json = await getJSONfeed(servers[1].url, 'video-comments', { version: 2 })
+        const jsonObj = JSON.parse(json.text)
+        expect(jsonObj.items.length).to.be.equal(0)
+      }
+
+      await removeAccountFromServerBlocklist(servers[1].url, servers[1].accessToken, remoteHandle)
+
+      {
+        const videoUUID = (await uploadVideoAndGetId({ server: servers[1], videoName: 'server 2' })).uuid
+        await waitJobs(servers)
+        await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoUUID, 'super comment')
+        await waitJobs(servers)
+
+        const json = await getJSONfeed(servers[1].url, 'video-comments', { version: 3 })
+        const jsonObj = JSON.parse(json.text)
+        expect(jsonObj.items.length).to.be.equal(3)
+      }
+
+      await addAccountToAccountBlocklist(servers[1].url, servers[1].accessToken, remoteHandle)
+
+      {
+        const json = await getJSONfeed(servers[1].url, 'video-comments', { version: 4 })
+        const jsonObj = JSON.parse(json.text)
+        expect(jsonObj.items.length).to.be.equal(2)
+      }
+    })
   })
 
   after(async function () {