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,
10 flushAndRunMultipleServers,
15 setAccessTokensToServers,
16 setDefaultVideoChannel,
18 } from '../../../../shared/extra-utils'
19 import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
20 import { VideoDetails, VideoPrivacy } from '../../../../shared/models/videos'
22 const expect = chai.expect
24 describe('Test video change ownership - nominal', function () {
25 let servers: ServerInfo[] = []
27 const firstUser = 'first'
28 const secondUser = 'second'
30 let firstUserToken = ''
31 let firstUserChannelId: number
33 let secondUserToken = ''
34 let secondUserChannelId: number
36 let lastRequestId: number
40 let command: ChangeOwnershipCommand
42 before(async function () {
45 servers = await flushAndRunMultipleServers(2)
46 await setAccessTokensToServers(servers)
47 await setDefaultVideoChannel(servers)
49 await servers[0].configCommand.updateCustomSubConfig({
60 firstUserToken = await servers[0].usersCommand.generateUserAndToken(firstUser)
61 secondUserToken = await servers[0].usersCommand.generateUserAndToken(secondUser)
64 const { videoChannels } = await servers[0].usersCommand.getMyInfo({ token: firstUserToken })
65 firstUserChannelId = videoChannels[0].id
69 const { videoChannels } = await servers[0].usersCommand.getMyInfo({ token: secondUserToken })
70 secondUserChannelId = videoChannels[0].id
74 const videoAttributes = {
75 name: 'my super name',
76 description: 'my super description'
78 const res = await uploadVideo(servers[0].url, firstUserToken, videoAttributes)
80 const resVideo = await getVideo(servers[0].url, res.body.video.id)
81 servers[0].video = resVideo.body
85 const attributes = { name: 'live', channelId: firstUserChannelId, privacy: VideoPrivacy.PUBLIC }
86 const video = await servers[0].liveCommand.create({ token: firstUserToken, fields: attributes })
91 command = servers[0].changeOwnershipCommand
93 await doubleFollow(servers[0], servers[1])
96 it('Should not have video change ownership', async function () {
98 const body = await command.list({ token: firstUserToken })
100 expect(body.total).to.equal(0)
101 expect(body.data).to.be.an('array')
102 expect(body.data.length).to.equal(0)
106 const body = await command.list({ token: secondUserToken })
108 expect(body.total).to.equal(0)
109 expect(body.data).to.be.an('array')
110 expect(body.data.length).to.equal(0)
114 it('Should send a request to change ownership of a video', async function () {
117 await command.create({ token: firstUserToken, videoId: servers[0].video.id, username: secondUser })
120 it('Should only return a request to change ownership for the second user', async function () {
122 const body = await command.list({ token: firstUserToken })
124 expect(body.total).to.equal(0)
125 expect(body.data).to.be.an('array')
126 expect(body.data.length).to.equal(0)
130 const body = await command.list({ token: secondUserToken })
132 expect(body.total).to.equal(1)
133 expect(body.data).to.be.an('array')
134 expect(body.data.length).to.equal(1)
136 lastRequestId = body.data[0].id
140 it('Should accept the same change ownership request without crashing', async function () {
143 await command.create({ token: firstUserToken, videoId: servers[0].video.id, username: secondUser })
146 it('Should not create multiple change ownership requests while one is waiting', async function () {
149 const body = await command.list({ token: secondUserToken })
151 expect(body.total).to.equal(1)
152 expect(body.data).to.be.an('array')
153 expect(body.data.length).to.equal(1)
156 it('Should not be possible to refuse the change of ownership from first user', async function () {
159 await command.refuse({ token: firstUserToken, ownershipId: lastRequestId, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
162 it('Should be possible to refuse the change of ownership from second user', async function () {
165 await command.refuse({ token: secondUserToken, ownershipId: lastRequestId })
168 it('Should send a new request to change ownership of a video', async function () {
171 await command.create({ token: firstUserToken, videoId: servers[0].video.id, username: secondUser })
174 it('Should return two requests to change ownership for the second user', async function () {
176 const body = await command.list({ token: firstUserToken })
178 expect(body.total).to.equal(0)
179 expect(body.data).to.be.an('array')
180 expect(body.data.length).to.equal(0)
184 const body = await command.list({ token: secondUserToken })
186 expect(body.total).to.equal(2)
187 expect(body.data).to.be.an('array')
188 expect(body.data.length).to.equal(2)
190 lastRequestId = body.data[0].id
194 it('Should not be possible to accept the change of ownership from first user', async function () {
197 await command.accept({
198 token: firstUserToken,
199 ownershipId: lastRequestId,
200 channelId: secondUserChannelId,
201 expectedStatus: HttpStatusCode.FORBIDDEN_403
205 it('Should be possible to accept the change of ownership from second user', async function () {
208 await command.accept({ token: secondUserToken, ownershipId: lastRequestId, channelId: secondUserChannelId })
210 await waitJobs(servers)
213 it('Should have the channel of the video updated', async function () {
214 for (const server of servers) {
215 const res = await getVideo(server.url, servers[0].video.uuid)
217 const video: VideoDetails = res.body
219 expect(video.name).to.equal('my super name')
220 expect(video.channel.displayName).to.equal('Main second channel')
221 expect(video.channel.name).to.equal('second_channel')
225 it('Should send a request to change ownership of a live', async function () {
228 await command.create({ token: firstUserToken, videoId: liveId, username: secondUser })
230 const body = await command.list({ token: secondUserToken })
232 expect(body.total).to.equal(3)
233 expect(body.data.length).to.equal(3)
235 lastRequestId = body.data[0].id
238 it('Should accept a live ownership change', async function () {
241 await command.accept({ token: secondUserToken, ownershipId: lastRequestId, channelId: secondUserChannelId })
243 await waitJobs(servers)
245 for (const server of servers) {
246 const res = await getVideo(server.url, servers[0].video.uuid)
248 const video: VideoDetails = res.body
250 expect(video.name).to.equal('my super name')
251 expect(video.channel.displayName).to.equal('Main second channel')
252 expect(video.channel.name).to.equal('second_channel')
256 after(async function () {
257 await cleanupTests(servers)
261 describe('Test video change ownership - quota too small', function () {
262 let server: ServerInfo
263 const firstUser = 'first'
264 const secondUser = 'second'
266 let firstUserToken = ''
267 let secondUserToken = ''
268 let lastRequestId: number
270 before(async function () {
274 server = await flushAndRunServer(1)
275 await setAccessTokensToServers([ server ])
277 await server.usersCommand.create({ username: secondUser, videoQuota: 10 })
279 firstUserToken = await server.usersCommand.generateUserAndToken(firstUser)
280 secondUserToken = await server.loginCommand.getAccessToken(secondUser)
282 // Upload some videos on the server
283 const video1Attributes = {
284 name: 'my super name',
285 description: 'my super description'
287 await uploadVideo(server.url, firstUserToken, video1Attributes)
289 await waitJobs(server)
291 const res = await getVideosList(server.url)
292 const videos = res.body.data
294 expect(videos.length).to.equal(1)
296 server.video = videos.find(video => video.name === 'my super name')
299 it('Should send a request to change ownership of a video', async function () {
302 await server.changeOwnershipCommand.create({ token: firstUserToken, videoId: server.video.id, username: secondUser })
305 it('Should only return a request to change ownership for the second user', async function () {
307 const body = await server.changeOwnershipCommand.list({ token: firstUserToken })
309 expect(body.total).to.equal(0)
310 expect(body.data).to.be.an('array')
311 expect(body.data.length).to.equal(0)
315 const body = await server.changeOwnershipCommand.list({ token: secondUserToken })
317 expect(body.total).to.equal(1)
318 expect(body.data).to.be.an('array')
319 expect(body.data.length).to.equal(1)
321 lastRequestId = body.data[0].id
325 it('Should not be possible to accept the change of ownership from second user because of exceeded quota', async function () {
328 const { videoChannels } = await server.usersCommand.getMyInfo({ token: secondUserToken })
329 const channelId = videoChannels[0].id
331 await server.changeOwnershipCommand.accept({
332 token: secondUserToken,
333 ownershipId: lastRequestId,
335 expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413
339 after(async function () {
340 await cleanupTests([ server ])