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