1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
3 import * as chai from 'chai'
11 flushAndRunMultipleServers,
15 getVideoChangeOwnershipList,
17 refuseChangeOwnership,
19 setAccessTokensToServers,
22 } from '../../../../shared/extra-utils'
23 import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
24 import { User } from '../../../../shared/models/users'
25 import { VideoDetails } from '../../../../shared/models/videos'
26 import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
28 const expect = chai.expect
30 describe('Test video change ownership - nominal', function () {
31 let servers: ServerInfo[] = []
34 password: 'My great password'
38 password: 'My other password'
40 let firstUserAccessToken = ''
41 let secondUserAccessToken = ''
42 let lastRequestChangeOwnershipId = ''
44 before(async function () {
47 servers = await flushAndRunMultipleServers(2)
48 await setAccessTokensToServers(servers)
50 const videoQuota = 42000000
53 accessToken: servers[0].accessToken,
54 username: firstUser.username,
55 password: firstUser.password,
56 videoQuota: videoQuota
60 accessToken: servers[0].accessToken,
61 username: secondUser.username,
62 password: secondUser.password,
63 videoQuota: videoQuota
66 firstUserAccessToken = await userLogin(servers[0], firstUser)
67 secondUserAccessToken = await userLogin(servers[0], secondUser)
69 const videoAttributes = {
70 name: 'my super name',
71 description: 'my super description'
73 await uploadVideo(servers[0].url, firstUserAccessToken, videoAttributes)
75 await waitJobs(servers)
77 const res = await getVideosList(servers[0].url)
78 const videos = res.body.data
80 expect(videos.length).to.equal(1)
82 const video = videos.find(video => video.name === 'my super name')
83 expect(video.channel.name).to.equal('first_channel')
84 servers[0].video = video
86 await doubleFollow(servers[0], servers[1])
89 it('Should not have video change ownership', async function () {
90 const resFirstUser = await getVideoChangeOwnershipList(servers[0].url, firstUserAccessToken)
92 expect(resFirstUser.body.total).to.equal(0)
93 expect(resFirstUser.body.data).to.be.an('array')
94 expect(resFirstUser.body.data.length).to.equal(0)
96 const resSecondUser = await getVideoChangeOwnershipList(servers[0].url, secondUserAccessToken)
98 expect(resSecondUser.body.total).to.equal(0)
99 expect(resSecondUser.body.data).to.be.an('array')
100 expect(resSecondUser.body.data.length).to.equal(0)
103 it('Should send a request to change ownership of a video', async function () {
106 await changeVideoOwnership(servers[0].url, firstUserAccessToken, servers[0].video.id, secondUser.username)
109 it('Should only return a request to change ownership for the second user', async function () {
110 const resFirstUser = await getVideoChangeOwnershipList(servers[0].url, firstUserAccessToken)
112 expect(resFirstUser.body.total).to.equal(0)
113 expect(resFirstUser.body.data).to.be.an('array')
114 expect(resFirstUser.body.data.length).to.equal(0)
116 const resSecondUser = await getVideoChangeOwnershipList(servers[0].url, secondUserAccessToken)
118 expect(resSecondUser.body.total).to.equal(1)
119 expect(resSecondUser.body.data).to.be.an('array')
120 expect(resSecondUser.body.data.length).to.equal(1)
122 lastRequestChangeOwnershipId = resSecondUser.body.data[0].id
125 it('Should accept the same change ownership request without crashing', async function () {
128 await changeVideoOwnership(servers[0].url, firstUserAccessToken, servers[0].video.id, secondUser.username)
131 it('Should not create multiple change ownership requests while one is waiting', async function () {
134 const resSecondUser = await getVideoChangeOwnershipList(servers[0].url, secondUserAccessToken)
136 expect(resSecondUser.body.total).to.equal(1)
137 expect(resSecondUser.body.data).to.be.an('array')
138 expect(resSecondUser.body.data.length).to.equal(1)
141 it('Should not be possible to refuse the change of ownership from first user', async function () {
144 await refuseChangeOwnership(servers[0].url, firstUserAccessToken, lastRequestChangeOwnershipId, HttpStatusCode.FORBIDDEN_403)
147 it('Should be possible to refuse the change of ownership from second user', async function () {
150 await refuseChangeOwnership(servers[0].url, secondUserAccessToken, lastRequestChangeOwnershipId)
153 it('Should send a new request to change ownership of a video', async function () {
156 await changeVideoOwnership(servers[0].url, firstUserAccessToken, servers[0].video.id, secondUser.username)
159 it('Should return two requests to change ownership for the second user', async function () {
160 const resFirstUser = await getVideoChangeOwnershipList(servers[0].url, firstUserAccessToken)
162 expect(resFirstUser.body.total).to.equal(0)
163 expect(resFirstUser.body.data).to.be.an('array')
164 expect(resFirstUser.body.data.length).to.equal(0)
166 const resSecondUser = await getVideoChangeOwnershipList(servers[0].url, secondUserAccessToken)
168 expect(resSecondUser.body.total).to.equal(2)
169 expect(resSecondUser.body.data).to.be.an('array')
170 expect(resSecondUser.body.data.length).to.equal(2)
172 lastRequestChangeOwnershipId = resSecondUser.body.data[0].id
175 it('Should not be possible to accept the change of ownership from first user', async function () {
178 const secondUserInformationResponse = await getMyUserInformation(servers[0].url, secondUserAccessToken)
179 const secondUserInformation: User = secondUserInformationResponse.body
180 const channelId = secondUserInformation.videoChannels[0].id
181 await acceptChangeOwnership(servers[0].url, firstUserAccessToken, lastRequestChangeOwnershipId, channelId, HttpStatusCode.FORBIDDEN_403)
184 it('Should be possible to accept the change of ownership from second user', async function () {
187 const secondUserInformationResponse = await getMyUserInformation(servers[0].url, secondUserAccessToken)
188 const secondUserInformation: User = secondUserInformationResponse.body
189 const channelId = secondUserInformation.videoChannels[0].id
190 await acceptChangeOwnership(servers[0].url, secondUserAccessToken, lastRequestChangeOwnershipId, channelId)
192 await waitJobs(servers)
195 it('Should have the channel of the video updated', async function () {
196 for (const server of servers) {
197 const res = await getVideo(server.url, servers[0].video.uuid)
199 const video: VideoDetails = res.body
201 expect(video.name).to.equal('my super name')
202 expect(video.channel.displayName).to.equal('Main second channel')
203 expect(video.channel.name).to.equal('second_channel')
207 after(async function () {
208 await cleanupTests(servers)
212 describe('Test video change ownership - quota too small', function () {
213 let server: ServerInfo
216 password: 'My great password'
220 password: 'My other password'
222 let firstUserAccessToken = ''
223 let secondUserAccessToken = ''
224 let lastRequestChangeOwnershipId = ''
226 before(async function () {
230 server = await flushAndRunServer(1)
231 await setAccessTokensToServers([ server ])
233 const videoQuota = 42000000
234 const limitedVideoQuota = 10
237 accessToken: server.accessToken,
238 username: firstUser.username,
239 password: firstUser.password,
240 videoQuota: videoQuota
244 accessToken: server.accessToken,
245 username: secondUser.username,
246 password: secondUser.password,
247 videoQuota: limitedVideoQuota
250 firstUserAccessToken = await userLogin(server, firstUser)
251 secondUserAccessToken = await userLogin(server, secondUser)
253 // Upload some videos on the server
254 const video1Attributes = {
255 name: 'my super name',
256 description: 'my super description'
258 await uploadVideo(server.url, firstUserAccessToken, video1Attributes)
260 await waitJobs(server)
262 const res = await getVideosList(server.url)
263 const videos = res.body.data
265 expect(videos.length).to.equal(1)
267 server.video = videos.find(video => video.name === 'my super name')
270 it('Should send a request to change ownership of a video', async function () {
273 await changeVideoOwnership(server.url, firstUserAccessToken, server.video.id, secondUser.username)
276 it('Should only return a request to change ownership for the second user', async function () {
277 const resFirstUser = await getVideoChangeOwnershipList(server.url, firstUserAccessToken)
279 expect(resFirstUser.body.total).to.equal(0)
280 expect(resFirstUser.body.data).to.be.an('array')
281 expect(resFirstUser.body.data.length).to.equal(0)
283 const resSecondUser = await getVideoChangeOwnershipList(server.url, secondUserAccessToken)
285 expect(resSecondUser.body.total).to.equal(1)
286 expect(resSecondUser.body.data).to.be.an('array')
287 expect(resSecondUser.body.data.length).to.equal(1)
289 lastRequestChangeOwnershipId = resSecondUser.body.data[0].id
292 it('Should not be possible to accept the change of ownership from second user because of exceeded quota', async function () {
295 const secondUserInformationResponse = await getMyUserInformation(server.url, secondUserAccessToken)
296 const secondUserInformation: User = secondUserInformationResponse.body
297 const channelId = secondUserInformation.videoChannels[0].id
299 await acceptChangeOwnership(
301 secondUserAccessToken,
302 lastRequestChangeOwnershipId,
304 HttpStatusCode.PAYLOAD_TOO_LARGE_413
308 after(async function () {
309 await cleanupTests([ server ])