1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
3 import { expect } from 'chai'
4 import { HttpStatusCode } from '@shared/models'
10 setAccessTokensToServers,
12 } from '@shared/server-commands'
14 describe('Official plugin Akismet', function () {
15 let servers: PeerTubeServer[]
18 before(async function () {
21 servers = await createMultipleServers(2)
22 await setAccessTokensToServers(servers)
24 await servers[0].plugins.install({ npmName: 'peertube-plugin-akismet' })
26 if (!process.env.AKISMET_KEY) throw new Error('Missing AKISMET_KEY from env')
28 await servers[0].plugins.updateSettings({
29 npmName: 'peertube-plugin-akismet',
31 'akismet-api-key': process.env.AKISMET_KEY
35 await doubleFollow(servers[0], servers[1])
38 describe('Local threads/replies', function () {
40 before(async function () {
41 const { uuid } = await servers[0].videos.quickUpload({ name: 'video 1' })
45 it('Should not detect a thread as spam', async function () {
46 await servers[0].comments.createThread({ videoId: videoUUID, text: 'comment' })
49 it('Should not detect a reply as spam', async function () {
50 await servers[0].comments.addReplyToLastThread({ text: 'reply' })
53 it('Should detect a thread as spam', async function () {
54 await servers[0].comments.createThread({
56 text: 'akismet-guaranteed-spam',
57 expectedStatus: HttpStatusCode.FORBIDDEN_403
61 it('Should detect a thread as spam', async function () {
62 await servers[0].comments.createThread({ videoId: videoUUID, text: 'comment' })
63 await servers[0].comments.addReplyToLastThread({ text: 'akismet-guaranteed-spam', expectedStatus: HttpStatusCode.FORBIDDEN_403 })
67 describe('Remote threads/replies', function () {
69 before(async function () {
72 const { uuid } = await servers[0].videos.quickUpload({ name: 'video 1' })
76 it('Should not detect a thread as spam', async function () {
79 await servers[1].comments.createThread({ videoId: videoUUID, text: 'remote comment 1' })
80 await waitJobs(servers)
82 const { data } = await servers[0].comments.listThreads({ videoId: videoUUID })
83 expect(data).to.have.lengthOf(1)
86 it('Should not detect a reply as spam', async function () {
89 await servers[1].comments.addReplyToLastThread({ text: 'I agree with you' })
90 await waitJobs(servers)
92 const { data } = await servers[0].comments.listThreads({ videoId: videoUUID })
93 expect(data).to.have.lengthOf(1)
95 const tree = await servers[0].comments.getThread({ videoId: videoUUID, threadId: data[0].id })
96 expect(tree.children).to.have.lengthOf(1)
99 it('Should detect a thread as spam', async function () {
102 await servers[1].comments.createThread({ videoId: videoUUID, text: 'akismet-guaranteed-spam' })
103 await waitJobs(servers)
105 const { data } = await servers[0].comments.listThreads({ videoId: videoUUID })
106 expect(data).to.have.lengthOf(1)
109 it('Should detect a thread as spam', async function () {
112 await servers[1].comments.createThread({ videoId: videoUUID, text: 'remote comment 2' })
113 await servers[1].comments.addReplyToLastThread({ text: 'akismet-guaranteed-spam' })
114 await waitJobs(servers)
116 const { data } = await servers[0].comments.listThreads({ videoId: videoUUID })
117 expect(data).to.have.lengthOf(2)
119 for (const thread of data) {
120 const tree = await servers[0].comments.getThread({ videoId: videoUUID, threadId: thread.id })
121 if (tree.comment.text === 'remote comment 1') continue
123 expect(tree.children).to.have.lengthOf(0)
128 after(async function () {
129 await cleanupTests(servers)