aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/tests/api/videos/video-change-ownership.ts185
1 files changed, 100 insertions, 85 deletions
diff --git a/server/tests/api/videos/video-change-ownership.ts b/server/tests/api/videos/video-change-ownership.ts
index 3c33cf015..1b81fe047 100644
--- a/server/tests/api/videos/video-change-ownership.ts
+++ b/server/tests/api/videos/video-change-ownership.ts
@@ -4,8 +4,7 @@ import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' 5import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
6import { 6import {
7 acceptChangeOwnership, 7 ChangeOwnershipCommand,
8 changeVideoOwnership,
9 cleanupTests, 8 cleanupTests,
10 createUser, 9 createUser,
11 doubleFollow, 10 doubleFollow,
@@ -13,9 +12,7 @@ import {
13 flushAndRunServer, 12 flushAndRunServer,
14 getMyUserInformation, 13 getMyUserInformation,
15 getVideo, 14 getVideo,
16 getVideoChangeOwnershipList,
17 getVideosList, 15 getVideosList,
18 refuseChangeOwnership,
19 ServerInfo, 16 ServerInfo,
20 setAccessTokensToServers, 17 setAccessTokensToServers,
21 setDefaultVideoChannel, 18 setDefaultVideoChannel,
@@ -39,16 +36,18 @@ describe('Test video change ownership - nominal', function () {
39 password: 'My other password' 36 password: 'My other password'
40 } 37 }
41 38
42 let firstUserAccessToken = '' 39 let firstUserToken = ''
43 let firstUserChannelId: number 40 let firstUserChannelId: number
44 41
45 let secondUserAccessToken = '' 42 let secondUserToken = ''
46 let secondUserChannelId: number 43 let secondUserChannelId: number
47 44
48 let lastRequestChangeOwnershipId = '' 45 let lastRequestId: number
49 46
50 let liveId: number 47 let liveId: number
51 48
49 let command: ChangeOwnershipCommand
50
52 before(async function () { 51 before(async function () {
53 this.timeout(50000) 52 this.timeout(50000)
54 53
@@ -83,17 +82,17 @@ describe('Test video change ownership - nominal', function () {
83 videoQuota: videoQuota 82 videoQuota: videoQuota
84 }) 83 })
85 84
86 firstUserAccessToken = await userLogin(servers[0], firstUser) 85 firstUserToken = await userLogin(servers[0], firstUser)
87 secondUserAccessToken = await userLogin(servers[0], secondUser) 86 secondUserToken = await userLogin(servers[0], secondUser)
88 87
89 { 88 {
90 const res = await getMyUserInformation(servers[0].url, firstUserAccessToken) 89 const res = await getMyUserInformation(servers[0].url, firstUserToken)
91 const firstUserInformation: User = res.body 90 const firstUserInformation: User = res.body
92 firstUserChannelId = firstUserInformation.videoChannels[0].id 91 firstUserChannelId = firstUserInformation.videoChannels[0].id
93 } 92 }
94 93
95 { 94 {
96 const res = await getMyUserInformation(servers[0].url, secondUserAccessToken) 95 const res = await getMyUserInformation(servers[0].url, secondUserToken)
97 const secondUserInformation: User = res.body 96 const secondUserInformation: User = res.body
98 secondUserChannelId = secondUserInformation.videoChannels[0].id 97 secondUserChannelId = secondUserInformation.videoChannels[0].id
99 } 98 }
@@ -103,7 +102,7 @@ describe('Test video change ownership - nominal', function () {
103 name: 'my super name', 102 name: 'my super name',
104 description: 'my super description' 103 description: 'my super description'
105 } 104 }
106 const res = await uploadVideo(servers[0].url, firstUserAccessToken, videoAttributes) 105 const res = await uploadVideo(servers[0].url, firstUserToken, videoAttributes)
107 106
108 const resVideo = await getVideo(servers[0].url, res.body.video.id) 107 const resVideo = await getVideo(servers[0].url, res.body.video.id)
109 servers[0].video = resVideo.body 108 servers[0].video = resVideo.body
@@ -111,116 +110,129 @@ describe('Test video change ownership - nominal', function () {
111 110
112 { 111 {
113 const attributes = { name: 'live', channelId: firstUserChannelId, privacy: VideoPrivacy.PUBLIC } 112 const attributes = { name: 'live', channelId: firstUserChannelId, privacy: VideoPrivacy.PUBLIC }
114 const video = await servers[0].liveCommand.create({ token: firstUserAccessToken, fields: attributes }) 113 const video = await servers[0].liveCommand.create({ token: firstUserToken, fields: attributes })
115 114
116 liveId = video.id 115 liveId = video.id
117 } 116 }
118 117
118 command = servers[0].changeOwnershipCommand
119
119 await doubleFollow(servers[0], servers[1]) 120 await doubleFollow(servers[0], servers[1])
120 }) 121 })
121 122
122 it('Should not have video change ownership', async function () { 123 it('Should not have video change ownership', async function () {
123 const resFirstUser = await getVideoChangeOwnershipList(servers[0].url, firstUserAccessToken) 124 {
125 const body = await command.list({ token: firstUserToken })
124 126
125 expect(resFirstUser.body.total).to.equal(0) 127 expect(body.total).to.equal(0)
126 expect(resFirstUser.body.data).to.be.an('array') 128 expect(body.data).to.be.an('array')
127 expect(resFirstUser.body.data.length).to.equal(0) 129 expect(body.data.length).to.equal(0)
130 }
128 131
129 const resSecondUser = await getVideoChangeOwnershipList(servers[0].url, secondUserAccessToken) 132 {
133 const body = await command.list({ token: secondUserToken })
130 134
131 expect(resSecondUser.body.total).to.equal(0) 135 expect(body.total).to.equal(0)
132 expect(resSecondUser.body.data).to.be.an('array') 136 expect(body.data).to.be.an('array')
133 expect(resSecondUser.body.data.length).to.equal(0) 137 expect(body.data.length).to.equal(0)
138 }
134 }) 139 })
135 140
136 it('Should send a request to change ownership of a video', async function () { 141 it('Should send a request to change ownership of a video', async function () {
137 this.timeout(15000) 142 this.timeout(15000)
138 143
139 await changeVideoOwnership(servers[0].url, firstUserAccessToken, servers[0].video.id, secondUser.username) 144 await command.create({ token: firstUserToken, videoId: servers[0].video.id, username: secondUser.username })
140 }) 145 })
141 146
142 it('Should only return a request to change ownership for the second user', async function () { 147 it('Should only return a request to change ownership for the second user', async function () {
143 const resFirstUser = await getVideoChangeOwnershipList(servers[0].url, firstUserAccessToken) 148 {
149 const body = await command.list({ token: firstUserToken })
144 150
145 expect(resFirstUser.body.total).to.equal(0) 151 expect(body.total).to.equal(0)
146 expect(resFirstUser.body.data).to.be.an('array') 152 expect(body.data).to.be.an('array')
147 expect(resFirstUser.body.data.length).to.equal(0) 153 expect(body.data.length).to.equal(0)
154 }
148 155
149 const resSecondUser = await getVideoChangeOwnershipList(servers[0].url, secondUserAccessToken) 156 {
157 const body = await command.list({ token: secondUserToken })
150 158
151 expect(resSecondUser.body.total).to.equal(1) 159 expect(body.total).to.equal(1)
152 expect(resSecondUser.body.data).to.be.an('array') 160 expect(body.data).to.be.an('array')
153 expect(resSecondUser.body.data.length).to.equal(1) 161 expect(body.data.length).to.equal(1)
154 162
155 lastRequestChangeOwnershipId = resSecondUser.body.data[0].id 163 lastRequestId = body.data[0].id
164 }
156 }) 165 })
157 166
158 it('Should accept the same change ownership request without crashing', async function () { 167 it('Should accept the same change ownership request without crashing', async function () {
159 this.timeout(10000) 168 this.timeout(10000)
160 169
161 await changeVideoOwnership(servers[0].url, firstUserAccessToken, servers[0].video.id, secondUser.username) 170 await command.create({ token: firstUserToken, videoId: servers[0].video.id, username: secondUser.username })
162 }) 171 })
163 172
164 it('Should not create multiple change ownership requests while one is waiting', async function () { 173 it('Should not create multiple change ownership requests while one is waiting', async function () {
165 this.timeout(10000) 174 this.timeout(10000)
166 175
167 const resSecondUser = await getVideoChangeOwnershipList(servers[0].url, secondUserAccessToken) 176 const body = await command.list({ token: secondUserToken })
168 177
169 expect(resSecondUser.body.total).to.equal(1) 178 expect(body.total).to.equal(1)
170 expect(resSecondUser.body.data).to.be.an('array') 179 expect(body.data).to.be.an('array')
171 expect(resSecondUser.body.data.length).to.equal(1) 180 expect(body.data.length).to.equal(1)
172 }) 181 })
173 182
174 it('Should not be possible to refuse the change of ownership from first user', async function () { 183 it('Should not be possible to refuse the change of ownership from first user', async function () {
175 this.timeout(10000) 184 this.timeout(10000)
176 185
177 await refuseChangeOwnership(servers[0].url, firstUserAccessToken, lastRequestChangeOwnershipId, HttpStatusCode.FORBIDDEN_403) 186 await command.refuse({ token: firstUserToken, ownershipId: lastRequestId, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
178 }) 187 })
179 188
180 it('Should be possible to refuse the change of ownership from second user', async function () { 189 it('Should be possible to refuse the change of ownership from second user', async function () {
181 this.timeout(10000) 190 this.timeout(10000)
182 191
183 await refuseChangeOwnership(servers[0].url, secondUserAccessToken, lastRequestChangeOwnershipId) 192 await command.refuse({ token: secondUserToken, ownershipId: lastRequestId })
184 }) 193 })
185 194
186 it('Should send a new request to change ownership of a video', async function () { 195 it('Should send a new request to change ownership of a video', async function () {
187 this.timeout(15000) 196 this.timeout(15000)
188 197
189 await changeVideoOwnership(servers[0].url, firstUserAccessToken, servers[0].video.id, secondUser.username) 198 await command.create({ token: firstUserToken, videoId: servers[0].video.id, username: secondUser.username })
190 }) 199 })
191 200
192 it('Should return two requests to change ownership for the second user', async function () { 201 it('Should return two requests to change ownership for the second user', async function () {
193 const resFirstUser = await getVideoChangeOwnershipList(servers[0].url, firstUserAccessToken) 202 {
203 const body = await command.list({ token: firstUserToken })
194 204
195 expect(resFirstUser.body.total).to.equal(0) 205 expect(body.total).to.equal(0)
196 expect(resFirstUser.body.data).to.be.an('array') 206 expect(body.data).to.be.an('array')
197 expect(resFirstUser.body.data.length).to.equal(0) 207 expect(body.data.length).to.equal(0)
208 }
198 209
199 const resSecondUser = await getVideoChangeOwnershipList(servers[0].url, secondUserAccessToken) 210 {
211 const body = await command.list({ token: secondUserToken })
200 212
201 expect(resSecondUser.body.total).to.equal(2) 213 expect(body.total).to.equal(2)
202 expect(resSecondUser.body.data).to.be.an('array') 214 expect(body.data).to.be.an('array')
203 expect(resSecondUser.body.data.length).to.equal(2) 215 expect(body.data.length).to.equal(2)
204 216
205 lastRequestChangeOwnershipId = resSecondUser.body.data[0].id 217 lastRequestId = body.data[0].id
218 }
206 }) 219 })
207 220
208 it('Should not be possible to accept the change of ownership from first user', async function () { 221 it('Should not be possible to accept the change of ownership from first user', async function () {
209 this.timeout(10000) 222 this.timeout(10000)
210 223
211 await acceptChangeOwnership( 224 await command.accept({
212 servers[0].url, 225 token: firstUserToken,
213 firstUserAccessToken, 226 ownershipId: lastRequestId,
214 lastRequestChangeOwnershipId, 227 channelId: secondUserChannelId,
215 secondUserChannelId, 228 expectedStatus: HttpStatusCode.FORBIDDEN_403
216 HttpStatusCode.FORBIDDEN_403 229 })
217 )
218 }) 230 })
219 231
220 it('Should be possible to accept the change of ownership from second user', async function () { 232 it('Should be possible to accept the change of ownership from second user', async function () {
221 this.timeout(10000) 233 this.timeout(10000)
222 234
223 await acceptChangeOwnership(servers[0].url, secondUserAccessToken, lastRequestChangeOwnershipId, secondUserChannelId) 235 await command.accept({ token: secondUserToken, ownershipId: lastRequestId, channelId: secondUserChannelId })
224 236
225 await waitJobs(servers) 237 await waitJobs(servers)
226 }) 238 })
@@ -240,20 +252,20 @@ describe('Test video change ownership - nominal', function () {
240 it('Should send a request to change ownership of a live', async function () { 252 it('Should send a request to change ownership of a live', async function () {
241 this.timeout(15000) 253 this.timeout(15000)
242 254
243 await changeVideoOwnership(servers[0].url, firstUserAccessToken, liveId, secondUser.username) 255 await command.create({ token: firstUserToken, videoId: liveId, username: secondUser.username })
244 256
245 const resSecondUser = await getVideoChangeOwnershipList(servers[0].url, secondUserAccessToken) 257 const body = await command.list({ token: secondUserToken })
246 258
247 expect(resSecondUser.body.total).to.equal(3) 259 expect(body.total).to.equal(3)
248 expect(resSecondUser.body.data.length).to.equal(3) 260 expect(body.data.length).to.equal(3)
249 261
250 lastRequestChangeOwnershipId = resSecondUser.body.data[0].id 262 lastRequestId = body.data[0].id
251 }) 263 })
252 264
253 it('Should accept a live ownership change', async function () { 265 it('Should accept a live ownership change', async function () {
254 this.timeout(20000) 266 this.timeout(20000)
255 267
256 await acceptChangeOwnership(servers[0].url, secondUserAccessToken, lastRequestChangeOwnershipId, secondUserChannelId) 268 await command.accept({ token: secondUserToken, ownershipId: lastRequestId, channelId: secondUserChannelId })
257 269
258 await waitJobs(servers) 270 await waitJobs(servers)
259 271
@@ -283,9 +295,9 @@ describe('Test video change ownership - quota too small', function () {
283 username: 'second', 295 username: 'second',
284 password: 'My other password' 296 password: 'My other password'
285 } 297 }
286 let firstUserAccessToken = '' 298 let firstUserToken = ''
287 let secondUserAccessToken = '' 299 let secondUserToken = ''
288 let lastRequestChangeOwnershipId = '' 300 let lastRequestId: number
289 301
290 before(async function () { 302 before(async function () {
291 this.timeout(50000) 303 this.timeout(50000)
@@ -311,15 +323,15 @@ describe('Test video change ownership - quota too small', function () {
311 videoQuota: limitedVideoQuota 323 videoQuota: limitedVideoQuota
312 }) 324 })
313 325
314 firstUserAccessToken = await userLogin(server, firstUser) 326 firstUserToken = await userLogin(server, firstUser)
315 secondUserAccessToken = await userLogin(server, secondUser) 327 secondUserToken = await userLogin(server, secondUser)
316 328
317 // Upload some videos on the server 329 // Upload some videos on the server
318 const video1Attributes = { 330 const video1Attributes = {
319 name: 'my super name', 331 name: 'my super name',
320 description: 'my super description' 332 description: 'my super description'
321 } 333 }
322 await uploadVideo(server.url, firstUserAccessToken, video1Attributes) 334 await uploadVideo(server.url, firstUserToken, video1Attributes)
323 335
324 await waitJobs(server) 336 await waitJobs(server)
325 337
@@ -334,39 +346,42 @@ describe('Test video change ownership - quota too small', function () {
334 it('Should send a request to change ownership of a video', async function () { 346 it('Should send a request to change ownership of a video', async function () {
335 this.timeout(15000) 347 this.timeout(15000)
336 348
337 await changeVideoOwnership(server.url, firstUserAccessToken, server.video.id, secondUser.username) 349 await server.changeOwnershipCommand.create({ token: firstUserToken, videoId: server.video.id, username: secondUser.username })
338 }) 350 })
339 351
340 it('Should only return a request to change ownership for the second user', async function () { 352 it('Should only return a request to change ownership for the second user', async function () {
341 const resFirstUser = await getVideoChangeOwnershipList(server.url, firstUserAccessToken) 353 {
354 const body = await server.changeOwnershipCommand.list({ token: firstUserToken })
342 355
343 expect(resFirstUser.body.total).to.equal(0) 356 expect(body.total).to.equal(0)
344 expect(resFirstUser.body.data).to.be.an('array') 357 expect(body.data).to.be.an('array')
345 expect(resFirstUser.body.data.length).to.equal(0) 358 expect(body.data.length).to.equal(0)
359 }
346 360
347 const resSecondUser = await getVideoChangeOwnershipList(server.url, secondUserAccessToken) 361 {
362 const body = await server.changeOwnershipCommand.list({ token: secondUserToken })
348 363
349 expect(resSecondUser.body.total).to.equal(1) 364 expect(body.total).to.equal(1)
350 expect(resSecondUser.body.data).to.be.an('array') 365 expect(body.data).to.be.an('array')
351 expect(resSecondUser.body.data.length).to.equal(1) 366 expect(body.data.length).to.equal(1)
352 367
353 lastRequestChangeOwnershipId = resSecondUser.body.data[0].id 368 lastRequestId = body.data[0].id
369 }
354 }) 370 })
355 371
356 it('Should not be possible to accept the change of ownership from second user because of exceeded quota', async function () { 372 it('Should not be possible to accept the change of ownership from second user because of exceeded quota', async function () {
357 this.timeout(10000) 373 this.timeout(10000)
358 374
359 const secondUserInformationResponse = await getMyUserInformation(server.url, secondUserAccessToken) 375 const secondUserInformationResponse = await getMyUserInformation(server.url, secondUserToken)
360 const secondUserInformation: User = secondUserInformationResponse.body 376 const secondUserInformation: User = secondUserInformationResponse.body
361 const channelId = secondUserInformation.videoChannels[0].id 377 const channelId = secondUserInformation.videoChannels[0].id
362 378
363 await acceptChangeOwnership( 379 await server.changeOwnershipCommand.accept({
364 server.url, 380 token: secondUserToken,
365 secondUserAccessToken, 381 ownershipId: lastRequestId,
366 lastRequestChangeOwnershipId,
367 channelId, 382 channelId,
368 HttpStatusCode.PAYLOAD_TOO_LARGE_413 383 expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413
369 ) 384 })
370 }) 385 })
371 386
372 after(async function () { 387 after(async function () {