]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/videos/video-change-ownership.ts
Merge branch 'release/5.1.0' into develop
[github/Chocobozzz/PeerTube.git] / server / tests / api / videos / video-change-ownership.ts
CommitLineData
a1587156 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
74d63469 2
86347717 3import { expect } from 'chai'
74d63469 4import {
72cbfc56 5 ChangeOwnershipCommand,
48f07b4a 6 cleanupTests,
254d3579
C
7 createMultipleServers,
8 createSingleServer,
4c7e60bc 9 doubleFollow,
254d3579 10 PeerTubeServer,
74d63469 11 setAccessTokensToServers,
21b5c298 12 setDefaultVideoChannel,
d23dd9fb 13 waitJobs
bf54587a 14} from '@shared/server-commands'
4c7e60bc 15import { HttpStatusCode, VideoPrivacy } from '@shared/models'
74d63469 16
74d63469 17describe('Test video change ownership - nominal', function () {
254d3579 18 let servers: PeerTubeServer[] = []
7926c5f9
C
19
20 const firstUser = 'first'
21 const secondUser = 'second'
21b5c298 22
72cbfc56 23 let firstUserToken = ''
21b5c298
C
24 let firstUserChannelId: number
25
72cbfc56 26 let secondUserToken = ''
21b5c298
C
27 let secondUserChannelId: number
28
72cbfc56 29 let lastRequestId: number
74d63469 30
21b5c298
C
31 let liveId: number
32
72cbfc56
C
33 let command: ChangeOwnershipCommand
34
74d63469
GR
35 before(async function () {
36 this.timeout(50000)
37
254d3579 38 servers = await createMultipleServers(2)
5cf84858 39 await setAccessTokensToServers(servers)
21b5c298
C
40 await setDefaultVideoChannel(servers)
41
89d241a7 42 await servers[0].config.updateCustomSubConfig({
65e6e260
C
43 newConfig: {
44 transcoding: {
45 enabled: false
46 },
47 live: {
48 enabled: true
49 }
21b5c298
C
50 }
51 })
74d63469 52
89d241a7
C
53 firstUserToken = await servers[0].users.generateUserAndToken(firstUser)
54 secondUserToken = await servers[0].users.generateUserAndToken(secondUser)
74d63469 55
21b5c298 56 {
89d241a7 57 const { videoChannels } = await servers[0].users.getMyInfo({ token: firstUserToken })
7926c5f9 58 firstUserChannelId = videoChannels[0].id
74d63469 59 }
74d63469 60
21b5c298 61 {
89d241a7 62 const { videoChannels } = await servers[0].users.getMyInfo({ token: secondUserToken })
7926c5f9 63 secondUserChannelId = videoChannels[0].id
21b5c298 64 }
74d63469 65
21b5c298 66 {
d23dd9fb 67 const attributes = {
21b5c298
C
68 name: 'my super name',
69 description: 'my super description'
70 }
89d241a7 71 const { id } = await servers[0].videos.upload({ token: firstUserToken, attributes })
74d63469 72
83903cb6 73 servers[0].store.videoCreated = await servers[0].videos.get({ id })
21b5c298 74 }
74d63469 75
21b5c298
C
76 {
77 const attributes = { name: 'live', channelId: firstUserChannelId, privacy: VideoPrivacy.PUBLIC }
89d241a7 78 const video = await servers[0].live.create({ token: firstUserToken, fields: attributes })
21b5c298 79
4f219914 80 liveId = video.id
21b5c298 81 }
5cf84858 82
89d241a7 83 command = servers[0].changeOwnership
72cbfc56 84
5cf84858 85 await doubleFollow(servers[0], servers[1])
74d63469
GR
86 })
87
88 it('Should not have video change ownership', async function () {
72cbfc56
C
89 {
90 const body = await command.list({ token: firstUserToken })
74d63469 91
72cbfc56
C
92 expect(body.total).to.equal(0)
93 expect(body.data).to.be.an('array')
94 expect(body.data.length).to.equal(0)
95 }
74d63469 96
72cbfc56
C
97 {
98 const body = await command.list({ token: secondUserToken })
74d63469 99
72cbfc56
C
100 expect(body.total).to.equal(0)
101 expect(body.data).to.be.an('array')
102 expect(body.data.length).to.equal(0)
103 }
74d63469
GR
104 })
105
106 it('Should send a request to change ownership of a video', async function () {
107 this.timeout(15000)
108
83903cb6 109 await command.create({ token: firstUserToken, videoId: servers[0].store.videoCreated.id, username: secondUser })
74d63469
GR
110 })
111
112 it('Should only return a request to change ownership for the second user', async function () {
72cbfc56
C
113 {
114 const body = await command.list({ token: firstUserToken })
74d63469 115
72cbfc56
C
116 expect(body.total).to.equal(0)
117 expect(body.data).to.be.an('array')
118 expect(body.data.length).to.equal(0)
119 }
74d63469 120
72cbfc56
C
121 {
122 const body = await command.list({ token: secondUserToken })
74d63469 123
72cbfc56
C
124 expect(body.total).to.equal(1)
125 expect(body.data).to.be.an('array')
126 expect(body.data.length).to.equal(1)
74d63469 127
72cbfc56
C
128 lastRequestId = body.data[0].id
129 }
74d63469
GR
130 })
131
132 it('Should accept the same change ownership request without crashing', async function () {
133 this.timeout(10000)
134
83903cb6 135 await command.create({ token: firstUserToken, videoId: servers[0].store.videoCreated.id, username: secondUser })
74d63469
GR
136 })
137
138 it('Should not create multiple change ownership requests while one is waiting', async function () {
139 this.timeout(10000)
140
72cbfc56 141 const body = await command.list({ token: secondUserToken })
74d63469 142
72cbfc56
C
143 expect(body.total).to.equal(1)
144 expect(body.data).to.be.an('array')
145 expect(body.data.length).to.equal(1)
74d63469
GR
146 })
147
148 it('Should not be possible to refuse the change of ownership from first user', async function () {
149 this.timeout(10000)
150
72cbfc56 151 await command.refuse({ token: firstUserToken, ownershipId: lastRequestId, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
74d63469
GR
152 })
153
154 it('Should be possible to refuse the change of ownership from second user', async function () {
155 this.timeout(10000)
156
72cbfc56 157 await command.refuse({ token: secondUserToken, ownershipId: lastRequestId })
74d63469
GR
158 })
159
160 it('Should send a new request to change ownership of a video', async function () {
161 this.timeout(15000)
162
83903cb6 163 await command.create({ token: firstUserToken, videoId: servers[0].store.videoCreated.id, username: secondUser })
74d63469
GR
164 })
165
166 it('Should return two requests to change ownership for the second user', async function () {
72cbfc56
C
167 {
168 const body = await command.list({ token: firstUserToken })
74d63469 169
72cbfc56
C
170 expect(body.total).to.equal(0)
171 expect(body.data).to.be.an('array')
172 expect(body.data.length).to.equal(0)
173 }
74d63469 174
72cbfc56
C
175 {
176 const body = await command.list({ token: secondUserToken })
74d63469 177
72cbfc56
C
178 expect(body.total).to.equal(2)
179 expect(body.data).to.be.an('array')
180 expect(body.data.length).to.equal(2)
74d63469 181
72cbfc56
C
182 lastRequestId = body.data[0].id
183 }
74d63469
GR
184 })
185
186 it('Should not be possible to accept the change of ownership from first user', async function () {
187 this.timeout(10000)
188
72cbfc56
C
189 await command.accept({
190 token: firstUserToken,
191 ownershipId: lastRequestId,
192 channelId: secondUserChannelId,
193 expectedStatus: HttpStatusCode.FORBIDDEN_403
194 })
74d63469
GR
195 })
196
197 it('Should be possible to accept the change of ownership from second user', async function () {
198 this.timeout(10000)
199
72cbfc56 200 await command.accept({ token: secondUserToken, ownershipId: lastRequestId, channelId: secondUserChannelId })
5cf84858
C
201
202 await waitJobs(servers)
203 })
204
f92e7f76 205 it('Should have the channel of the video updated', async function () {
5cf84858 206 for (const server of servers) {
83903cb6 207 const video = await server.videos.get({ id: servers[0].store.videoCreated.uuid })
5cf84858
C
208
209 expect(video.name).to.equal('my super name')
210 expect(video.channel.displayName).to.equal('Main second channel')
211 expect(video.channel.name).to.equal('second_channel')
212 }
74d63469
GR
213 })
214
21b5c298
C
215 it('Should send a request to change ownership of a live', async function () {
216 this.timeout(15000)
217
7926c5f9 218 await command.create({ token: firstUserToken, videoId: liveId, username: secondUser })
21b5c298 219
72cbfc56 220 const body = await command.list({ token: secondUserToken })
21b5c298 221
72cbfc56
C
222 expect(body.total).to.equal(3)
223 expect(body.data.length).to.equal(3)
21b5c298 224
72cbfc56 225 lastRequestId = body.data[0].id
21b5c298
C
226 })
227
228 it('Should accept a live ownership change', async function () {
229 this.timeout(20000)
230
72cbfc56 231 await command.accept({ token: secondUserToken, ownershipId: lastRequestId, channelId: secondUserChannelId })
21b5c298
C
232
233 await waitJobs(servers)
234
235 for (const server of servers) {
83903cb6 236 const video = await server.videos.get({ id: servers[0].store.videoCreated.uuid })
21b5c298
C
237
238 expect(video.name).to.equal('my super name')
239 expect(video.channel.displayName).to.equal('Main second channel')
240 expect(video.channel.name).to.equal('second_channel')
241 }
242 })
243
48f07b4a
C
244 after(async function () {
245 await cleanupTests(servers)
74d63469
GR
246 })
247})
248
249describe('Test video change ownership - quota too small', function () {
254d3579 250 let server: PeerTubeServer
7926c5f9
C
251 const firstUser = 'first'
252 const secondUser = 'second'
253
72cbfc56
C
254 let firstUserToken = ''
255 let secondUserToken = ''
256 let lastRequestId: number
74d63469
GR
257
258 before(async function () {
259 this.timeout(50000)
260
261 // Run one server
254d3579 262 server = await createSingleServer(1)
a1587156 263 await setAccessTokensToServers([ server ])
74d63469 264
89d241a7 265 await server.users.create({ username: secondUser, videoQuota: 10 })
74d63469 266
89d241a7
C
267 firstUserToken = await server.users.generateUserAndToken(firstUser)
268 secondUserToken = await server.login.getAccessToken(secondUser)
74d63469
GR
269
270 // Upload some videos on the server
d23dd9fb 271 const attributes = {
74d63469
GR
272 name: 'my super name',
273 description: 'my super description'
274 }
89d241a7 275 await server.videos.upload({ token: firstUserToken, attributes })
74d63469
GR
276
277 await waitJobs(server)
278
89d241a7 279 const { data } = await server.videos.list()
d23dd9fb 280 expect(data.length).to.equal(1)
74d63469 281
83903cb6 282 server.store.videoCreated = data.find(video => video.name === 'my super name')
74d63469
GR
283 })
284
285 it('Should send a request to change ownership of a video', async function () {
286 this.timeout(15000)
287
83903cb6 288 await server.changeOwnership.create({ token: firstUserToken, videoId: server.store.videoCreated.id, username: secondUser })
74d63469
GR
289 })
290
291 it('Should only return a request to change ownership for the second user', async function () {
72cbfc56 292 {
89d241a7 293 const body = await server.changeOwnership.list({ token: firstUserToken })
74d63469 294
72cbfc56
C
295 expect(body.total).to.equal(0)
296 expect(body.data).to.be.an('array')
297 expect(body.data.length).to.equal(0)
298 }
74d63469 299
72cbfc56 300 {
89d241a7 301 const body = await server.changeOwnership.list({ token: secondUserToken })
74d63469 302
72cbfc56
C
303 expect(body.total).to.equal(1)
304 expect(body.data).to.be.an('array')
305 expect(body.data.length).to.equal(1)
74d63469 306
72cbfc56
C
307 lastRequestId = body.data[0].id
308 }
74d63469
GR
309 })
310
311 it('Should not be possible to accept the change of ownership from second user because of exceeded quota', async function () {
312 this.timeout(10000)
313
89d241a7 314 const { videoChannels } = await server.users.getMyInfo({ token: secondUserToken })
7926c5f9 315 const channelId = videoChannels[0].id
f2eb23cd 316
89d241a7 317 await server.changeOwnership.accept({
72cbfc56
C
318 token: secondUserToken,
319 ownershipId: lastRequestId,
f2eb23cd 320 channelId,
72cbfc56
C
321 expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413
322 })
74d63469
GR
323 })
324
7c3b7976
C
325 after(async function () {
326 await cleanupTests([ server ])
74d63469
GR
327 })
328})