]>
Commit | Line | Data |
---|---|---|
a1587156 | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
74d63469 GR |
2 | |
3 | import * as chai from 'chai' | |
4 | import 'mocha' | |
5 | import { | |
6 | acceptChangeOwnership, | |
48f07b4a C |
7 | changeVideoOwnership, |
8 | cleanupTests, | |
210feb6c C |
9 | createUser, |
10 | doubleFollow, | |
11 | flushAndRunMultipleServers, | |
12 | flushAndRunServer, | |
74d63469 | 13 | getMyUserInformation, |
210feb6c | 14 | getVideo, |
74d63469 GR |
15 | getVideoChangeOwnershipList, |
16 | getVideosList, | |
74d63469 | 17 | refuseChangeOwnership, |
74d63469 GR |
18 | ServerInfo, |
19 | setAccessTokensToServers, | |
20 | uploadVideo, | |
210feb6c | 21 | userLogin |
94565d52 C |
22 | } from '../../../../shared/extra-utils' |
23 | import { waitJobs } from '../../../../shared/extra-utils/server/jobs' | |
74d63469 | 24 | import { User } from '../../../../shared/models/users' |
5cf84858 | 25 | import { VideoDetails } from '../../../../shared/models/videos' |
f2eb23cd | 26 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' |
74d63469 GR |
27 | |
28 | const expect = chai.expect | |
29 | ||
30 | describe('Test video change ownership - nominal', function () { | |
5cf84858 | 31 | let servers: ServerInfo[] = [] |
74d63469 GR |
32 | const firstUser = { |
33 | username: 'first', | |
34 | password: 'My great password' | |
35 | } | |
36 | const secondUser = { | |
37 | username: 'second', | |
38 | password: 'My other password' | |
39 | } | |
40 | let firstUserAccessToken = '' | |
41 | let secondUserAccessToken = '' | |
a1587156 | 42 | let lastRequestChangeOwnershipId = '' |
74d63469 GR |
43 | |
44 | before(async function () { | |
45 | this.timeout(50000) | |
46 | ||
5cf84858 C |
47 | servers = await flushAndRunMultipleServers(2) |
48 | await setAccessTokensToServers(servers) | |
74d63469 GR |
49 | |
50 | const videoQuota = 42000000 | |
1eddc9a7 | 51 | await createUser({ |
a1587156 C |
52 | url: servers[0].url, |
53 | accessToken: servers[0].accessToken, | |
1eddc9a7 C |
54 | username: firstUser.username, |
55 | password: firstUser.password, | |
56 | videoQuota: videoQuota | |
57 | }) | |
58 | await createUser({ | |
a1587156 C |
59 | url: servers[0].url, |
60 | accessToken: servers[0].accessToken, | |
1eddc9a7 C |
61 | username: secondUser.username, |
62 | password: secondUser.password, | |
63 | videoQuota: videoQuota | |
64 | }) | |
74d63469 | 65 | |
5cf84858 C |
66 | firstUserAccessToken = await userLogin(servers[0], firstUser) |
67 | secondUserAccessToken = await userLogin(servers[0], secondUser) | |
74d63469 | 68 | |
5cf84858 | 69 | const videoAttributes = { |
74d63469 GR |
70 | name: 'my super name', |
71 | description: 'my super description' | |
72 | } | |
5cf84858 | 73 | await uploadVideo(servers[0].url, firstUserAccessToken, videoAttributes) |
74d63469 | 74 | |
5cf84858 | 75 | await waitJobs(servers) |
74d63469 | 76 | |
5cf84858 | 77 | const res = await getVideosList(servers[0].url) |
74d63469 GR |
78 | const videos = res.body.data |
79 | ||
80 | expect(videos.length).to.equal(1) | |
81 | ||
5cf84858 C |
82 | const video = videos.find(video => video.name === 'my super name') |
83 | expect(video.channel.name).to.equal('first_channel') | |
84 | servers[0].video = video | |
85 | ||
86 | await doubleFollow(servers[0], servers[1]) | |
74d63469 GR |
87 | }) |
88 | ||
89 | it('Should not have video change ownership', async function () { | |
5cf84858 | 90 | const resFirstUser = await getVideoChangeOwnershipList(servers[0].url, firstUserAccessToken) |
74d63469 GR |
91 | |
92 | expect(resFirstUser.body.total).to.equal(0) | |
93 | expect(resFirstUser.body.data).to.be.an('array') | |
94 | expect(resFirstUser.body.data.length).to.equal(0) | |
95 | ||
5cf84858 | 96 | const resSecondUser = await getVideoChangeOwnershipList(servers[0].url, secondUserAccessToken) |
74d63469 GR |
97 | |
98 | expect(resSecondUser.body.total).to.equal(0) | |
99 | expect(resSecondUser.body.data).to.be.an('array') | |
100 | expect(resSecondUser.body.data.length).to.equal(0) | |
101 | }) | |
102 | ||
103 | it('Should send a request to change ownership of a video', async function () { | |
104 | this.timeout(15000) | |
105 | ||
5cf84858 | 106 | await changeVideoOwnership(servers[0].url, firstUserAccessToken, servers[0].video.id, secondUser.username) |
74d63469 GR |
107 | }) |
108 | ||
109 | it('Should only return a request to change ownership for the second user', async function () { | |
5cf84858 | 110 | const resFirstUser = await getVideoChangeOwnershipList(servers[0].url, firstUserAccessToken) |
74d63469 GR |
111 | |
112 | expect(resFirstUser.body.total).to.equal(0) | |
113 | expect(resFirstUser.body.data).to.be.an('array') | |
114 | expect(resFirstUser.body.data.length).to.equal(0) | |
115 | ||
5cf84858 | 116 | const resSecondUser = await getVideoChangeOwnershipList(servers[0].url, secondUserAccessToken) |
74d63469 GR |
117 | |
118 | expect(resSecondUser.body.total).to.equal(1) | |
119 | expect(resSecondUser.body.data).to.be.an('array') | |
120 | expect(resSecondUser.body.data.length).to.equal(1) | |
121 | ||
122 | lastRequestChangeOwnershipId = resSecondUser.body.data[0].id | |
123 | }) | |
124 | ||
125 | it('Should accept the same change ownership request without crashing', async function () { | |
126 | this.timeout(10000) | |
127 | ||
5cf84858 | 128 | await changeVideoOwnership(servers[0].url, firstUserAccessToken, servers[0].video.id, secondUser.username) |
74d63469 GR |
129 | }) |
130 | ||
131 | it('Should not create multiple change ownership requests while one is waiting', async function () { | |
132 | this.timeout(10000) | |
133 | ||
5cf84858 | 134 | const resSecondUser = await getVideoChangeOwnershipList(servers[0].url, secondUserAccessToken) |
74d63469 GR |
135 | |
136 | expect(resSecondUser.body.total).to.equal(1) | |
137 | expect(resSecondUser.body.data).to.be.an('array') | |
138 | expect(resSecondUser.body.data.length).to.equal(1) | |
139 | }) | |
140 | ||
141 | it('Should not be possible to refuse the change of ownership from first user', async function () { | |
142 | this.timeout(10000) | |
143 | ||
f2eb23cd | 144 | await refuseChangeOwnership(servers[0].url, firstUserAccessToken, lastRequestChangeOwnershipId, HttpStatusCode.FORBIDDEN_403) |
74d63469 GR |
145 | }) |
146 | ||
147 | it('Should be possible to refuse the change of ownership from second user', async function () { | |
148 | this.timeout(10000) | |
149 | ||
5cf84858 | 150 | await refuseChangeOwnership(servers[0].url, secondUserAccessToken, lastRequestChangeOwnershipId) |
74d63469 GR |
151 | }) |
152 | ||
153 | it('Should send a new request to change ownership of a video', async function () { | |
154 | this.timeout(15000) | |
155 | ||
5cf84858 | 156 | await changeVideoOwnership(servers[0].url, firstUserAccessToken, servers[0].video.id, secondUser.username) |
74d63469 GR |
157 | }) |
158 | ||
159 | it('Should return two requests to change ownership for the second user', async function () { | |
5cf84858 | 160 | const resFirstUser = await getVideoChangeOwnershipList(servers[0].url, firstUserAccessToken) |
74d63469 GR |
161 | |
162 | expect(resFirstUser.body.total).to.equal(0) | |
163 | expect(resFirstUser.body.data).to.be.an('array') | |
164 | expect(resFirstUser.body.data.length).to.equal(0) | |
165 | ||
5cf84858 | 166 | const resSecondUser = await getVideoChangeOwnershipList(servers[0].url, secondUserAccessToken) |
74d63469 GR |
167 | |
168 | expect(resSecondUser.body.total).to.equal(2) | |
169 | expect(resSecondUser.body.data).to.be.an('array') | |
170 | expect(resSecondUser.body.data.length).to.equal(2) | |
171 | ||
172 | lastRequestChangeOwnershipId = resSecondUser.body.data[0].id | |
173 | }) | |
174 | ||
175 | it('Should not be possible to accept the change of ownership from first user', async function () { | |
176 | this.timeout(10000) | |
177 | ||
5cf84858 | 178 | const secondUserInformationResponse = await getMyUserInformation(servers[0].url, secondUserAccessToken) |
74d63469 GR |
179 | const secondUserInformation: User = secondUserInformationResponse.body |
180 | const channelId = secondUserInformation.videoChannels[0].id | |
f2eb23cd | 181 | await acceptChangeOwnership(servers[0].url, firstUserAccessToken, lastRequestChangeOwnershipId, channelId, HttpStatusCode.FORBIDDEN_403) |
74d63469 GR |
182 | }) |
183 | ||
184 | it('Should be possible to accept the change of ownership from second user', async function () { | |
185 | this.timeout(10000) | |
186 | ||
5cf84858 | 187 | const secondUserInformationResponse = await getMyUserInformation(servers[0].url, secondUserAccessToken) |
74d63469 GR |
188 | const secondUserInformation: User = secondUserInformationResponse.body |
189 | const channelId = secondUserInformation.videoChannels[0].id | |
5cf84858 C |
190 | await acceptChangeOwnership(servers[0].url, secondUserAccessToken, lastRequestChangeOwnershipId, channelId) |
191 | ||
192 | await waitJobs(servers) | |
193 | }) | |
194 | ||
f92e7f76 | 195 | it('Should have the channel of the video updated', async function () { |
5cf84858 C |
196 | for (const server of servers) { |
197 | const res = await getVideo(server.url, servers[0].video.uuid) | |
198 | ||
199 | const video: VideoDetails = res.body | |
200 | ||
201 | expect(video.name).to.equal('my super name') | |
202 | expect(video.channel.displayName).to.equal('Main second channel') | |
203 | expect(video.channel.name).to.equal('second_channel') | |
204 | } | |
74d63469 GR |
205 | }) |
206 | ||
48f07b4a C |
207 | after(async function () { |
208 | await cleanupTests(servers) | |
74d63469 GR |
209 | }) |
210 | }) | |
211 | ||
212 | describe('Test video change ownership - quota too small', function () { | |
a1587156 | 213 | let server: ServerInfo |
74d63469 GR |
214 | const firstUser = { |
215 | username: 'first', | |
216 | password: 'My great password' | |
217 | } | |
218 | const secondUser = { | |
219 | username: 'second', | |
220 | password: 'My other password' | |
221 | } | |
222 | let firstUserAccessToken = '' | |
223 | let secondUserAccessToken = '' | |
a1587156 | 224 | let lastRequestChangeOwnershipId = '' |
74d63469 GR |
225 | |
226 | before(async function () { | |
227 | this.timeout(50000) | |
228 | ||
229 | // Run one server | |
210feb6c | 230 | server = await flushAndRunServer(1) |
a1587156 | 231 | await setAccessTokensToServers([ server ]) |
74d63469 GR |
232 | |
233 | const videoQuota = 42000000 | |
234 | const limitedVideoQuota = 10 | |
1eddc9a7 C |
235 | await createUser({ |
236 | url: server.url, | |
237 | accessToken: server.accessToken, | |
238 | username: firstUser.username, | |
239 | password: firstUser.password, | |
240 | videoQuota: videoQuota | |
241 | }) | |
242 | await createUser({ | |
243 | url: server.url, | |
244 | accessToken: server.accessToken, | |
245 | username: secondUser.username, | |
246 | password: secondUser.password, | |
247 | videoQuota: limitedVideoQuota | |
248 | }) | |
74d63469 GR |
249 | |
250 | firstUserAccessToken = await userLogin(server, firstUser) | |
251 | secondUserAccessToken = await userLogin(server, secondUser) | |
252 | ||
253 | // Upload some videos on the server | |
254 | const video1Attributes = { | |
255 | name: 'my super name', | |
256 | description: 'my super description' | |
257 | } | |
258 | await uploadVideo(server.url, firstUserAccessToken, video1Attributes) | |
259 | ||
260 | await waitJobs(server) | |
261 | ||
262 | const res = await getVideosList(server.url) | |
263 | const videos = res.body.data | |
264 | ||
265 | expect(videos.length).to.equal(1) | |
266 | ||
267 | server.video = videos.find(video => video.name === 'my super name') | |
268 | }) | |
269 | ||
270 | it('Should send a request to change ownership of a video', async function () { | |
271 | this.timeout(15000) | |
272 | ||
273 | await changeVideoOwnership(server.url, firstUserAccessToken, server.video.id, secondUser.username) | |
274 | }) | |
275 | ||
276 | it('Should only return a request to change ownership for the second user', async function () { | |
277 | const resFirstUser = await getVideoChangeOwnershipList(server.url, firstUserAccessToken) | |
278 | ||
279 | expect(resFirstUser.body.total).to.equal(0) | |
280 | expect(resFirstUser.body.data).to.be.an('array') | |
281 | expect(resFirstUser.body.data.length).to.equal(0) | |
282 | ||
283 | const resSecondUser = await getVideoChangeOwnershipList(server.url, secondUserAccessToken) | |
284 | ||
285 | expect(resSecondUser.body.total).to.equal(1) | |
286 | expect(resSecondUser.body.data).to.be.an('array') | |
287 | expect(resSecondUser.body.data.length).to.equal(1) | |
288 | ||
289 | lastRequestChangeOwnershipId = resSecondUser.body.data[0].id | |
290 | }) | |
291 | ||
292 | it('Should not be possible to accept the change of ownership from second user because of exceeded quota', async function () { | |
293 | this.timeout(10000) | |
294 | ||
295 | const secondUserInformationResponse = await getMyUserInformation(server.url, secondUserAccessToken) | |
296 | const secondUserInformation: User = secondUserInformationResponse.body | |
297 | const channelId = secondUserInformation.videoChannels[0].id | |
f2eb23cd RK |
298 | |
299 | await acceptChangeOwnership( | |
300 | server.url, | |
301 | secondUserAccessToken, | |
302 | lastRequestChangeOwnershipId, | |
303 | channelId, | |
304 | HttpStatusCode.PAYLOAD_TOO_LARGE_413 | |
305 | ) | |
74d63469 GR |
306 | }) |
307 | ||
7c3b7976 C |
308 | after(async function () { |
309 | await cleanupTests([ server ]) | |
74d63469 GR |
310 | }) |
311 | }) |