aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/external-plugins/akismet.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2022-09-23 15:32:56 +0200
committerChocobozzz <me@florianbigard.com>2022-09-23 15:38:21 +0200
commit4f3814808791d8f380e75d152e0e14a01b758b9a (patch)
treebd9778c89e114f2325dfb756f0208c0fe353c212 /server/tests/external-plugins/akismet.ts
parent255c00305c899d8db829b07b49d06cd2fea7ca02 (diff)
downloadPeerTube-4f3814808791d8f380e75d152e0e14a01b758b9a.tar.gz
PeerTube-4f3814808791d8f380e75d152e0e14a01b758b9a.tar.zst
PeerTube-4f3814808791d8f380e75d152e0e14a01b758b9a.zip
Add akismet tests
Diffstat (limited to 'server/tests/external-plugins/akismet.ts')
-rw-r--r--server/tests/external-plugins/akismet.ts131
1 files changed, 131 insertions, 0 deletions
diff --git a/server/tests/external-plugins/akismet.ts b/server/tests/external-plugins/akismet.ts
new file mode 100644
index 000000000..557fc3daf
--- /dev/null
+++ b/server/tests/external-plugins/akismet.ts
@@ -0,0 +1,131 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3import { expect } from 'chai'
4import { HttpStatusCode } from '@shared/models'
5import {
6 cleanupTests,
7 createMultipleServers,
8 doubleFollow,
9 PeerTubeServer,
10 setAccessTokensToServers,
11 waitJobs
12} from '@shared/server-commands'
13
14describe('Official plugin Akismet', function () {
15 let servers: PeerTubeServer[]
16 let videoUUID: string
17
18 before(async function () {
19 this.timeout(30000)
20
21 servers = await createMultipleServers(2)
22 await setAccessTokensToServers(servers)
23
24 await servers[0].plugins.install({ npmName: 'peertube-plugin-akismet' })
25
26 if (!process.env.AKISMET_KEY) throw new Error('Missing AKISMET_KEY from env')
27
28 await servers[0].plugins.updateSettings({
29 npmName: 'peertube-plugin-akismet',
30 settings: {
31 'akismet-api-key': process.env.AKISMET_KEY
32 }
33 })
34
35 await doubleFollow(servers[0], servers[1])
36 })
37
38 describe('Local threads/replies', function () {
39
40 before(async function () {
41 const { uuid } = await servers[0].videos.quickUpload({ name: 'video 1' })
42 videoUUID = uuid
43 })
44
45 it('Should not detect a thread as spam', async function () {
46 await servers[0].comments.createThread({ videoId: videoUUID, text: 'comment' })
47 })
48
49 it('Should not detect a reply as spam', async function () {
50 await servers[0].comments.addReplyToLastThread({ text: 'reply' })
51 })
52
53 it('Should detect a thread as spam', async function () {
54 await servers[0].comments.createThread({
55 videoId: videoUUID,
56 text: 'akismet-guaranteed-spam',
57 expectedStatus: HttpStatusCode.FORBIDDEN_403
58 })
59 })
60
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 })
64 })
65 })
66
67 describe('Remote threads/replies', function () {
68
69 before(async function () {
70 this.timeout(60000)
71
72 const { uuid } = await servers[0].videos.quickUpload({ name: 'video 1' })
73 videoUUID = uuid
74 })
75
76 it('Should not detect a thread as spam', async function () {
77 this.timeout(30000)
78
79 await servers[1].comments.createThread({ videoId: videoUUID, text: 'remote comment 1' })
80 await waitJobs(servers)
81
82 const { data } = await servers[0].comments.listThreads({ videoId: videoUUID })
83 expect(data).to.have.lengthOf(1)
84 })
85
86 it('Should not detect a reply as spam', async function () {
87 this.timeout(30000)
88
89 await servers[1].comments.addReplyToLastThread({ text: 'I agree with you' })
90 await waitJobs(servers)
91
92 const { data } = await servers[0].comments.listThreads({ videoId: videoUUID })
93 expect(data).to.have.lengthOf(1)
94
95 const tree = await servers[0].comments.getThread({ videoId: videoUUID, threadId: data[0].id })
96 expect(tree.children).to.have.lengthOf(1)
97 })
98
99 it('Should detect a thread as spam', async function () {
100 this.timeout(30000)
101
102 await servers[1].comments.createThread({ videoId: videoUUID, text: 'akismet-guaranteed-spam' })
103 await waitJobs(servers)
104
105 const { data } = await servers[0].comments.listThreads({ videoId: videoUUID })
106 expect(data).to.have.lengthOf(1)
107 })
108
109 it('Should detect a thread as spam', async function () {
110 this.timeout(30000)
111
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)
115
116 const { data } = await servers[0].comments.listThreads({ videoId: videoUUID })
117 expect(data).to.have.lengthOf(2)
118
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
122
123 expect(tree.children).to.have.lengthOf(0)
124 }
125 })
126 })
127
128 after(async function () {
129 await cleanupTests(servers)
130 })
131})