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({
25 npmName: 'peertube-plugin-akismet'
28 if (!process.env.AKISMET_KEY) throw new Error('Missing AKISMET_KEY from env')
30 await servers[0].plugins.updateSettings({
31 npmName: 'peertube-plugin-akismet',
33 'akismet-api-key': process.env.AKISMET_KEY
37 await doubleFollow(servers[0], servers[1])
40 describe('Local threads/replies', function () {
42 before(async function () {
43 const { uuid } = await servers[0].videos.quickUpload({ name: 'video 1' })
47 it('Should not detect a thread as spam', async function () {
48 await servers[0].comments.createThread({ videoId: videoUUID, text: 'comment' })
51 it('Should not detect a reply as spam', async function () {
52 await servers[0].comments.addReplyToLastThread({ text: 'reply' })
55 it('Should detect a thread as spam', async function () {
56 await servers[0].comments.createThread({
58 text: 'akismet-guaranteed-spam',
59 expectedStatus: HttpStatusCode.FORBIDDEN_403
63 it('Should detect a thread as spam', async function () {
64 await servers[0].comments.createThread({ videoId: videoUUID, text: 'comment' })
65 await servers[0].comments.addReplyToLastThread({ text: 'akismet-guaranteed-spam', expectedStatus: HttpStatusCode.FORBIDDEN_403 })
69 describe('Remote threads/replies', function () {
71 before(async function () {
74 const { uuid } = await servers[0].videos.quickUpload({ name: 'video 1' })
77 await waitJobs(servers)
80 it('Should not detect a thread as spam', async function () {
83 await servers[1].comments.createThread({ videoId: videoUUID, text: 'remote comment 1' })
84 await waitJobs(servers)
86 const { data } = await servers[0].comments.listThreads({ videoId: videoUUID })
87 expect(data).to.have.lengthOf(1)
90 it('Should not detect a reply as spam', async function () {
93 await servers[1].comments.addReplyToLastThread({ text: 'I agree with you' })
94 await waitJobs(servers)
96 const { data } = await servers[0].comments.listThreads({ videoId: videoUUID })
97 expect(data).to.have.lengthOf(1)
99 const tree = await servers[0].comments.getThread({ videoId: videoUUID, threadId: data[0].id })
100 expect(tree.children).to.have.lengthOf(1)
103 it('Should detect a thread as spam', async function () {
106 await servers[1].comments.createThread({ videoId: videoUUID, text: 'akismet-guaranteed-spam' })
107 await waitJobs(servers)
109 const { data } = await servers[0].comments.listThreads({ videoId: videoUUID })
110 expect(data).to.have.lengthOf(1)
113 it('Should detect a thread as spam', async function () {
116 await servers[1].comments.addReplyToLastThread({ text: 'akismet-guaranteed-spam' })
117 await waitJobs(servers)
119 const { data } = await servers[0].comments.listThreads({ videoId: videoUUID })
120 expect(data).to.have.lengthOf(1)
122 const thread = data[0]
123 const tree = await servers[0].comments.getThread({ videoId: videoUUID, threadId: thread.id })
124 expect(tree.children).to.have.lengthOf(1)
128 describe('Signup', function () {
130 before(async function () {
131 await servers[0].config.updateExistingSubConfig({
140 it('Should allow signup', async function () {
141 await servers[0].users.register({
143 displayName: 'user 1'
147 it('Should detect a signup as SPAM', async function () {
148 await servers[0].users.register({
150 displayName: 'user 2',
151 email: 'akismet-guaranteed-spam@example.com',
152 expectedStatus: HttpStatusCode.FORBIDDEN_403
157 after(async function () {
158 await cleanupTests(servers)