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