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