]>
Commit | Line | Data |
---|---|---|
a1587156 | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
74d63469 | 2 | |
86347717 | 3 | import { expect } 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 | 16 | |
74d63469 | 17 | describe('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 () { | |
83903cb6 | 133 | await command.create({ token: firstUserToken, videoId: servers[0].store.videoCreated.id, username: secondUser }) |
74d63469 GR |
134 | }) |
135 | ||
136 | it('Should not create multiple change ownership requests while one is waiting', async function () { | |
72cbfc56 | 137 | const body = await command.list({ token: secondUserToken }) |
74d63469 | 138 | |
72cbfc56 C |
139 | expect(body.total).to.equal(1) |
140 | expect(body.data).to.be.an('array') | |
141 | expect(body.data.length).to.equal(1) | |
74d63469 GR |
142 | }) |
143 | ||
144 | it('Should not be possible to refuse the change of ownership from first user', async function () { | |
72cbfc56 | 145 | await command.refuse({ token: firstUserToken, ownershipId: lastRequestId, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) |
74d63469 GR |
146 | }) |
147 | ||
148 | it('Should be possible to refuse the change of ownership from second user', async function () { | |
72cbfc56 | 149 | await command.refuse({ token: secondUserToken, ownershipId: lastRequestId }) |
74d63469 GR |
150 | }) |
151 | ||
152 | it('Should send a new request to change ownership of a video', async function () { | |
153 | this.timeout(15000) | |
154 | ||
83903cb6 | 155 | await command.create({ token: firstUserToken, videoId: servers[0].store.videoCreated.id, username: secondUser }) |
74d63469 GR |
156 | }) |
157 | ||
158 | it('Should return two requests to change ownership for the second user', async function () { | |
72cbfc56 C |
159 | { |
160 | const body = await command.list({ token: firstUserToken }) | |
74d63469 | 161 | |
72cbfc56 C |
162 | expect(body.total).to.equal(0) |
163 | expect(body.data).to.be.an('array') | |
164 | expect(body.data.length).to.equal(0) | |
165 | } | |
74d63469 | 166 | |
72cbfc56 C |
167 | { |
168 | const body = await command.list({ token: secondUserToken }) | |
74d63469 | 169 | |
72cbfc56 C |
170 | expect(body.total).to.equal(2) |
171 | expect(body.data).to.be.an('array') | |
172 | expect(body.data.length).to.equal(2) | |
74d63469 | 173 | |
72cbfc56 C |
174 | lastRequestId = body.data[0].id |
175 | } | |
74d63469 GR |
176 | }) |
177 | ||
178 | it('Should not be possible to accept the change of ownership from first user', async function () { | |
72cbfc56 C |
179 | await command.accept({ |
180 | token: firstUserToken, | |
181 | ownershipId: lastRequestId, | |
182 | channelId: secondUserChannelId, | |
183 | expectedStatus: HttpStatusCode.FORBIDDEN_403 | |
184 | }) | |
74d63469 GR |
185 | }) |
186 | ||
187 | it('Should be possible to accept the change of ownership from second user', async function () { | |
72cbfc56 | 188 | await command.accept({ token: secondUserToken, ownershipId: lastRequestId, channelId: secondUserChannelId }) |
5cf84858 C |
189 | |
190 | await waitJobs(servers) | |
191 | }) | |
192 | ||
f92e7f76 | 193 | it('Should have the channel of the video updated', async function () { |
5cf84858 | 194 | for (const server of servers) { |
83903cb6 | 195 | const video = await server.videos.get({ id: servers[0].store.videoCreated.uuid }) |
5cf84858 C |
196 | |
197 | expect(video.name).to.equal('my super name') | |
198 | expect(video.channel.displayName).to.equal('Main second channel') | |
199 | expect(video.channel.name).to.equal('second_channel') | |
200 | } | |
74d63469 GR |
201 | }) |
202 | ||
21b5c298 C |
203 | it('Should send a request to change ownership of a live', async function () { |
204 | this.timeout(15000) | |
205 | ||
7926c5f9 | 206 | await command.create({ token: firstUserToken, videoId: liveId, username: secondUser }) |
21b5c298 | 207 | |
72cbfc56 | 208 | const body = await command.list({ token: secondUserToken }) |
21b5c298 | 209 | |
72cbfc56 C |
210 | expect(body.total).to.equal(3) |
211 | expect(body.data.length).to.equal(3) | |
21b5c298 | 212 | |
72cbfc56 | 213 | lastRequestId = body.data[0].id |
21b5c298 C |
214 | }) |
215 | ||
216 | it('Should accept a live ownership change', async function () { | |
217 | this.timeout(20000) | |
218 | ||
72cbfc56 | 219 | await command.accept({ token: secondUserToken, ownershipId: lastRequestId, channelId: secondUserChannelId }) |
21b5c298 C |
220 | |
221 | await waitJobs(servers) | |
222 | ||
223 | for (const server of servers) { | |
83903cb6 | 224 | const video = await server.videos.get({ id: servers[0].store.videoCreated.uuid }) |
21b5c298 C |
225 | |
226 | expect(video.name).to.equal('my super name') | |
227 | expect(video.channel.displayName).to.equal('Main second channel') | |
228 | expect(video.channel.name).to.equal('second_channel') | |
229 | } | |
230 | }) | |
231 | ||
48f07b4a C |
232 | after(async function () { |
233 | await cleanupTests(servers) | |
74d63469 GR |
234 | }) |
235 | }) | |
236 | ||
237 | describe('Test video change ownership - quota too small', function () { | |
254d3579 | 238 | let server: PeerTubeServer |
7926c5f9 C |
239 | const firstUser = 'first' |
240 | const secondUser = 'second' | |
241 | ||
72cbfc56 C |
242 | let firstUserToken = '' |
243 | let secondUserToken = '' | |
244 | let lastRequestId: number | |
74d63469 GR |
245 | |
246 | before(async function () { | |
247 | this.timeout(50000) | |
248 | ||
249 | // Run one server | |
254d3579 | 250 | server = await createSingleServer(1) |
a1587156 | 251 | await setAccessTokensToServers([ server ]) |
74d63469 | 252 | |
89d241a7 | 253 | await server.users.create({ username: secondUser, videoQuota: 10 }) |
74d63469 | 254 | |
89d241a7 C |
255 | firstUserToken = await server.users.generateUserAndToken(firstUser) |
256 | secondUserToken = await server.login.getAccessToken(secondUser) | |
74d63469 GR |
257 | |
258 | // Upload some videos on the server | |
d23dd9fb | 259 | const attributes = { |
74d63469 GR |
260 | name: 'my super name', |
261 | description: 'my super description' | |
262 | } | |
89d241a7 | 263 | await server.videos.upload({ token: firstUserToken, attributes }) |
74d63469 GR |
264 | |
265 | await waitJobs(server) | |
266 | ||
89d241a7 | 267 | const { data } = await server.videos.list() |
d23dd9fb | 268 | expect(data.length).to.equal(1) |
74d63469 | 269 | |
83903cb6 | 270 | server.store.videoCreated = data.find(video => video.name === 'my super name') |
74d63469 GR |
271 | }) |
272 | ||
273 | it('Should send a request to change ownership of a video', async function () { | |
274 | this.timeout(15000) | |
275 | ||
83903cb6 | 276 | await server.changeOwnership.create({ token: firstUserToken, videoId: server.store.videoCreated.id, username: secondUser }) |
74d63469 GR |
277 | }) |
278 | ||
279 | it('Should only return a request to change ownership for the second user', async function () { | |
72cbfc56 | 280 | { |
89d241a7 | 281 | const body = await server.changeOwnership.list({ token: firstUserToken }) |
74d63469 | 282 | |
72cbfc56 C |
283 | expect(body.total).to.equal(0) |
284 | expect(body.data).to.be.an('array') | |
285 | expect(body.data.length).to.equal(0) | |
286 | } | |
74d63469 | 287 | |
72cbfc56 | 288 | { |
89d241a7 | 289 | const body = await server.changeOwnership.list({ token: secondUserToken }) |
74d63469 | 290 | |
72cbfc56 C |
291 | expect(body.total).to.equal(1) |
292 | expect(body.data).to.be.an('array') | |
293 | expect(body.data.length).to.equal(1) | |
74d63469 | 294 | |
72cbfc56 C |
295 | lastRequestId = body.data[0].id |
296 | } | |
74d63469 GR |
297 | }) |
298 | ||
299 | it('Should not be possible to accept the change of ownership from second user because of exceeded quota', async function () { | |
89d241a7 | 300 | const { videoChannels } = await server.users.getMyInfo({ token: secondUserToken }) |
7926c5f9 | 301 | const channelId = videoChannels[0].id |
f2eb23cd | 302 | |
89d241a7 | 303 | await server.changeOwnership.accept({ |
72cbfc56 C |
304 | token: secondUserToken, |
305 | ownershipId: lastRequestId, | |
f2eb23cd | 306 | channelId, |
72cbfc56 C |
307 | expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413 |
308 | }) | |
74d63469 GR |
309 | }) |
310 | ||
7c3b7976 C |
311 | after(async function () { |
312 | await cleanupTests([ server ]) | |
74d63469 GR |
313 | }) |
314 | }) |