1 /* tslint:disable:no-unused-expression */
3 import * as chai from 'chai'
8 createUser, doubleFollow, flushAndRunMultipleServers,
11 getVideoChangeOwnershipList,
14 refuseChangeOwnership,
17 setAccessTokensToServers,
21 } from '../../../../shared/extra-utils'
22 import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
23 import { User } from '../../../../shared/models/users'
24 import { VideoDetails } 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'
38 let firstUserAccessToken = ''
39 let secondUserAccessToken = ''
40 let lastRequestChangeOwnershipId = undefined
42 before(async function () {
45 servers = await flushAndRunMultipleServers(2)
46 await setAccessTokensToServers(servers)
48 const videoQuota = 42000000
50 url: servers[ 0 ].url,
51 accessToken: servers[ 0 ].accessToken,
52 username: firstUser.username,
53 password: firstUser.password,
54 videoQuota: videoQuota
57 url: servers[ 0 ].url,
58 accessToken: servers[ 0 ].accessToken,
59 username: secondUser.username,
60 password: secondUser.password,
61 videoQuota: videoQuota
64 firstUserAccessToken = await userLogin(servers[0], firstUser)
65 secondUserAccessToken = await userLogin(servers[0], secondUser)
67 const videoAttributes = {
68 name: 'my super name',
69 description: 'my super description'
71 await uploadVideo(servers[0].url, firstUserAccessToken, videoAttributes)
73 await waitJobs(servers)
75 const res = await getVideosList(servers[0].url)
76 const videos = res.body.data
78 expect(videos.length).to.equal(1)
80 const video = videos.find(video => video.name === 'my super name')
81 expect(video.channel.name).to.equal('first_channel')
82 servers[0].video = video
84 await doubleFollow(servers[0], servers[1])
87 it('Should not have video change ownership', async function () {
88 const resFirstUser = await getVideoChangeOwnershipList(servers[0].url, firstUserAccessToken)
90 expect(resFirstUser.body.total).to.equal(0)
91 expect(resFirstUser.body.data).to.be.an('array')
92 expect(resFirstUser.body.data.length).to.equal(0)
94 const resSecondUser = await getVideoChangeOwnershipList(servers[0].url, secondUserAccessToken)
96 expect(resSecondUser.body.total).to.equal(0)
97 expect(resSecondUser.body.data).to.be.an('array')
98 expect(resSecondUser.body.data.length).to.equal(0)
101 it('Should send a request to change ownership of a video', async function () {
104 await changeVideoOwnership(servers[0].url, firstUserAccessToken, servers[0].video.id, secondUser.username)
107 it('Should only return a request to change ownership for the second user', async function () {
108 const resFirstUser = await getVideoChangeOwnershipList(servers[0].url, firstUserAccessToken)
110 expect(resFirstUser.body.total).to.equal(0)
111 expect(resFirstUser.body.data).to.be.an('array')
112 expect(resFirstUser.body.data.length).to.equal(0)
114 const resSecondUser = await getVideoChangeOwnershipList(servers[0].url, secondUserAccessToken)
116 expect(resSecondUser.body.total).to.equal(1)
117 expect(resSecondUser.body.data).to.be.an('array')
118 expect(resSecondUser.body.data.length).to.equal(1)
120 lastRequestChangeOwnershipId = resSecondUser.body.data[0].id
123 it('Should accept the same change ownership request without crashing', async function () {
126 await changeVideoOwnership(servers[0].url, firstUserAccessToken, servers[0].video.id, secondUser.username)
129 it('Should not create multiple change ownership requests while one is waiting', async function () {
132 const resSecondUser = await getVideoChangeOwnershipList(servers[0].url, secondUserAccessToken)
134 expect(resSecondUser.body.total).to.equal(1)
135 expect(resSecondUser.body.data).to.be.an('array')
136 expect(resSecondUser.body.data.length).to.equal(1)
139 it('Should not be possible to refuse the change of ownership from first user', async function () {
142 await refuseChangeOwnership(servers[0].url, firstUserAccessToken, lastRequestChangeOwnershipId, 403)
145 it('Should be possible to refuse the change of ownership from second user', async function () {
148 await refuseChangeOwnership(servers[0].url, secondUserAccessToken, lastRequestChangeOwnershipId)
151 it('Should send a new request to change ownership of a video', async function () {
154 await changeVideoOwnership(servers[0].url, firstUserAccessToken, servers[0].video.id, secondUser.username)
157 it('Should return two requests to change ownership for the second user', async function () {
158 const resFirstUser = await getVideoChangeOwnershipList(servers[0].url, firstUserAccessToken)
160 expect(resFirstUser.body.total).to.equal(0)
161 expect(resFirstUser.body.data).to.be.an('array')
162 expect(resFirstUser.body.data.length).to.equal(0)
164 const resSecondUser = await getVideoChangeOwnershipList(servers[0].url, secondUserAccessToken)
166 expect(resSecondUser.body.total).to.equal(2)
167 expect(resSecondUser.body.data).to.be.an('array')
168 expect(resSecondUser.body.data.length).to.equal(2)
170 lastRequestChangeOwnershipId = resSecondUser.body.data[0].id
173 it('Should not be possible to accept the change of ownership from first user', async function () {
176 const secondUserInformationResponse = await getMyUserInformation(servers[0].url, secondUserAccessToken)
177 const secondUserInformation: User = secondUserInformationResponse.body
178 const channelId = secondUserInformation.videoChannels[0].id
179 await acceptChangeOwnership(servers[0].url, firstUserAccessToken, lastRequestChangeOwnershipId, channelId, 403)
182 it('Should be possible to accept the change of ownership from second user', async function () {
185 const secondUserInformationResponse = await getMyUserInformation(servers[0].url, secondUserAccessToken)
186 const secondUserInformation: User = secondUserInformationResponse.body
187 const channelId = secondUserInformation.videoChannels[0].id
188 await acceptChangeOwnership(servers[0].url, secondUserAccessToken, lastRequestChangeOwnershipId, channelId)
190 await waitJobs(servers)
193 it('Should have video channel updated', async function () {
194 for (const server of servers) {
195 const res = await getVideo(server.url, servers[0].video.uuid)
197 const video: VideoDetails = res.body
199 expect(video.name).to.equal('my super name')
200 expect(video.channel.displayName).to.equal('Main second channel')
201 expect(video.channel.name).to.equal('second_channel')
205 after(async function () {
206 killallServers(servers)
210 describe('Test video change ownership - quota too small', function () {
211 let server: ServerInfo = undefined
214 password: 'My great password'
218 password: 'My other password'
220 let firstUserAccessToken = ''
221 let secondUserAccessToken = ''
222 let lastRequestChangeOwnershipId = undefined
224 before(async function () {
229 server = await runServer(1)
230 await setAccessTokensToServers([server])
232 const videoQuota = 42000000
233 const limitedVideoQuota = 10
236 accessToken: server.accessToken,
237 username: firstUser.username,
238 password: firstUser.password,
239 videoQuota: videoQuota
243 accessToken: server.accessToken,
244 username: secondUser.username,
245 password: secondUser.password,
246 videoQuota: limitedVideoQuota
249 firstUserAccessToken = await userLogin(server, firstUser)
250 secondUserAccessToken = await userLogin(server, secondUser)
252 // Upload some videos on the server
253 const video1Attributes = {
254 name: 'my super name',
255 description: 'my super description'
257 await uploadVideo(server.url, firstUserAccessToken, video1Attributes)
259 await waitJobs(server)
261 const res = await getVideosList(server.url)
262 const videos = res.body.data
264 expect(videos.length).to.equal(1)
266 server.video = videos.find(video => video.name === 'my super name')
269 it('Should send a request to change ownership of a video', async function () {
272 await changeVideoOwnership(server.url, firstUserAccessToken, server.video.id, secondUser.username)
275 it('Should only return a request to change ownership for the second user', async function () {
276 const resFirstUser = await getVideoChangeOwnershipList(server.url, firstUserAccessToken)
278 expect(resFirstUser.body.total).to.equal(0)
279 expect(resFirstUser.body.data).to.be.an('array')
280 expect(resFirstUser.body.data.length).to.equal(0)
282 const resSecondUser = await getVideoChangeOwnershipList(server.url, secondUserAccessToken)
284 expect(resSecondUser.body.total).to.equal(1)
285 expect(resSecondUser.body.data).to.be.an('array')
286 expect(resSecondUser.body.data.length).to.equal(1)
288 lastRequestChangeOwnershipId = resSecondUser.body.data[0].id
291 it('Should not be possible to accept the change of ownership from second user because of exceeded quota', async function () {
294 const secondUserInformationResponse = await getMyUserInformation(server.url, secondUserAccessToken)
295 const secondUserInformation: User = secondUserInformationResponse.body
296 const channelId = secondUserInformation.videoChannels[0].id
297 await acceptChangeOwnership(server.url, secondUserAccessToken, lastRequestChangeOwnershipId, channelId, 403)
300 after(async function () {
301 killallServers([server])