]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/videos/video-change-ownership.ts
Move plugin blocklist mock
[github/Chocobozzz/PeerTube.git] / server / tests / api / videos / video-change-ownership.ts
CommitLineData
a1587156 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
74d63469 2
74d63469 3import 'mocha'
21b5c298
C
4import * as chai from 'chai'
5import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
74d63469
GR
6import {
7 acceptChangeOwnership,
48f07b4a
C
8 changeVideoOwnership,
9 cleanupTests,
21b5c298 10 createLive,
210feb6c
C
11 createUser,
12 doubleFollow,
13 flushAndRunMultipleServers,
14 flushAndRunServer,
74d63469 15 getMyUserInformation,
210feb6c 16 getVideo,
74d63469
GR
17 getVideoChangeOwnershipList,
18 getVideosList,
74d63469 19 refuseChangeOwnership,
74d63469
GR
20 ServerInfo,
21 setAccessTokensToServers,
21b5c298
C
22 setDefaultVideoChannel,
23 updateCustomSubConfig,
74d63469 24 uploadVideo,
210feb6c 25 userLogin
94565d52
C
26} from '../../../../shared/extra-utils'
27import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
74d63469 28import { User } from '../../../../shared/models/users'
21b5c298 29import { VideoDetails, VideoPrivacy } from '../../../../shared/models/videos'
74d63469
GR
30
31const expect = chai.expect
32
33describe('Test video change ownership - nominal', function () {
5cf84858 34 let servers: ServerInfo[] = []
74d63469
GR
35 const firstUser = {
36 username: 'first',
37 password: 'My great password'
38 }
39 const secondUser = {
40 username: 'second',
41 password: 'My other password'
42 }
21b5c298 43
74d63469 44 let firstUserAccessToken = ''
21b5c298
C
45 let firstUserChannelId: number
46
74d63469 47 let secondUserAccessToken = ''
21b5c298
C
48 let secondUserChannelId: number
49
a1587156 50 let lastRequestChangeOwnershipId = ''
74d63469 51
21b5c298
C
52 let liveId: number
53
74d63469
GR
54 before(async function () {
55 this.timeout(50000)
56
5cf84858
C
57 servers = await flushAndRunMultipleServers(2)
58 await setAccessTokensToServers(servers)
21b5c298
C
59 await setDefaultVideoChannel(servers)
60
61 await updateCustomSubConfig(servers[0].url, servers[0].accessToken, {
62 transcoding: {
63 enabled: false
64 },
65 live: {
66 enabled: true
67 }
68 })
74d63469
GR
69
70 const videoQuota = 42000000
1eddc9a7 71 await createUser({
a1587156
C
72 url: servers[0].url,
73 accessToken: servers[0].accessToken,
1eddc9a7
C
74 username: firstUser.username,
75 password: firstUser.password,
76 videoQuota: videoQuota
77 })
78 await createUser({
a1587156
C
79 url: servers[0].url,
80 accessToken: servers[0].accessToken,
1eddc9a7
C
81 username: secondUser.username,
82 password: secondUser.password,
83 videoQuota: videoQuota
84 })
74d63469 85
5cf84858
C
86 firstUserAccessToken = await userLogin(servers[0], firstUser)
87 secondUserAccessToken = await userLogin(servers[0], secondUser)
74d63469 88
21b5c298
C
89 {
90 const res = await getMyUserInformation(servers[0].url, firstUserAccessToken)
91 const firstUserInformation: User = res.body
92 firstUserChannelId = firstUserInformation.videoChannels[0].id
74d63469 93 }
74d63469 94
21b5c298
C
95 {
96 const res = await getMyUserInformation(servers[0].url, secondUserAccessToken)
97 const secondUserInformation: User = res.body
98 secondUserChannelId = secondUserInformation.videoChannels[0].id
99 }
74d63469 100
21b5c298
C
101 {
102 const videoAttributes = {
103 name: 'my super name',
104 description: 'my super description'
105 }
106 const res = await uploadVideo(servers[0].url, firstUserAccessToken, videoAttributes)
74d63469 107
21b5c298
C
108 const resVideo = await getVideo(servers[0].url, res.body.video.id)
109 servers[0].video = resVideo.body
110 }
74d63469 111
21b5c298
C
112 {
113 const attributes = { name: 'live', channelId: firstUserChannelId, privacy: VideoPrivacy.PUBLIC }
114 const res = await createLive(servers[0].url, firstUserAccessToken, attributes)
115
116 liveId = res.body.video.id
117 }
5cf84858
C
118
119 await doubleFollow(servers[0], servers[1])
74d63469
GR
120 })
121
122 it('Should not have video change ownership', async function () {
5cf84858 123 const resFirstUser = await getVideoChangeOwnershipList(servers[0].url, firstUserAccessToken)
74d63469
GR
124
125 expect(resFirstUser.body.total).to.equal(0)
126 expect(resFirstUser.body.data).to.be.an('array')
127 expect(resFirstUser.body.data.length).to.equal(0)
128
5cf84858 129 const resSecondUser = await getVideoChangeOwnershipList(servers[0].url, secondUserAccessToken)
74d63469
GR
130
131 expect(resSecondUser.body.total).to.equal(0)
132 expect(resSecondUser.body.data).to.be.an('array')
133 expect(resSecondUser.body.data.length).to.equal(0)
134 })
135
136 it('Should send a request to change ownership of a video', async function () {
137 this.timeout(15000)
138
5cf84858 139 await changeVideoOwnership(servers[0].url, firstUserAccessToken, servers[0].video.id, secondUser.username)
74d63469
GR
140 })
141
142 it('Should only return a request to change ownership for the second user', async function () {
5cf84858 143 const resFirstUser = await getVideoChangeOwnershipList(servers[0].url, firstUserAccessToken)
74d63469
GR
144
145 expect(resFirstUser.body.total).to.equal(0)
146 expect(resFirstUser.body.data).to.be.an('array')
147 expect(resFirstUser.body.data.length).to.equal(0)
148
5cf84858 149 const resSecondUser = await getVideoChangeOwnershipList(servers[0].url, secondUserAccessToken)
74d63469
GR
150
151 expect(resSecondUser.body.total).to.equal(1)
152 expect(resSecondUser.body.data).to.be.an('array')
153 expect(resSecondUser.body.data.length).to.equal(1)
154
155 lastRequestChangeOwnershipId = resSecondUser.body.data[0].id
156 })
157
158 it('Should accept the same change ownership request without crashing', async function () {
159 this.timeout(10000)
160
5cf84858 161 await changeVideoOwnership(servers[0].url, firstUserAccessToken, servers[0].video.id, secondUser.username)
74d63469
GR
162 })
163
164 it('Should not create multiple change ownership requests while one is waiting', async function () {
165 this.timeout(10000)
166
5cf84858 167 const resSecondUser = await getVideoChangeOwnershipList(servers[0].url, secondUserAccessToken)
74d63469
GR
168
169 expect(resSecondUser.body.total).to.equal(1)
170 expect(resSecondUser.body.data).to.be.an('array')
171 expect(resSecondUser.body.data.length).to.equal(1)
172 })
173
174 it('Should not be possible to refuse the change of ownership from first user', async function () {
175 this.timeout(10000)
176
f2eb23cd 177 await refuseChangeOwnership(servers[0].url, firstUserAccessToken, lastRequestChangeOwnershipId, HttpStatusCode.FORBIDDEN_403)
74d63469
GR
178 })
179
180 it('Should be possible to refuse the change of ownership from second user', async function () {
181 this.timeout(10000)
182
5cf84858 183 await refuseChangeOwnership(servers[0].url, secondUserAccessToken, lastRequestChangeOwnershipId)
74d63469
GR
184 })
185
186 it('Should send a new request to change ownership of a video', async function () {
187 this.timeout(15000)
188
5cf84858 189 await changeVideoOwnership(servers[0].url, firstUserAccessToken, servers[0].video.id, secondUser.username)
74d63469
GR
190 })
191
192 it('Should return two requests to change ownership for the second user', async function () {
5cf84858 193 const resFirstUser = await getVideoChangeOwnershipList(servers[0].url, firstUserAccessToken)
74d63469
GR
194
195 expect(resFirstUser.body.total).to.equal(0)
196 expect(resFirstUser.body.data).to.be.an('array')
197 expect(resFirstUser.body.data.length).to.equal(0)
198
5cf84858 199 const resSecondUser = await getVideoChangeOwnershipList(servers[0].url, secondUserAccessToken)
74d63469
GR
200
201 expect(resSecondUser.body.total).to.equal(2)
202 expect(resSecondUser.body.data).to.be.an('array')
203 expect(resSecondUser.body.data.length).to.equal(2)
204
205 lastRequestChangeOwnershipId = resSecondUser.body.data[0].id
206 })
207
208 it('Should not be possible to accept the change of ownership from first user', async function () {
209 this.timeout(10000)
210
21b5c298
C
211 await acceptChangeOwnership(
212 servers[0].url,
213 firstUserAccessToken,
214 lastRequestChangeOwnershipId,
215 secondUserChannelId,
216 HttpStatusCode.FORBIDDEN_403
217 )
74d63469
GR
218 })
219
220 it('Should be possible to accept the change of ownership from second user', async function () {
221 this.timeout(10000)
222
21b5c298 223 await acceptChangeOwnership(servers[0].url, secondUserAccessToken, lastRequestChangeOwnershipId, secondUserChannelId)
5cf84858
C
224
225 await waitJobs(servers)
226 })
227
f92e7f76 228 it('Should have the channel of the video updated', async function () {
5cf84858
C
229 for (const server of servers) {
230 const res = await getVideo(server.url, servers[0].video.uuid)
231
232 const video: VideoDetails = res.body
233
234 expect(video.name).to.equal('my super name')
235 expect(video.channel.displayName).to.equal('Main second channel')
236 expect(video.channel.name).to.equal('second_channel')
237 }
74d63469
GR
238 })
239
21b5c298
C
240 it('Should send a request to change ownership of a live', async function () {
241 this.timeout(15000)
242
243 await changeVideoOwnership(servers[0].url, firstUserAccessToken, liveId, secondUser.username)
244
245 const resSecondUser = await getVideoChangeOwnershipList(servers[0].url, secondUserAccessToken)
246
247 expect(resSecondUser.body.total).to.equal(3)
248 expect(resSecondUser.body.data.length).to.equal(3)
249
250 lastRequestChangeOwnershipId = resSecondUser.body.data[0].id
251 })
252
253 it('Should accept a live ownership change', async function () {
254 this.timeout(20000)
255
256 await acceptChangeOwnership(servers[0].url, secondUserAccessToken, lastRequestChangeOwnershipId, secondUserChannelId)
257
258 await waitJobs(servers)
259
260 for (const server of servers) {
261 const res = await getVideo(server.url, servers[0].video.uuid)
262
263 const video: VideoDetails = res.body
264
265 expect(video.name).to.equal('my super name')
266 expect(video.channel.displayName).to.equal('Main second channel')
267 expect(video.channel.name).to.equal('second_channel')
268 }
269 })
270
48f07b4a
C
271 after(async function () {
272 await cleanupTests(servers)
74d63469
GR
273 })
274})
275
276describe('Test video change ownership - quota too small', function () {
a1587156 277 let server: ServerInfo
74d63469
GR
278 const firstUser = {
279 username: 'first',
280 password: 'My great password'
281 }
282 const secondUser = {
283 username: 'second',
284 password: 'My other password'
285 }
286 let firstUserAccessToken = ''
287 let secondUserAccessToken = ''
a1587156 288 let lastRequestChangeOwnershipId = ''
74d63469
GR
289
290 before(async function () {
291 this.timeout(50000)
292
293 // Run one server
210feb6c 294 server = await flushAndRunServer(1)
a1587156 295 await setAccessTokensToServers([ server ])
74d63469
GR
296
297 const videoQuota = 42000000
298 const limitedVideoQuota = 10
1eddc9a7
C
299 await createUser({
300 url: server.url,
301 accessToken: server.accessToken,
302 username: firstUser.username,
303 password: firstUser.password,
304 videoQuota: videoQuota
305 })
306 await createUser({
307 url: server.url,
308 accessToken: server.accessToken,
309 username: secondUser.username,
310 password: secondUser.password,
311 videoQuota: limitedVideoQuota
312 })
74d63469
GR
313
314 firstUserAccessToken = await userLogin(server, firstUser)
315 secondUserAccessToken = await userLogin(server, secondUser)
316
317 // Upload some videos on the server
318 const video1Attributes = {
319 name: 'my super name',
320 description: 'my super description'
321 }
322 await uploadVideo(server.url, firstUserAccessToken, video1Attributes)
323
324 await waitJobs(server)
325
326 const res = await getVideosList(server.url)
327 const videos = res.body.data
328
329 expect(videos.length).to.equal(1)
330
331 server.video = videos.find(video => video.name === 'my super name')
332 })
333
334 it('Should send a request to change ownership of a video', async function () {
335 this.timeout(15000)
336
337 await changeVideoOwnership(server.url, firstUserAccessToken, server.video.id, secondUser.username)
338 })
339
340 it('Should only return a request to change ownership for the second user', async function () {
341 const resFirstUser = await getVideoChangeOwnershipList(server.url, firstUserAccessToken)
342
343 expect(resFirstUser.body.total).to.equal(0)
344 expect(resFirstUser.body.data).to.be.an('array')
345 expect(resFirstUser.body.data.length).to.equal(0)
346
347 const resSecondUser = await getVideoChangeOwnershipList(server.url, secondUserAccessToken)
348
349 expect(resSecondUser.body.total).to.equal(1)
350 expect(resSecondUser.body.data).to.be.an('array')
351 expect(resSecondUser.body.data.length).to.equal(1)
352
353 lastRequestChangeOwnershipId = resSecondUser.body.data[0].id
354 })
355
356 it('Should not be possible to accept the change of ownership from second user because of exceeded quota', async function () {
357 this.timeout(10000)
358
359 const secondUserInformationResponse = await getMyUserInformation(server.url, secondUserAccessToken)
360 const secondUserInformation: User = secondUserInformationResponse.body
361 const channelId = secondUserInformation.videoChannels[0].id
f2eb23cd
RK
362
363 await acceptChangeOwnership(
364 server.url,
365 secondUserAccessToken,
366 lastRequestChangeOwnershipId,
367 channelId,
368 HttpStatusCode.PAYLOAD_TOO_LARGE_413
369 )
74d63469
GR
370 })
371
7c3b7976
C
372 after(async function () {
373 await cleanupTests([ server ])
74d63469
GR
374 })
375})