1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
5 import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
7 ChangeOwnershipCommand,
11 flushAndRunMultipleServers,
17 setAccessTokensToServers,
18 setDefaultVideoChannel,
20 } from '../../../../shared/extra-utils'
21 import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
22 import { User } from '../../../../shared/models/users'
23 import { VideoDetails, VideoPrivacy } from '../../../../shared/models/videos'
25 const expect = chai.expect
27 describe('Test video change ownership - nominal', function () {
28 let servers: ServerInfo[] = []
31 password: 'My great password'
35 password: 'My other password'
38 let firstUserToken = ''
39 let firstUserChannelId: number
41 let secondUserToken = ''
42 let secondUserChannelId: number
44 let lastRequestId: number
48 let command: ChangeOwnershipCommand
50 before(async function () {
53 servers = await flushAndRunMultipleServers(2)
54 await setAccessTokensToServers(servers)
55 await setDefaultVideoChannel(servers)
57 await servers[0].configCommand.updateCustomSubConfig({
68 const videoQuota = 42000000
71 accessToken: servers[0].accessToken,
72 username: firstUser.username,
73 password: firstUser.password,
74 videoQuota: videoQuota
78 accessToken: servers[0].accessToken,
79 username: secondUser.username,
80 password: secondUser.password,
81 videoQuota: videoQuota
84 firstUserToken = await servers[0].loginCommand.getAccessToken(firstUser)
85 secondUserToken = await servers[0].loginCommand.getAccessToken(secondUser)
88 const res = await getMyUserInformation(servers[0].url, firstUserToken)
89 const firstUserInformation: User = res.body
90 firstUserChannelId = firstUserInformation.videoChannels[0].id
94 const res = await getMyUserInformation(servers[0].url, secondUserToken)
95 const secondUserInformation: User = res.body
96 secondUserChannelId = secondUserInformation.videoChannels[0].id
100 const videoAttributes = {
101 name: 'my super name',
102 description: 'my super description'
104 const res = await uploadVideo(servers[0].url, firstUserToken, videoAttributes)
106 const resVideo = await getVideo(servers[0].url, res.body.video.id)
107 servers[0].video = resVideo.body
111 const attributes = { name: 'live', channelId: firstUserChannelId, privacy: VideoPrivacy.PUBLIC }
112 const video = await servers[0].liveCommand.create({ token: firstUserToken, fields: attributes })
117 command = servers[0].changeOwnershipCommand
119 await doubleFollow(servers[0], servers[1])
122 it('Should not have video change ownership', async function () {
124 const body = await command.list({ token: firstUserToken })
126 expect(body.total).to.equal(0)
127 expect(body.data).to.be.an('array')
128 expect(body.data.length).to.equal(0)
132 const body = await command.list({ token: secondUserToken })
134 expect(body.total).to.equal(0)
135 expect(body.data).to.be.an('array')
136 expect(body.data.length).to.equal(0)
140 it('Should send a request to change ownership of a video', async function () {
143 await command.create({ token: firstUserToken, videoId: servers[0].video.id, username: secondUser.username })
146 it('Should only return a request to change ownership for the second user', async function () {
148 const body = await command.list({ token: firstUserToken })
150 expect(body.total).to.equal(0)
151 expect(body.data).to.be.an('array')
152 expect(body.data.length).to.equal(0)
156 const body = await command.list({ token: secondUserToken })
158 expect(body.total).to.equal(1)
159 expect(body.data).to.be.an('array')
160 expect(body.data.length).to.equal(1)
162 lastRequestId = body.data[0].id
166 it('Should accept the same change ownership request without crashing', async function () {
169 await command.create({ token: firstUserToken, videoId: servers[0].video.id, username: secondUser.username })
172 it('Should not create multiple change ownership requests while one is waiting', async function () {
175 const body = await command.list({ token: secondUserToken })
177 expect(body.total).to.equal(1)
178 expect(body.data).to.be.an('array')
179 expect(body.data.length).to.equal(1)
182 it('Should not be possible to refuse the change of ownership from first user', async function () {
185 await command.refuse({ token: firstUserToken, ownershipId: lastRequestId, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
188 it('Should be possible to refuse the change of ownership from second user', async function () {
191 await command.refuse({ token: secondUserToken, ownershipId: lastRequestId })
194 it('Should send a new request to change ownership of a video', async function () {
197 await command.create({ token: firstUserToken, videoId: servers[0].video.id, username: secondUser.username })
200 it('Should return two requests to change ownership for the second user', async function () {
202 const body = await command.list({ token: firstUserToken })
204 expect(body.total).to.equal(0)
205 expect(body.data).to.be.an('array')
206 expect(body.data.length).to.equal(0)
210 const body = await command.list({ token: secondUserToken })
212 expect(body.total).to.equal(2)
213 expect(body.data).to.be.an('array')
214 expect(body.data.length).to.equal(2)
216 lastRequestId = body.data[0].id
220 it('Should not be possible to accept the change of ownership from first user', async function () {
223 await command.accept({
224 token: firstUserToken,
225 ownershipId: lastRequestId,
226 channelId: secondUserChannelId,
227 expectedStatus: HttpStatusCode.FORBIDDEN_403
231 it('Should be possible to accept the change of ownership from second user', async function () {
234 await command.accept({ token: secondUserToken, ownershipId: lastRequestId, channelId: secondUserChannelId })
236 await waitJobs(servers)
239 it('Should have the channel of the video updated', async function () {
240 for (const server of servers) {
241 const res = await getVideo(server.url, servers[0].video.uuid)
243 const video: VideoDetails = res.body
245 expect(video.name).to.equal('my super name')
246 expect(video.channel.displayName).to.equal('Main second channel')
247 expect(video.channel.name).to.equal('second_channel')
251 it('Should send a request to change ownership of a live', async function () {
254 await command.create({ token: firstUserToken, videoId: liveId, username: secondUser.username })
256 const body = await command.list({ token: secondUserToken })
258 expect(body.total).to.equal(3)
259 expect(body.data.length).to.equal(3)
261 lastRequestId = body.data[0].id
264 it('Should accept a live ownership change', async function () {
267 await command.accept({ token: secondUserToken, ownershipId: lastRequestId, channelId: secondUserChannelId })
269 await waitJobs(servers)
271 for (const server of servers) {
272 const res = await getVideo(server.url, servers[0].video.uuid)
274 const video: VideoDetails = res.body
276 expect(video.name).to.equal('my super name')
277 expect(video.channel.displayName).to.equal('Main second channel')
278 expect(video.channel.name).to.equal('second_channel')
282 after(async function () {
283 await cleanupTests(servers)
287 describe('Test video change ownership - quota too small', function () {
288 let server: ServerInfo
291 password: 'My great password'
295 password: 'My other password'
297 let firstUserToken = ''
298 let secondUserToken = ''
299 let lastRequestId: number
301 before(async function () {
305 server = await flushAndRunServer(1)
306 await setAccessTokensToServers([ server ])
308 const videoQuota = 42000000
309 const limitedVideoQuota = 10
312 accessToken: server.accessToken,
313 username: firstUser.username,
314 password: firstUser.password,
315 videoQuota: videoQuota
319 accessToken: server.accessToken,
320 username: secondUser.username,
321 password: secondUser.password,
322 videoQuota: limitedVideoQuota
325 firstUserToken = await server.loginCommand.getAccessToken(firstUser)
326 secondUserToken = await server.loginCommand.getAccessToken(secondUser)
328 // Upload some videos on the server
329 const video1Attributes = {
330 name: 'my super name',
331 description: 'my super description'
333 await uploadVideo(server.url, firstUserToken, video1Attributes)
335 await waitJobs(server)
337 const res = await getVideosList(server.url)
338 const videos = res.body.data
340 expect(videos.length).to.equal(1)
342 server.video = videos.find(video => video.name === 'my super name')
345 it('Should send a request to change ownership of a video', async function () {
348 await server.changeOwnershipCommand.create({ token: firstUserToken, videoId: server.video.id, username: secondUser.username })
351 it('Should only return a request to change ownership for the second user', async function () {
353 const body = await server.changeOwnershipCommand.list({ token: firstUserToken })
355 expect(body.total).to.equal(0)
356 expect(body.data).to.be.an('array')
357 expect(body.data.length).to.equal(0)
361 const body = await server.changeOwnershipCommand.list({ token: secondUserToken })
363 expect(body.total).to.equal(1)
364 expect(body.data).to.be.an('array')
365 expect(body.data.length).to.equal(1)
367 lastRequestId = body.data[0].id
371 it('Should not be possible to accept the change of ownership from second user because of exceeded quota', async function () {
374 const secondUserInformationResponse = await getMyUserInformation(server.url, secondUserToken)
375 const secondUserInformation: User = secondUserInformationResponse.body
376 const channelId = secondUserInformation.videoChannels[0].id
378 await server.changeOwnershipCommand.accept({
379 token: secondUserToken,
380 ownershipId: lastRequestId,
382 expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413
386 after(async function () {
387 await cleanupTests([ server ])