]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/server/bulk.ts
fix missing title attribute on <iframe> tag suggested for embedding (#3901)
[github/Chocobozzz/PeerTube.git] / server / tests / api / server / bulk.ts
1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3 import 'mocha'
4 import * as chai from 'chai'
5 import { VideoComment } from '@shared/models/videos/video-comment.model'
6 import {
7 addVideoCommentThread,
8 bulkRemoveCommentsOf,
9 cleanupTests,
10 createUser,
11 flushAndRunMultipleServers,
12 getVideoCommentThreads,
13 getVideosList,
14 ServerInfo,
15 setAccessTokensToServers,
16 uploadVideo,
17 userLogin,
18 waitJobs,
19 addVideoCommentReply
20 } from '../../../../shared/extra-utils/index'
21 import { doubleFollow } from '../../../../shared/extra-utils/server/follows'
22 import { Video } from '@shared/models'
23
24 const expect = chai.expect
25
26 describe('Test bulk actions', function () {
27 const commentsUser3: { videoId: number, commentId: number }[] = []
28
29 let servers: ServerInfo[] = []
30 let user1AccessToken: string
31 let user2AccessToken: string
32 let user3AccessToken: string
33
34 before(async function () {
35 this.timeout(30000)
36
37 servers = await flushAndRunMultipleServers(2)
38
39 // Get the access tokens
40 await setAccessTokensToServers(servers)
41
42 {
43 const user = { username: 'user1', password: 'password' }
44 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password })
45
46 user1AccessToken = await userLogin(servers[0], user)
47 }
48
49 {
50 const user = { username: 'user2', password: 'password' }
51 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password })
52
53 user2AccessToken = await userLogin(servers[0], user)
54 }
55
56 {
57 const user = { username: 'user3', password: 'password' }
58 await createUser({ url: servers[1].url, accessToken: servers[1].accessToken, username: user.username, password: user.password })
59
60 user3AccessToken = await userLogin(servers[1], user)
61 }
62
63 await doubleFollow(servers[0], servers[1])
64 })
65
66 describe('Bulk remove comments', function () {
67 async function checkInstanceCommentsRemoved () {
68 {
69 const res = await getVideosList(servers[0].url)
70 const videos = res.body.data as Video[]
71
72 // Server 1 should not have these comments anymore
73 for (const video of videos) {
74 const resThreads = await getVideoCommentThreads(servers[0].url, video.id, 0, 10)
75 const comments = resThreads.body.data as VideoComment[]
76 const comment = comments.find(c => c.text === 'comment by user 3')
77
78 expect(comment).to.not.exist
79 }
80 }
81
82 {
83 const res = await getVideosList(servers[1].url)
84 const videos = res.body.data as Video[]
85
86 // Server 1 should not have these comments on videos of server 1
87 for (const video of videos) {
88 const resThreads = await getVideoCommentThreads(servers[1].url, video.id, 0, 10)
89 const comments = resThreads.body.data as VideoComment[]
90 const comment = comments.find(c => c.text === 'comment by user 3')
91
92 if (video.account.host === 'localhost:' + servers[0].port) {
93 expect(comment).to.not.exist
94 } else {
95 expect(comment).to.exist
96 }
97 }
98 }
99 }
100
101 before(async function () {
102 this.timeout(120000)
103
104 await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video 1 server 1' })
105 await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video 2 server 1' })
106 await uploadVideo(servers[0].url, user1AccessToken, { name: 'video 3 server 1' })
107
108 await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video 1 server 2' })
109
110 await waitJobs(servers)
111
112 {
113 const res = await getVideosList(servers[0].url)
114 for (const video of res.body.data) {
115 await addVideoCommentThread(servers[0].url, servers[0].accessToken, video.id, 'comment by root server 1')
116 await addVideoCommentThread(servers[0].url, user1AccessToken, video.id, 'comment by user 1')
117 await addVideoCommentThread(servers[0].url, user2AccessToken, video.id, 'comment by user 2')
118 }
119 }
120
121 {
122 const res = await getVideosList(servers[1].url)
123 for (const video of res.body.data) {
124 await addVideoCommentThread(servers[1].url, servers[1].accessToken, video.id, 'comment by root server 2')
125
126 const res = await addVideoCommentThread(servers[1].url, user3AccessToken, video.id, 'comment by user 3')
127 commentsUser3.push({ videoId: video.id, commentId: res.body.comment.id })
128 }
129 }
130
131 await waitJobs(servers)
132 })
133
134 it('Should delete comments of an account on my videos', async function () {
135 this.timeout(60000)
136
137 await bulkRemoveCommentsOf({
138 url: servers[0].url,
139 token: user1AccessToken,
140 attributes: {
141 accountName: 'user2',
142 scope: 'my-videos'
143 }
144 })
145
146 await waitJobs(servers)
147
148 for (const server of servers) {
149 const res = await getVideosList(server.url)
150
151 for (const video of res.body.data) {
152 const resThreads = await getVideoCommentThreads(server.url, video.id, 0, 10)
153 const comments = resThreads.body.data as VideoComment[]
154 const comment = comments.find(c => c.text === 'comment by user 2')
155
156 if (video.name === 'video 3 server 1') {
157 expect(comment).to.not.exist
158 } else {
159 expect(comment).to.exist
160 }
161 }
162 }
163 })
164
165 it('Should delete comments of an account on the instance', async function () {
166 this.timeout(60000)
167
168 await bulkRemoveCommentsOf({
169 url: servers[0].url,
170 token: servers[0].accessToken,
171 attributes: {
172 accountName: 'user3@localhost:' + servers[1].port,
173 scope: 'instance'
174 }
175 })
176
177 await waitJobs(servers)
178
179 await checkInstanceCommentsRemoved()
180 })
181
182 it('Should not re create the comment on video update', async function () {
183 this.timeout(60000)
184
185 for (const obj of commentsUser3) {
186 await addVideoCommentReply(servers[1].url, user3AccessToken, obj.videoId, obj.commentId, 'comment by user 3 bis')
187 }
188
189 await waitJobs(servers)
190
191 await checkInstanceCommentsRemoved()
192 })
193 })
194
195 after(async function () {
196 await cleanupTests(servers)
197 })
198 })