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,
21 } from '../../../../shared/extra-utils'
22 import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
23 import { User } from '../../../../shared/models/users'
24 import { VideoDetails, VideoPrivacy } from '../../../../shared/models/videos'
26 const expect = chai.expect
28 describe('Test video change ownership - nominal', function () {
29 let servers: ServerInfo[] = []
32 password: 'My great password'
36 password: 'My other password'
39 let firstUserToken = ''
40 let firstUserChannelId: number
42 let secondUserToken = ''
43 let secondUserChannelId: number
45 let lastRequestId: number
49 let command: ChangeOwnershipCommand
51 before(async function () {
54 servers = await flushAndRunMultipleServers(2)
55 await setAccessTokensToServers(servers)
56 await setDefaultVideoChannel(servers)
58 await servers[0].configCommand.updateCustomSubConfig({
69 const videoQuota = 42000000
72 accessToken: servers[0].accessToken,
73 username: firstUser.username,
74 password: firstUser.password,
75 videoQuota: videoQuota
79 accessToken: servers[0].accessToken,
80 username: secondUser.username,
81 password: secondUser.password,
82 videoQuota: videoQuota
85 firstUserToken = await userLogin(servers[0], firstUser)
86 secondUserToken = await userLogin(servers[0], secondUser)
89 const res = await getMyUserInformation(servers[0].url, firstUserToken)
90 const firstUserInformation: User = res.body
91 firstUserChannelId = firstUserInformation.videoChannels[0].id
95 const res = await getMyUserInformation(servers[0].url, secondUserToken)
96 const secondUserInformation: User = res.body
97 secondUserChannelId = secondUserInformation.videoChannels[0].id
101 const videoAttributes = {
102 name: 'my super name',
103 description: 'my super description'
105 const res = await uploadVideo(servers[0].url, firstUserToken, videoAttributes)
107 const resVideo = await getVideo(servers[0].url, res.body.video.id)
108 servers[0].video = resVideo.body
112 const attributes = { name: 'live', channelId: firstUserChannelId, privacy: VideoPrivacy.PUBLIC }
113 const video = await servers[0].liveCommand.create({ token: firstUserToken, fields: attributes })
118 command = servers[0].changeOwnershipCommand
120 await doubleFollow(servers[0], servers[1])
123 it('Should not have video change ownership', async function () {
125 const body = await command.list({ token: firstUserToken })
127 expect(body.total).to.equal(0)
128 expect(body.data).to.be.an('array')
129 expect(body.data.length).to.equal(0)
133 const body = await command.list({ token: secondUserToken })
135 expect(body.total).to.equal(0)
136 expect(body.data).to.be.an('array')
137 expect(body.data.length).to.equal(0)
141 it('Should send a request to change ownership of a video', async function () {
144 await command.create({ token: firstUserToken, videoId: servers[0].video.id, username: secondUser.username })
147 it('Should only return a request to change ownership for the second user', async function () {
149 const body = await command.list({ token: firstUserToken })
151 expect(body.total).to.equal(0)
152 expect(body.data).to.be.an('array')
153 expect(body.data.length).to.equal(0)
157 const body = await command.list({ token: secondUserToken })
159 expect(body.total).to.equal(1)
160 expect(body.data).to.be.an('array')
161 expect(body.data.length).to.equal(1)
163 lastRequestId = body.data[0].id
167 it('Should accept the same change ownership request without crashing', async function () {
170 await command.create({ token: firstUserToken, videoId: servers[0].video.id, username: secondUser.username })
173 it('Should not create multiple change ownership requests while one is waiting', async function () {
176 const body = await command.list({ token: secondUserToken })
178 expect(body.total).to.equal(1)
179 expect(body.data).to.be.an('array')
180 expect(body.data.length).to.equal(1)
183 it('Should not be possible to refuse the change of ownership from first user', async function () {
186 await command.refuse({ token: firstUserToken, ownershipId: lastRequestId, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
189 it('Should be possible to refuse the change of ownership from second user', async function () {
192 await command.refuse({ token: secondUserToken, ownershipId: lastRequestId })
195 it('Should send a new request to change ownership of a video', async function () {
198 await command.create({ token: firstUserToken, videoId: servers[0].video.id, username: secondUser.username })
201 it('Should return two requests to change ownership for the second user', async function () {
203 const body = await command.list({ token: firstUserToken })
205 expect(body.total).to.equal(0)
206 expect(body.data).to.be.an('array')
207 expect(body.data.length).to.equal(0)
211 const body = await command.list({ token: secondUserToken })
213 expect(body.total).to.equal(2)
214 expect(body.data).to.be.an('array')
215 expect(body.data.length).to.equal(2)
217 lastRequestId = body.data[0].id
221 it('Should not be possible to accept the change of ownership from first user', async function () {
224 await command.accept({
225 token: firstUserToken,
226 ownershipId: lastRequestId,
227 channelId: secondUserChannelId,
228 expectedStatus: HttpStatusCode.FORBIDDEN_403
232 it('Should be possible to accept the change of ownership from second user', async function () {
235 await command.accept({ token: secondUserToken, ownershipId: lastRequestId, channelId: secondUserChannelId })
237 await waitJobs(servers)
240 it('Should have the channel of the video updated', async function () {
241 for (const server of servers) {
242 const res = await getVideo(server.url, servers[0].video.uuid)
244 const video: VideoDetails = res.body
246 expect(video.name).to.equal('my super name')
247 expect(video.channel.displayName).to.equal('Main second channel')
248 expect(video.channel.name).to.equal('second_channel')
252 it('Should send a request to change ownership of a live', async function () {
255 await command.create({ token: firstUserToken, videoId: liveId, username: secondUser.username })
257 const body = await command.list({ token: secondUserToken })
259 expect(body.total).to.equal(3)
260 expect(body.data.length).to.equal(3)
262 lastRequestId = body.data[0].id
265 it('Should accept a live ownership change', async function () {
268 await command.accept({ token: secondUserToken, ownershipId: lastRequestId, channelId: secondUserChannelId })
270 await waitJobs(servers)
272 for (const server of servers) {
273 const res = await getVideo(server.url, servers[0].video.uuid)
275 const video: VideoDetails = res.body
277 expect(video.name).to.equal('my super name')
278 expect(video.channel.displayName).to.equal('Main second channel')
279 expect(video.channel.name).to.equal('second_channel')
283 after(async function () {
284 await cleanupTests(servers)
288 describe('Test video change ownership - quota too small', function () {
289 let server: ServerInfo
292 password: 'My great password'
296 password: 'My other password'
298 let firstUserToken = ''
299 let secondUserToken = ''
300 let lastRequestId: number
302 before(async function () {
306 server = await flushAndRunServer(1)
307 await setAccessTokensToServers([ server ])
309 const videoQuota = 42000000
310 const limitedVideoQuota = 10
313 accessToken: server.accessToken,
314 username: firstUser.username,
315 password: firstUser.password,
316 videoQuota: videoQuota
320 accessToken: server.accessToken,
321 username: secondUser.username,
322 password: secondUser.password,
323 videoQuota: limitedVideoQuota
326 firstUserToken = await userLogin(server, firstUser)
327 secondUserToken = await userLogin(server, secondUser)
329 // Upload some videos on the server
330 const video1Attributes = {
331 name: 'my super name',
332 description: 'my super description'
334 await uploadVideo(server.url, firstUserToken, video1Attributes)
336 await waitJobs(server)
338 const res = await getVideosList(server.url)
339 const videos = res.body.data
341 expect(videos.length).to.equal(1)
343 server.video = videos.find(video => video.name === 'my super name')
346 it('Should send a request to change ownership of a video', async function () {
349 await server.changeOwnershipCommand.create({ token: firstUserToken, videoId: server.video.id, username: secondUser.username })
352 it('Should only return a request to change ownership for the second user', async function () {
354 const body = await server.changeOwnershipCommand.list({ token: firstUserToken })
356 expect(body.total).to.equal(0)
357 expect(body.data).to.be.an('array')
358 expect(body.data.length).to.equal(0)
362 const body = await server.changeOwnershipCommand.list({ token: secondUserToken })
364 expect(body.total).to.equal(1)
365 expect(body.data).to.be.an('array')
366 expect(body.data.length).to.equal(1)
368 lastRequestId = body.data[0].id
372 it('Should not be possible to accept the change of ownership from second user because of exceeded quota', async function () {
375 const secondUserInformationResponse = await getMyUserInformation(server.url, secondUserToken)
376 const secondUserInformation: User = secondUserInformationResponse.body
377 const channelId = secondUserInformation.videoChannels[0].id
379 await server.changeOwnershipCommand.accept({
380 token: secondUserToken,
381 ownershipId: lastRequestId,
383 expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413
387 after(async function () {
388 await cleanupTests([ server ])