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